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);
1816 gtk_entry_set_buffer (entry, g_value_get_object (value));
1821 gboolean new_value = g_value_get_boolean (value);
1823 if (new_value != entry->editable)
1827 _gtk_entry_reset_im_context (entry);
1828 if (GTK_WIDGET_HAS_FOCUS (entry))
1829 gtk_im_context_focus_out (entry->im_context);
1831 entry->preedit_length = 0;
1832 entry->preedit_cursor = 0;
1835 entry->editable = new_value;
1837 if (new_value && GTK_WIDGET_HAS_FOCUS (entry))
1838 gtk_im_context_focus_in (entry->im_context);
1840 gtk_entry_queue_draw (entry);
1845 case PROP_MAX_LENGTH:
1846 gtk_entry_set_max_length (entry, g_value_get_int (value));
1849 case PROP_VISIBILITY:
1850 gtk_entry_set_visibility (entry, g_value_get_boolean (value));
1853 case PROP_HAS_FRAME:
1854 gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
1857 case PROP_INNER_BORDER:
1858 gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
1861 case PROP_INVISIBLE_CHAR:
1862 gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
1865 case PROP_ACTIVATES_DEFAULT:
1866 gtk_entry_set_activates_default (entry, g_value_get_boolean (value));
1869 case PROP_WIDTH_CHARS:
1870 gtk_entry_set_width_chars (entry, g_value_get_int (value));
1874 gtk_entry_set_text (entry, g_value_get_string (value));
1878 gtk_entry_set_alignment (entry, g_value_get_float (value));
1881 case PROP_TRUNCATE_MULTILINE:
1882 entry->truncate_multiline = g_value_get_boolean (value);
1885 case PROP_SHADOW_TYPE:
1886 priv->shadow_type = g_value_get_enum (value);
1889 case PROP_OVERWRITE_MODE:
1890 gtk_entry_set_overwrite_mode (entry, g_value_get_boolean (value));
1893 case PROP_INVISIBLE_CHAR_SET:
1894 if (g_value_get_boolean (value))
1895 priv->invisible_char_set = TRUE;
1897 gtk_entry_unset_invisible_char (entry);
1900 case PROP_CAPS_LOCK_WARNING:
1901 priv->caps_lock_warning = g_value_get_boolean (value);
1904 case PROP_PROGRESS_FRACTION:
1905 gtk_entry_set_progress_fraction (entry, g_value_get_double (value));
1908 case PROP_PROGRESS_PULSE_STEP:
1909 gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
1912 case PROP_PIXBUF_PRIMARY:
1913 gtk_entry_set_icon_from_pixbuf (entry,
1914 GTK_ENTRY_ICON_PRIMARY,
1915 g_value_get_object (value));
1918 case PROP_PIXBUF_SECONDARY:
1919 gtk_entry_set_icon_from_pixbuf (entry,
1920 GTK_ENTRY_ICON_SECONDARY,
1921 g_value_get_object (value));
1924 case PROP_STOCK_PRIMARY:
1925 gtk_entry_set_icon_from_stock (entry,
1926 GTK_ENTRY_ICON_PRIMARY,
1927 g_value_get_string (value));
1930 case PROP_STOCK_SECONDARY:
1931 gtk_entry_set_icon_from_stock (entry,
1932 GTK_ENTRY_ICON_SECONDARY,
1933 g_value_get_string (value));
1936 case PROP_ICON_NAME_PRIMARY:
1937 gtk_entry_set_icon_from_icon_name (entry,
1938 GTK_ENTRY_ICON_PRIMARY,
1939 g_value_get_string (value));
1942 case PROP_ICON_NAME_SECONDARY:
1943 gtk_entry_set_icon_from_icon_name (entry,
1944 GTK_ENTRY_ICON_SECONDARY,
1945 g_value_get_string (value));
1948 case PROP_GICON_PRIMARY:
1949 gtk_entry_set_icon_from_gicon (entry,
1950 GTK_ENTRY_ICON_PRIMARY,
1951 g_value_get_object (value));
1954 case PROP_GICON_SECONDARY:
1955 gtk_entry_set_icon_from_gicon (entry,
1956 GTK_ENTRY_ICON_SECONDARY,
1957 g_value_get_object (value));
1960 case PROP_ACTIVATABLE_PRIMARY:
1961 gtk_entry_set_icon_activatable (entry,
1962 GTK_ENTRY_ICON_PRIMARY,
1963 g_value_get_boolean (value));
1966 case PROP_ACTIVATABLE_SECONDARY:
1967 gtk_entry_set_icon_activatable (entry,
1968 GTK_ENTRY_ICON_SECONDARY,
1969 g_value_get_boolean (value));
1972 case PROP_SENSITIVE_PRIMARY:
1973 gtk_entry_set_icon_sensitive (entry,
1974 GTK_ENTRY_ICON_PRIMARY,
1975 g_value_get_boolean (value));
1978 case PROP_SENSITIVE_SECONDARY:
1979 gtk_entry_set_icon_sensitive (entry,
1980 GTK_ENTRY_ICON_SECONDARY,
1981 g_value_get_boolean (value));
1984 case PROP_TOOLTIP_TEXT_PRIMARY:
1985 gtk_entry_set_icon_tooltip_text (entry,
1986 GTK_ENTRY_ICON_PRIMARY,
1987 g_value_get_string (value));
1990 case PROP_TOOLTIP_TEXT_SECONDARY:
1991 gtk_entry_set_icon_tooltip_text (entry,
1992 GTK_ENTRY_ICON_SECONDARY,
1993 g_value_get_string (value));
1996 case PROP_TOOLTIP_MARKUP_PRIMARY:
1997 gtk_entry_set_icon_tooltip_markup (entry,
1998 GTK_ENTRY_ICON_PRIMARY,
1999 g_value_get_string (value));
2002 case PROP_TOOLTIP_MARKUP_SECONDARY:
2003 gtk_entry_set_icon_tooltip_markup (entry,
2004 GTK_ENTRY_ICON_SECONDARY,
2005 g_value_get_string (value));
2008 case PROP_IM_MODULE:
2009 g_free (priv->im_module);
2010 priv->im_module = g_value_dup_string (value);
2011 if (GTK_IS_IM_MULTICONTEXT (entry->im_context))
2012 gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module);
2015 case PROP_EDITING_CANCELED:
2016 entry->editing_canceled = g_value_get_boolean (value);
2019 case PROP_SCROLL_OFFSET:
2020 case PROP_CURSOR_POSITION:
2022 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2028 gtk_entry_get_property (GObject *object,
2033 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
2034 GtkEntry *entry = GTK_ENTRY (object);
2039 g_value_set_object (value, gtk_entry_get_buffer (entry));
2042 case PROP_CURSOR_POSITION:
2043 g_value_set_int (value, entry->current_pos);
2046 case PROP_SELECTION_BOUND:
2047 g_value_set_int (value, entry->selection_bound);
2051 g_value_set_boolean (value, entry->editable);
2054 case PROP_MAX_LENGTH:
2055 g_value_set_int (value, gtk_entry_buffer_get_max_length (get_buffer (entry)));
2058 case PROP_VISIBILITY:
2059 g_value_set_boolean (value, entry->visible);
2062 case PROP_HAS_FRAME:
2063 g_value_set_boolean (value, entry->has_frame);
2066 case PROP_INNER_BORDER:
2067 g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
2070 case PROP_INVISIBLE_CHAR:
2071 g_value_set_uint (value, entry->invisible_char);
2074 case PROP_ACTIVATES_DEFAULT:
2075 g_value_set_boolean (value, entry->activates_default);
2078 case PROP_WIDTH_CHARS:
2079 g_value_set_int (value, entry->width_chars);
2082 case PROP_SCROLL_OFFSET:
2083 g_value_set_int (value, entry->scroll_offset);
2087 g_value_set_string (value, gtk_entry_get_text (entry));
2091 g_value_set_float (value, gtk_entry_get_alignment (entry));
2094 case PROP_TRUNCATE_MULTILINE:
2095 g_value_set_boolean (value, entry->truncate_multiline);
2098 case PROP_SHADOW_TYPE:
2099 g_value_set_enum (value, priv->shadow_type);
2102 case PROP_OVERWRITE_MODE:
2103 g_value_set_boolean (value, entry->overwrite_mode);
2106 case PROP_TEXT_LENGTH:
2107 g_value_set_uint (value, gtk_entry_buffer_get_length (get_buffer (entry)));
2110 case PROP_INVISIBLE_CHAR_SET:
2111 g_value_set_boolean (value, priv->invisible_char_set);
2114 case PROP_IM_MODULE:
2115 g_value_set_string (value, priv->im_module);
2118 case PROP_CAPS_LOCK_WARNING:
2119 g_value_set_boolean (value, priv->caps_lock_warning);
2122 case PROP_PROGRESS_FRACTION:
2123 g_value_set_double (value, priv->progress_fraction);
2126 case PROP_PROGRESS_PULSE_STEP:
2127 g_value_set_double (value, priv->progress_pulse_fraction);
2130 case PROP_PIXBUF_PRIMARY:
2131 g_value_set_object (value,
2132 gtk_entry_get_icon_pixbuf (entry,
2133 GTK_ENTRY_ICON_PRIMARY));
2136 case PROP_PIXBUF_SECONDARY:
2137 g_value_set_object (value,
2138 gtk_entry_get_icon_pixbuf (entry,
2139 GTK_ENTRY_ICON_SECONDARY));
2142 case PROP_STOCK_PRIMARY:
2143 g_value_set_string (value,
2144 gtk_entry_get_icon_stock (entry,
2145 GTK_ENTRY_ICON_PRIMARY));
2148 case PROP_STOCK_SECONDARY:
2149 g_value_set_string (value,
2150 gtk_entry_get_icon_stock (entry,
2151 GTK_ENTRY_ICON_SECONDARY));
2154 case PROP_ICON_NAME_PRIMARY:
2155 g_value_set_string (value,
2156 gtk_entry_get_icon_name (entry,
2157 GTK_ENTRY_ICON_PRIMARY));
2160 case PROP_ICON_NAME_SECONDARY:
2161 g_value_set_string (value,
2162 gtk_entry_get_icon_name (entry,
2163 GTK_ENTRY_ICON_SECONDARY));
2166 case PROP_GICON_PRIMARY:
2167 g_value_set_object (value,
2168 gtk_entry_get_icon_gicon (entry,
2169 GTK_ENTRY_ICON_PRIMARY));
2172 case PROP_GICON_SECONDARY:
2173 g_value_set_object (value,
2174 gtk_entry_get_icon_gicon (entry,
2175 GTK_ENTRY_ICON_SECONDARY));
2178 case PROP_STORAGE_TYPE_PRIMARY:
2179 g_value_set_enum (value,
2180 gtk_entry_get_icon_storage_type (entry,
2181 GTK_ENTRY_ICON_PRIMARY));
2184 case PROP_STORAGE_TYPE_SECONDARY:
2185 g_value_set_enum (value,
2186 gtk_entry_get_icon_storage_type (entry,
2187 GTK_ENTRY_ICON_SECONDARY));
2190 case PROP_ACTIVATABLE_PRIMARY:
2191 g_value_set_boolean (value,
2192 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_PRIMARY));
2195 case PROP_ACTIVATABLE_SECONDARY:
2196 g_value_set_boolean (value,
2197 gtk_entry_get_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY));
2200 case PROP_SENSITIVE_PRIMARY:
2201 g_value_set_boolean (value,
2202 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_PRIMARY));
2205 case PROP_SENSITIVE_SECONDARY:
2206 g_value_set_boolean (value,
2207 gtk_entry_get_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY));
2210 case PROP_TOOLTIP_TEXT_PRIMARY:
2211 g_value_take_string (value,
2212 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_PRIMARY));
2215 case PROP_TOOLTIP_TEXT_SECONDARY:
2216 g_value_take_string (value,
2217 gtk_entry_get_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY));
2220 case PROP_TOOLTIP_MARKUP_PRIMARY:
2221 g_value_take_string (value,
2222 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY));
2225 case PROP_TOOLTIP_MARKUP_SECONDARY:
2226 g_value_take_string (value,
2227 gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
2230 case PROP_EDITING_CANCELED:
2231 g_value_set_boolean (value,
2232 entry->editing_canceled);
2236 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2242 find_invisible_char (GtkWidget *widget)
2244 PangoLayout *layout;
2245 PangoAttrList *attr_list;
2247 gunichar invisible_chars [] = {
2249 0x25cf, /* BLACK CIRCLE */
2250 0x2022, /* BULLET */
2251 0x2731, /* HEAVY ASTERISK */
2252 0x273a /* SIXTEEN POINTED ASTERISK */
2256 gtk_widget_style_get (widget,
2257 "invisible-char", &invisible_chars[0],
2260 layout = gtk_widget_create_pango_layout (widget, NULL);
2262 attr_list = pango_attr_list_new ();
2263 pango_attr_list_insert (attr_list, pango_attr_fallback_new (FALSE));
2265 pango_layout_set_attributes (layout, attr_list);
2266 pango_attr_list_unref (attr_list);
2268 for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++)
2270 gchar text[7] = { 0, };
2273 len = g_unichar_to_utf8 (invisible_chars[i], text);
2274 pango_layout_set_text (layout, text, len);
2276 count = pango_layout_get_unknown_glyphs_count (layout);
2280 g_object_unref (layout);
2281 return invisible_chars[i];
2285 g_object_unref (layout);
2291 gtk_entry_init (GtkEntry *entry)
2293 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2295 GTK_WIDGET_SET_FLAGS (entry, GTK_CAN_FOCUS);
2297 entry->editable = TRUE;
2298 entry->visible = TRUE;
2299 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
2300 entry->dnd_position = -1;
2301 entry->width_chars = -1;
2302 entry->is_cell_renderer = FALSE;
2303 entry->editing_canceled = FALSE;
2304 entry->has_frame = TRUE;
2305 entry->truncate_multiline = FALSE;
2306 priv->shadow_type = GTK_SHADOW_IN;
2308 priv->caps_lock_warning = TRUE;
2309 priv->caps_lock_warning_shown = FALSE;
2310 priv->progress_fraction = 0.0;
2311 priv->progress_pulse_fraction = 0.1;
2313 gtk_drag_dest_set (GTK_WIDGET (entry),
2314 GTK_DEST_DEFAULT_HIGHLIGHT,
2316 GDK_ACTION_COPY | GDK_ACTION_MOVE);
2317 gtk_drag_dest_add_text_targets (GTK_WIDGET (entry));
2319 /* This object is completely private. No external entity can gain a reference
2320 * to it; so we create it here and destroy it in finalize().
2322 entry->im_context = gtk_im_multicontext_new ();
2324 g_signal_connect (entry->im_context, "commit",
2325 G_CALLBACK (gtk_entry_commit_cb), entry);
2326 g_signal_connect (entry->im_context, "preedit-changed",
2327 G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
2328 g_signal_connect (entry->im_context, "retrieve-surrounding",
2329 G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
2330 g_signal_connect (entry->im_context, "delete-surrounding",
2331 G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
2336 get_icon_width (GtkEntry *entry,
2337 GtkEntryIconPosition icon_pos)
2339 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2340 EntryIconInfo *icon_info = priv->icons[icon_pos];
2342 GtkSettings *settings;
2343 gint menu_icon_width;
2345 if (!icon_info || icon_info->pixbuf == NULL)
2348 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
2349 settings = gtk_settings_get_for_screen (screen);
2351 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
2352 &menu_icon_width, NULL);
2354 return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
2358 get_icon_allocations (GtkEntry *entry,
2359 GtkAllocation *primary,
2360 GtkAllocation *secondary)
2363 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2364 gint x, y, width, height;
2366 get_text_area_size (entry, &x, &y, &width, &height);
2368 if (GTK_WIDGET_HAS_FOCUS (entry) && !priv->interior_focus)
2369 y += priv->focus_width;
2372 primary->height = height;
2373 primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
2374 if (primary->width > 0)
2375 primary->width += 2 * priv->icon_margin;
2378 secondary->height = height;
2379 secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
2380 if (secondary->width > 0)
2381 secondary->width += 2 * priv->icon_margin;
2383 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2385 primary->x = x + width - primary->width;
2391 secondary->x = x + width - secondary->width;
2397 begin_change (GtkEntry *entry)
2399 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2401 priv->change_count++;
2405 end_change (GtkEntry *entry)
2407 GtkEditable *editable = GTK_EDITABLE (entry);
2408 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2410 g_return_if_fail (priv->change_count > 0);
2412 priv->change_count--;
2414 if (priv->change_count == 0)
2416 if (priv->real_changed)
2418 g_signal_emit_by_name (editable, "changed");
2419 priv->real_changed = FALSE;
2425 emit_changed (GtkEntry *entry)
2427 GtkEditable *editable = GTK_EDITABLE (entry);
2428 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2430 if (priv->change_count == 0)
2431 g_signal_emit_by_name (editable, "changed");
2433 priv->real_changed = TRUE;
2437 gtk_entry_destroy (GtkObject *object)
2439 GtkEntry *entry = GTK_ENTRY (object);
2441 entry->current_pos = entry->selection_bound = 0;
2442 _gtk_entry_reset_im_context (entry);
2443 gtk_entry_reset_layout (entry);
2445 if (entry->blink_timeout)
2447 g_source_remove (entry->blink_timeout);
2448 entry->blink_timeout = 0;
2451 if (entry->recompute_idle)
2453 g_source_remove (entry->recompute_idle);
2454 entry->recompute_idle = 0;
2457 GTK_OBJECT_CLASS (gtk_entry_parent_class)->destroy (object);
2461 gtk_entry_dispose (GObject *object)
2463 GtkEntry *entry = GTK_ENTRY (object);
2465 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2466 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
2467 gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2468 gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
2470 G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
2474 gtk_entry_finalize (GObject *object)
2476 GtkEntry *entry = GTK_ENTRY (object);
2477 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2478 EntryIconInfo *icon_info = NULL;
2481 for (i = 0; i < MAX_ICONS; i++)
2483 if ((icon_info = priv->icons[i]) != NULL)
2485 if (icon_info->target_list != NULL)
2487 gtk_target_list_unref (icon_info->target_list);
2488 icon_info->target_list = NULL;
2491 g_slice_free (EntryIconInfo, icon_info);
2492 priv->icons[i] = NULL;
2496 gtk_entry_set_completion (entry, NULL);
2498 if (entry->cached_layout)
2499 g_object_unref (entry->cached_layout);
2501 g_object_unref (entry->im_context);
2503 if (entry->blink_timeout)
2504 g_source_remove (entry->blink_timeout);
2506 if (entry->recompute_idle)
2507 g_source_remove (entry->recompute_idle);
2509 g_free (priv->im_module);
2511 /* COMPAT: entry->text is a deprecated field, and the allocation
2512 is owned by the buffer. */
2514 gtk_entry_set_buffer (entry, NULL);
2516 G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
2520 gtk_entry_get_display_mode (GtkEntry *entry)
2522 GtkEntryPrivate *priv;
2524 return DISPLAY_NORMAL;
2525 priv = GTK_ENTRY_GET_PRIVATE (entry);
2526 if (entry->invisible_char == 0 && priv->invisible_char_set)
2527 return DISPLAY_BLANK;
2528 return DISPLAY_INVISIBLE;
2532 gtk_entry_get_display_text (GtkEntry *entry,
2536 GtkEntryPasswordHint *password_hint;
2537 GtkEntryPrivate *priv;
2538 gunichar invisible_char;
2548 priv = GTK_ENTRY_GET_PRIVATE (entry);
2549 text = gtk_entry_buffer_get_text (get_buffer (entry));
2550 length = gtk_entry_buffer_get_length (get_buffer (entry));
2554 if (start_pos > length)
2557 if (end_pos <= start_pos)
2558 return g_strdup ("");
2559 else if (entry->visible)
2561 start = g_utf8_offset_to_pointer (text, start_pos);
2562 end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
2563 return g_strndup (start, end - start);
2567 str = g_string_sized_new (length * 2);
2569 /* Figure out what our invisible char is and encode it */
2570 if (!entry->invisible_char)
2571 invisible_char = priv->invisible_char_set ? ' ' : '*';
2573 invisible_char = entry->invisible_char;
2574 char_len = g_unichar_to_utf8 (invisible_char, char_str);
2577 * Add hidden characters for each character in the text
2578 * buffer. If there is a password hint, then keep that
2579 * character visible.
2582 password_hint = g_object_get_qdata (G_OBJECT (entry), quark_password_hint);
2583 for (i = start_pos; i < end_pos; ++i)
2585 if (password_hint && i == password_hint->position)
2587 start = g_utf8_offset_to_pointer (text, i);
2588 g_string_append_len (str, start, g_utf8_next_char (start) - start);
2592 g_string_append_len (str, char_str, char_len);
2596 return g_string_free (str, FALSE);
2602 update_cursors (GtkWidget *widget)
2604 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2605 EntryIconInfo *icon_info = NULL;
2606 GdkDisplay *display;
2610 for (i = 0; i < MAX_ICONS; i++)
2612 if ((icon_info = priv->icons[i]) != NULL)
2614 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2615 gdk_window_show_unraised (icon_info->window);
2617 /* The icon windows are not children of the visible entry window,
2618 * thus we can't just inherit the xterm cursor. Slight complication
2619 * here is that for the entry, insensitive => arrow cursor, but for
2620 * an icon in a sensitive entry, insensitive => xterm cursor.
2622 if (GTK_WIDGET_IS_SENSITIVE (widget) &&
2623 (icon_info->insensitive ||
2624 (icon_info->nonactivatable && icon_info->target_list == NULL)))
2626 display = gtk_widget_get_display (widget);
2627 cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
2628 gdk_window_set_cursor (icon_info->window, cursor);
2629 gdk_cursor_unref (cursor);
2633 gdk_window_set_cursor (icon_info->window, NULL);
2640 realize_icon_info (GtkWidget *widget,
2641 GtkEntryIconPosition icon_pos)
2643 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2644 EntryIconInfo *icon_info = priv->icons[icon_pos];
2645 GdkWindowAttr attributes;
2646 gint attributes_mask;
2648 g_return_if_fail (icon_info != NULL);
2652 attributes.width = 1;
2653 attributes.height = 1;
2654 attributes.window_type = GDK_WINDOW_CHILD;
2655 attributes.wclass = GDK_INPUT_OUTPUT;
2656 attributes.visual = gtk_widget_get_visual (widget);
2657 attributes.colormap = gtk_widget_get_colormap (widget);
2658 attributes.event_mask = gtk_widget_get_events (widget);
2659 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2660 GDK_BUTTON_PRESS_MASK |
2661 GDK_BUTTON_RELEASE_MASK |
2662 GDK_BUTTON1_MOTION_MASK |
2663 GDK_BUTTON3_MOTION_MASK |
2664 GDK_POINTER_MOTION_HINT_MASK |
2665 GDK_POINTER_MOTION_MASK |
2666 GDK_ENTER_NOTIFY_MASK |
2667 GDK_LEAVE_NOTIFY_MASK);
2668 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2670 icon_info->window = gdk_window_new (widget->window,
2673 gdk_window_set_user_data (icon_info->window, widget);
2674 gdk_window_set_background (icon_info->window,
2675 &widget->style->base[GTK_WIDGET_STATE (widget)]);
2677 gtk_widget_queue_resize (widget);
2680 static EntryIconInfo*
2681 construct_icon_info (GtkWidget *widget,
2682 GtkEntryIconPosition icon_pos)
2684 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2685 EntryIconInfo *icon_info;
2687 g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
2689 icon_info = g_slice_new0 (EntryIconInfo);
2690 priv->icons[icon_pos] = icon_info;
2692 if (GTK_WIDGET_REALIZED (widget))
2693 realize_icon_info (widget, icon_pos);
2699 gtk_entry_map (GtkWidget *widget)
2701 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2702 EntryIconInfo *icon_info = NULL;
2705 if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_MAPPED (widget))
2707 GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
2709 for (i = 0; i < MAX_ICONS; i++)
2711 if ((icon_info = priv->icons[i]) != NULL)
2713 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2714 gdk_window_show (icon_info->window);
2718 update_cursors (widget);
2723 gtk_entry_unmap (GtkWidget *widget)
2725 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2726 EntryIconInfo *icon_info = NULL;
2729 if (GTK_WIDGET_MAPPED (widget))
2731 for (i = 0; i < MAX_ICONS; i++)
2733 if ((icon_info = priv->icons[i]) != NULL)
2735 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
2736 gdk_window_hide (icon_info->window);
2740 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
2745 gtk_entry_realize (GtkWidget *widget)
2748 GtkEntryPrivate *priv;
2749 EntryIconInfo *icon_info;
2750 GdkWindowAttr attributes;
2751 gint attributes_mask;
2754 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
2755 entry = GTK_ENTRY (widget);
2756 priv = GTK_ENTRY_GET_PRIVATE (entry);
2758 attributes.window_type = GDK_WINDOW_CHILD;
2760 get_widget_window_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2762 attributes.wclass = GDK_INPUT_OUTPUT;
2763 attributes.visual = gtk_widget_get_visual (widget);
2764 attributes.colormap = gtk_widget_get_colormap (widget);
2765 attributes.event_mask = gtk_widget_get_events (widget);
2766 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2767 GDK_BUTTON_PRESS_MASK |
2768 GDK_BUTTON_RELEASE_MASK |
2769 GDK_BUTTON1_MOTION_MASK |
2770 GDK_BUTTON3_MOTION_MASK |
2771 GDK_POINTER_MOTION_HINT_MASK |
2772 GDK_POINTER_MOTION_MASK |
2773 GDK_ENTER_NOTIFY_MASK |
2774 GDK_LEAVE_NOTIFY_MASK);
2775 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2777 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
2778 gdk_window_set_user_data (widget->window, entry);
2780 get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
2782 if (GTK_WIDGET_IS_SENSITIVE (widget))
2784 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
2785 attributes_mask |= GDK_WA_CURSOR;
2788 entry->text_area = gdk_window_new (widget->window, &attributes, attributes_mask);
2790 gdk_window_set_user_data (entry->text_area, entry);
2792 if (attributes_mask & GDK_WA_CURSOR)
2793 gdk_cursor_unref (attributes.cursor);
2795 widget->style = gtk_style_attach (widget->style, widget->window);
2797 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
2798 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
2800 gdk_window_show (entry->text_area);
2802 gtk_im_context_set_client_window (entry->im_context, entry->text_area);
2804 gtk_entry_adjust_scroll (entry);
2805 gtk_entry_update_primary_selection (entry);
2808 /* If the icon positions are already setup, create their windows.
2809 * Otherwise if they don't exist yet, then construct_icon_info()
2810 * will create the windows once the widget is already realized.
2812 for (i = 0; i < MAX_ICONS; i++)
2814 if ((icon_info = priv->icons[i]) != NULL)
2816 if (icon_info->window == NULL)
2817 realize_icon_info (widget, i);
2823 gtk_entry_unrealize (GtkWidget *widget)
2825 GtkEntry *entry = GTK_ENTRY (widget);
2826 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2827 GtkClipboard *clipboard;
2828 EntryIconInfo *icon_info;
2831 gtk_entry_reset_layout (entry);
2833 gtk_im_context_set_client_window (entry->im_context, NULL);
2835 clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
2836 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
2837 gtk_clipboard_clear (clipboard);
2839 if (entry->text_area)
2841 gdk_window_set_user_data (entry->text_area, NULL);
2842 gdk_window_destroy (entry->text_area);
2843 entry->text_area = NULL;
2846 if (entry->popup_menu)
2848 gtk_widget_destroy (entry->popup_menu);
2849 entry->popup_menu = NULL;
2852 GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
2854 for (i = 0; i < MAX_ICONS; i++)
2856 if ((icon_info = priv->icons[i]) != NULL)
2858 if (icon_info->window != NULL)
2860 gdk_window_destroy (icon_info->window);
2861 icon_info->window = NULL;
2868 _gtk_entry_get_borders (GtkEntry *entry,
2872 GtkWidget *widget = GTK_WIDGET (entry);
2873 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2875 if (entry->has_frame)
2877 *xborder = widget->style->xthickness;
2878 *yborder = widget->style->ythickness;
2886 if (!priv->interior_focus)
2888 *xborder += priv->focus_width;
2889 *yborder += priv->focus_width;
2894 gtk_entry_size_request (GtkWidget *widget,
2895 GtkRequisition *requisition)
2897 GtkEntry *entry = GTK_ENTRY (widget);
2898 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2899 PangoFontMetrics *metrics;
2900 gint xborder, yborder;
2901 GtkBorder inner_border;
2902 PangoContext *context;
2903 int icon_widths = 0;
2906 gtk_widget_ensure_style (widget);
2907 context = gtk_widget_get_pango_context (widget);
2908 metrics = pango_context_get_metrics (context,
2909 widget->style->font_desc,
2910 pango_context_get_language (context));
2912 entry->ascent = pango_font_metrics_get_ascent (metrics);
2913 entry->descent = pango_font_metrics_get_descent (metrics);
2915 _gtk_entry_get_borders (entry, &xborder, &yborder);
2916 _gtk_entry_effective_inner_border (entry, &inner_border);
2918 if (entry->width_chars < 0)
2919 requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
2922 gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
2923 gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
2924 gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
2926 requisition->width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
2929 requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
2931 for (i = 0; i < MAX_ICONS; i++)
2933 icon_width = get_icon_width (entry, i);
2935 icon_widths += icon_width + 2 * priv->icon_margin;
2938 if (icon_widths > requisition->width)
2939 requisition->width += icon_widths;
2941 pango_font_metrics_unref (metrics);
2945 place_windows (GtkEntry *entry)
2947 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
2948 gint x, y, width, height;
2949 GtkAllocation primary;
2950 GtkAllocation secondary;
2951 EntryIconInfo *icon_info = NULL;
2953 get_text_area_size (entry, &x, &y, &width, &height);
2954 get_icon_allocations (entry, &primary, &secondary);
2956 if (GTK_WIDGET_HAS_FOCUS (entry) && !priv->interior_focus)
2957 y += priv->focus_width;
2959 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
2960 x += secondary.width;
2963 width -= primary.width + secondary.width;
2965 if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
2966 gdk_window_move_resize (icon_info->window,
2967 primary.x, primary.y,
2968 primary.width, primary.height);
2970 if ((icon_info = priv->icons[GTK_ENTRY_ICON_SECONDARY]) != NULL)
2971 gdk_window_move_resize (icon_info->window,
2972 secondary.x, secondary.y,
2973 secondary.width, secondary.height);
2975 gdk_window_move_resize (GTK_ENTRY (entry)->text_area, x, y, width, height);
2979 gtk_entry_get_text_area_size (GtkEntry *entry,
2985 GtkWidget *widget = GTK_WIDGET (entry);
2986 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
2988 gint xborder, yborder;
2989 GtkRequisition requisition;
2991 gtk_widget_get_child_requisition (widget, &requisition);
2992 _gtk_entry_get_borders (entry, &xborder, &yborder);
2994 if (GTK_WIDGET_REALIZED (widget))
2995 gdk_drawable_get_size (widget->window, NULL, &frame_height);
2997 frame_height = requisition.height;
2999 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
3000 frame_height -= 2 * priv->focus_width;
3006 *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
3009 *width = GTK_WIDGET (entry)->allocation.width - xborder * 2;
3012 *height = requisition.height - yborder * 2;
3016 get_text_area_size (GtkEntry *entry,
3022 GtkEntryClass *class;
3024 g_return_if_fail (GTK_IS_ENTRY (entry));
3026 class = GTK_ENTRY_GET_CLASS (entry);
3028 if (class->get_text_area_size)
3029 class->get_text_area_size (entry, x, y, width, height);
3034 get_widget_window_size (GtkEntry *entry,
3040 GtkRequisition requisition;
3041 GtkWidget *widget = GTK_WIDGET (entry);
3043 gtk_widget_get_child_requisition (widget, &requisition);
3046 *x = widget->allocation.x;
3050 if (entry->is_cell_renderer)
3051 *y = widget->allocation.y;
3053 *y = widget->allocation.y + (widget->allocation.height - requisition.height) / 2;
3057 *width = widget->allocation.width;
3061 if (entry->is_cell_renderer)
3062 *height = widget->allocation.height;
3064 *height = requisition.height;
3069 _gtk_entry_effective_inner_border (GtkEntry *entry,
3072 GtkBorder *tmp_border;
3074 tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
3078 *border = *tmp_border;
3082 gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
3086 *border = *tmp_border;
3087 gtk_border_free (tmp_border);
3091 *border = default_inner_border;
3095 gtk_entry_size_allocate (GtkWidget *widget,
3096 GtkAllocation *allocation)
3098 GtkEntry *entry = GTK_ENTRY (widget);
3100 widget->allocation = *allocation;
3102 if (GTK_WIDGET_REALIZED (widget))
3104 /* We call gtk_widget_get_child_requisition, since we want (for
3105 * backwards compatibility reasons) the realization here to
3106 * be affected by the usize of the entry, if set
3108 gint x, y, width, height;
3109 GtkEntryCompletion* completion;
3111 get_widget_window_size (entry, &x, &y, &width, &height);
3112 gdk_window_move_resize (widget->window, x, y, width, height);
3114 place_windows (entry);
3115 gtk_entry_recompute (entry);
3117 completion = gtk_entry_get_completion (entry);
3118 if (completion && GTK_WIDGET_MAPPED (completion->priv->popup_window))
3119 _gtk_entry_completion_resize_popup (completion);
3123 /* Kudos to the gnome-panel guys. */
3125 colorshift_pixbuf (GdkPixbuf *dest,
3130 gint width, height, has_alpha, src_rowstride, dest_rowstride;
3131 guchar *target_pixels;
3132 guchar *original_pixels;
3138 has_alpha = gdk_pixbuf_get_has_alpha (src);
3139 width = gdk_pixbuf_get_width (src);
3140 height = gdk_pixbuf_get_height (src);
3141 src_rowstride = gdk_pixbuf_get_rowstride (src);
3142 dest_rowstride = gdk_pixbuf_get_rowstride (dest);
3143 original_pixels = gdk_pixbuf_get_pixels (src);
3144 target_pixels = gdk_pixbuf_get_pixels (dest);
3146 for (i = 0; i < height; i++)
3148 pix_dest = target_pixels + i * dest_rowstride;
3149 pix_src = original_pixels + i * src_rowstride;
3151 for (j = 0; j < width; j++)
3158 *(pix_dest++) = CLAMP (val, 0, 255);
3161 *(pix_dest++) = CLAMP (val, 0, 255);
3164 *(pix_dest++) = CLAMP (val, 0, 255);
3167 *(pix_dest++) = *(pix_src++);
3173 should_prelight (GtkEntry *entry,
3174 GtkEntryIconPosition icon_pos)
3176 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3177 EntryIconInfo *icon_info = priv->icons[icon_pos];
3183 if (icon_info->nonactivatable && icon_info->target_list == NULL)
3186 if (icon_info->pressed)
3189 gtk_widget_style_get (GTK_WIDGET (entry),
3190 "icon-prelight", &prelight,
3197 draw_icon (GtkWidget *widget,
3198 GtkEntryIconPosition icon_pos)
3200 GtkEntry *entry = GTK_ENTRY (widget);
3201 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3202 EntryIconInfo *icon_info = priv->icons[icon_pos];
3204 gint x, y, width, height;
3209 gtk_entry_ensure_pixbuf (entry, icon_pos);
3211 if (icon_info->pixbuf == NULL)
3214 gdk_drawable_get_size (icon_info->window, &width, &height);
3216 /* size_allocate hasn't been called yet. These are the default values.
3218 if (width == 1 || height == 1)
3221 pixbuf = icon_info->pixbuf;
3222 g_object_ref (pixbuf);
3224 if (gdk_pixbuf_get_height (pixbuf) > height)
3226 GdkPixbuf *temp_pixbuf;
3229 scale = height - 2 * priv->icon_margin;
3230 temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
3231 GDK_INTERP_BILINEAR);
3232 g_object_unref (pixbuf);
3233 pixbuf = temp_pixbuf;
3236 x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
3237 y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
3239 if (!GTK_WIDGET_IS_SENSITIVE (widget) ||
3240 icon_info->insensitive)
3242 GdkPixbuf *temp_pixbuf;
3244 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3245 gdk_pixbuf_saturate_and_pixelate (pixbuf,
3249 g_object_unref (pixbuf);
3250 pixbuf = temp_pixbuf;
3252 else if (icon_info->prelight)
3254 GdkPixbuf *temp_pixbuf;
3256 temp_pixbuf = gdk_pixbuf_copy (pixbuf);
3257 colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
3258 g_object_unref (pixbuf);
3259 pixbuf = temp_pixbuf;
3262 gdk_draw_pixbuf (icon_info->window, widget->style->black_gc, pixbuf,
3264 GDK_RGB_DITHER_NORMAL, 0, 0);
3266 g_object_unref (pixbuf);
3271 gtk_entry_draw_frame (GtkWidget *widget,
3272 GdkEventExpose *event)
3274 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3275 gint x = 0, y = 0, width, height;
3276 gboolean state_hint;
3279 gdk_drawable_get_size (widget->window, &width, &height);
3281 /* Fix a problem with some themes which assume that entry->text_area's
3282 * width equals widget->window's width */
3283 if (GTK_IS_SPIN_BUTTON (widget))
3285 gint xborder, yborder;
3287 gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
3288 _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
3291 width += xborder * 2;
3294 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
3296 x += priv->focus_width;
3297 y += priv->focus_width;
3298 width -= 2 * priv->focus_width;
3299 height -= 2 * priv->focus_width;
3302 gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
3304 state = GTK_WIDGET_HAS_FOCUS (widget) ?
3305 GTK_STATE_ACTIVE : GTK_WIDGET_STATE (widget);
3307 state = GTK_STATE_NORMAL;
3309 gtk_paint_shadow (widget->style, widget->window,
3310 state, priv->shadow_type,
3311 &event->area, widget, "entry", x, y, width, height);
3314 gtk_entry_draw_progress (widget, event);
3316 if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
3318 x -= priv->focus_width;
3319 y -= priv->focus_width;
3320 width += 2 * priv->focus_width;
3321 height += 2 * priv->focus_width;
3323 gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
3324 &event->area, widget, "entry",
3325 0, 0, width, height);
3330 gtk_entry_get_progress_border (GtkWidget *widget,
3331 GtkBorder *progress_border)
3333 GtkBorder *tmp_border;
3335 gtk_widget_style_get (widget, "progress-border", &tmp_border, NULL);
3338 *progress_border = *tmp_border;
3339 gtk_border_free (tmp_border);
3343 progress_border->left = widget->style->xthickness;
3344 progress_border->right = widget->style->xthickness;
3345 progress_border->top = widget->style->ythickness;
3346 progress_border->bottom = widget->style->ythickness;
3351 get_progress_area (GtkWidget *widget,
3357 GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
3358 GtkEntry *entry = GTK_ENTRY (widget);
3359 GtkBorder progress_border;
3361 gtk_entry_get_progress_border (widget, &progress_border);
3363 *x = progress_border.left;
3364 *y = progress_border.top;
3366 gdk_drawable_get_size (widget->window, width, height);
3368 *width -= progress_border.left + progress_border.right;
3369 *height -= progress_border.top + progress_border.bottom;
3371 if (GTK_WIDGET_HAS_FOCUS (widget) && !private->interior_focus)
3373 *x += private->focus_width;
3374 *y += private->focus_width;
3375 *width -= 2 * private->focus_width;
3376 *height -= 2 * private->focus_width;
3379 if (private->progress_pulse_mode)
3381 gdouble value = private->progress_pulse_current;
3383 *x += (gint) floor(value * (*width));
3384 *width = (gint) ceil(private->progress_pulse_fraction * (*width));
3386 else if (private->progress_fraction > 0)
3388 gdouble value = private->progress_fraction;
3390 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
3394 bar_width = floor(value * (*width) + 0.5);
3395 *x += *width - bar_width;
3400 *width = (gint) floor(value * (*width) + 0.5);
3411 gtk_entry_draw_progress (GtkWidget *widget,
3412 GdkEventExpose *event)
3414 gint x, y, width, height;
3417 get_progress_area (widget, &x, &y, &width, &height);
3419 if ((width <= 0) || (height <= 0))
3422 if (event->window != widget->window)
3426 gdk_window_get_position (event->window, &pos_x, &pos_y);
3432 state = GTK_STATE_SELECTED;
3433 if (!GTK_WIDGET_SENSITIVE (widget))
3434 state = GTK_STATE_INSENSITIVE;
3436 gtk_paint_box (widget->style, event->window,
3437 state, GTK_SHADOW_OUT,
3438 &event->area, widget, "entry-progress",
3444 gtk_entry_expose (GtkWidget *widget,
3445 GdkEventExpose *event)
3447 GtkEntry *entry = GTK_ENTRY (widget);
3448 gboolean state_hint;
3450 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3452 gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
3454 state = GTK_WIDGET_HAS_FOCUS (widget) ?
3455 GTK_STATE_ACTIVE : GTK_WIDGET_STATE (widget);
3457 state = GTK_WIDGET_STATE(widget);
3459 if (widget->window == event->window)
3461 gtk_entry_draw_frame (widget, event);
3463 else if (entry->text_area == event->window)
3467 gdk_drawable_get_size (entry->text_area, &width, &height);
3469 gtk_paint_flat_box (widget->style, entry->text_area,
3470 state, GTK_SHADOW_NONE,
3471 &event->area, widget, "entry_bg",
3472 0, 0, width, height);
3474 gtk_entry_draw_progress (widget, event);
3476 if (entry->dnd_position != -1)
3477 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_DND);
3479 gtk_entry_draw_text (GTK_ENTRY (widget));
3481 /* When no text is being displayed at all, don't show the cursor */
3482 if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
3483 GTK_WIDGET_HAS_FOCUS (widget) &&
3484 entry->selection_bound == entry->current_pos && entry->cursor_visible)
3485 gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_STANDARD);
3491 for (i = 0; i < MAX_ICONS; i++)
3493 EntryIconInfo *icon_info = priv->icons[i];
3495 if (icon_info != NULL && event->window == icon_info->window)
3499 gdk_drawable_get_size (icon_info->window, &width, &height);
3501 gtk_paint_flat_box (widget->style, icon_info->window,
3502 GTK_WIDGET_STATE (widget), GTK_SHADOW_NONE,
3503 NULL, widget, "entry_bg",
3504 0, 0, width, height);
3506 gtk_entry_draw_progress (widget, event);
3507 draw_icon (widget, i);
3518 gtk_entry_enter_notify (GtkWidget *widget,
3519 GdkEventCrossing *event)
3521 GtkEntry *entry = GTK_ENTRY (widget);
3522 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3525 for (i = 0; i < MAX_ICONS; i++)
3527 EntryIconInfo *icon_info = priv->icons[i];
3529 if (icon_info != NULL && event->window == icon_info->window)
3531 if (should_prelight (entry, i))
3533 icon_info->prelight = TRUE;
3534 gtk_widget_queue_draw (widget);
3545 gtk_entry_leave_notify (GtkWidget *widget,
3546 GdkEventCrossing *event)
3548 GtkEntry *entry = GTK_ENTRY (widget);
3549 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3552 for (i = 0; i < MAX_ICONS; i++)
3554 EntryIconInfo *icon_info = priv->icons[i];
3556 if (icon_info != NULL && event->window == icon_info->window)
3558 /* a grab means that we may never see the button release */
3559 if (event->mode == GDK_CROSSING_GRAB || event->mode == GDK_CROSSING_GTK_GRAB)
3560 icon_info->pressed = FALSE;
3562 if (should_prelight (entry, i))
3564 icon_info->prelight = FALSE;
3565 gtk_widget_queue_draw (widget);
3576 gtk_entry_get_pixel_ranges (GtkEntry *entry,
3580 gint start_char, end_char;
3582 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
3584 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
3585 PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
3586 const char *text = pango_layout_get_text (layout);
3587 gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
3588 gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
3589 gint real_n_ranges, i;
3591 pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
3597 for (i = 0; i < real_n_ranges; ++i)
3599 r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
3600 r[2 * i] = r[2 * i] / PANGO_SCALE;
3605 *n_ranges = real_n_ranges;
3617 in_selection (GtkEntry *entry,
3622 gint retval = FALSE;
3624 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
3626 for (i = 0; i < n_ranges; ++i)
3628 if (x >= ranges[2 * i] && x < ranges[2 * i] + ranges[2 * i + 1])
3640 gtk_entry_button_press (GtkWidget *widget,
3641 GdkEventButton *event)
3643 GtkEntry *entry = GTK_ENTRY (widget);
3644 GtkEditable *editable = GTK_EDITABLE (widget);
3645 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3646 EntryIconInfo *icon_info = NULL;
3648 gint sel_start, sel_end;
3651 for (i = 0; i < MAX_ICONS; i++)
3653 icon_info = priv->icons[i];
3655 if (!icon_info || icon_info->insensitive)
3658 if (event->window == icon_info->window)
3660 if (should_prelight (entry, i))
3662 icon_info->prelight = FALSE;
3663 gtk_widget_queue_draw (widget);
3666 priv->start_x = event->x;
3667 priv->start_y = event->y;
3668 icon_info->pressed = TRUE;
3670 if (!icon_info->nonactivatable)
3671 g_signal_emit (entry, signals[ICON_PRESS], 0, i, event);
3677 if (event->window != entry->text_area ||
3678 (entry->button && event->button != entry->button))
3681 gtk_entry_reset_blink_time (entry);
3683 entry->button = event->button;
3685 if (!GTK_WIDGET_HAS_FOCUS (widget))
3687 entry->in_click = TRUE;
3688 gtk_widget_grab_focus (widget);
3689 entry->in_click = FALSE;
3692 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
3694 if (event->button == 1)
3696 gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
3698 entry->select_words = FALSE;
3699 entry->select_lines = FALSE;
3701 if (event->state & GDK_SHIFT_MASK)
3703 _gtk_entry_reset_im_context (entry);
3705 if (!have_selection) /* select from the current position to the clicked position */
3706 sel_start = sel_end = entry->current_pos;
3708 if (tmp_pos > sel_start && tmp_pos < sel_end)
3710 /* Truncate current selection, but keep it as big as possible */
3711 if (tmp_pos - sel_start > sel_end - tmp_pos)
3712 gtk_entry_set_positions (entry, sel_start, tmp_pos);
3714 gtk_entry_set_positions (entry, tmp_pos, sel_end);
3718 gboolean extend_to_left;
3721 /* Figure out what click selects and extend current selection */
3722 switch (event->type)
3724 case GDK_BUTTON_PRESS:
3725 gtk_entry_set_positions (entry, tmp_pos, tmp_pos);
3728 case GDK_2BUTTON_PRESS:
3729 entry->select_words = TRUE;
3730 gtk_entry_select_word (entry);
3733 case GDK_3BUTTON_PRESS:
3734 entry->select_lines = TRUE;
3735 gtk_entry_select_line (entry);
3742 start = MIN (entry->current_pos, entry->selection_bound);
3743 start = MIN (sel_start, start);
3745 end = MAX (entry->current_pos, entry->selection_bound);
3746 end = MAX (sel_end, end);
3748 if (tmp_pos == sel_start || tmp_pos == sel_end)
3749 extend_to_left = (tmp_pos == start);
3751 extend_to_left = (end == sel_end);
3754 gtk_entry_set_positions (entry, start, end);
3756 gtk_entry_set_positions (entry, end, start);
3759 else /* no shift key */
3760 switch (event->type)
3762 case GDK_BUTTON_PRESS:
3763 if (in_selection (entry, event->x + entry->scroll_offset))
3765 /* Click inside the selection - we'll either start a drag, or
3766 * clear the selection
3768 entry->in_drag = TRUE;
3769 entry->drag_start_x = event->x + entry->scroll_offset;
3770 entry->drag_start_y = event->y;
3773 gtk_editable_set_position (editable, tmp_pos);
3776 case GDK_2BUTTON_PRESS:
3777 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3778 * receiving a GDK_2BUTTON_PRESS so we need to reset
3779 * entry->in_drag which may have been set above
3781 entry->in_drag = FALSE;
3782 entry->select_words = TRUE;
3783 gtk_entry_select_word (entry);
3786 case GDK_3BUTTON_PRESS:
3787 /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
3788 * receiving a GDK_3BUTTON_PRESS so we need to reset
3789 * entry->in_drag which may have been set above
3791 entry->in_drag = FALSE;
3792 entry->select_lines = TRUE;
3793 gtk_entry_select_line (entry);
3802 else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
3804 if (entry->editable)
3806 priv->insert_pos = tmp_pos;
3807 gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
3812 gtk_widget_error_bell (widget);
3815 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3817 gtk_entry_do_popup (entry, event);
3818 entry->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
3827 gtk_entry_button_release (GtkWidget *widget,
3828 GdkEventButton *event)
3830 GtkEntry *entry = GTK_ENTRY (widget);
3831 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
3832 EntryIconInfo *icon_info = NULL;
3835 for (i = 0; i < MAX_ICONS; i++)
3837 icon_info = priv->icons[i];
3839 if (!icon_info || icon_info->insensitive)
3842 if (event->window == icon_info->window)
3846 gdk_drawable_get_size (icon_info->window, &width, &height);
3848 icon_info->pressed = FALSE;
3850 if (should_prelight (entry, i) &&
3851 event->x >= 0 && event->y >= 0 &&
3852 event->x < width && event->y < height)
3854 icon_info->prelight = TRUE;
3855 gtk_widget_queue_draw (widget);
3858 if (!icon_info->nonactivatable)
3859 g_signal_emit (entry, signals[ICON_RELEASE], 0, i, event);
3865 if (event->window != entry->text_area || entry->button != event->button)
3870 gint tmp_pos = gtk_entry_find_position (entry, entry->drag_start_x);
3872 gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
3879 gtk_entry_update_primary_selection (entry);
3885 _gtk_entry_get_selected_text (GtkEntry *entry)
3887 GtkEditable *editable = GTK_EDITABLE (entry);
3888 gint start_text, end_text;
3891 if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
3892 text = gtk_editable_get_chars (editable, start_text, end_text);
3898 gtk_entry_motion_notify (GtkWidget *widget,
3899 GdkEventMotion *event)
3901 GtkEntry *entry = GTK_ENTRY (widget);
3902 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
3903 EntryIconInfo *icon_info = NULL;
3904 GdkDragContext *context;
3908 for (i = 0; i < MAX_ICONS; i++)
3910 icon_info = priv->icons[i];
3912 if (!icon_info || icon_info->insensitive)
3915 if (event->window == icon_info->window)
3917 if (icon_info->pressed &&
3918 icon_info->target_list != NULL &&
3919 gtk_drag_check_threshold (widget,
3925 icon_info->in_drag = TRUE;
3926 icon_info->pressed = FALSE;
3927 context = gtk_drag_begin (widget,
3928 icon_info->target_list,
3938 if (entry->mouse_cursor_obscured)
3942 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
3943 gdk_window_set_cursor (entry->text_area, cursor);
3944 gdk_cursor_unref (cursor);
3945 entry->mouse_cursor_obscured = FALSE;
3948 if (event->window != entry->text_area || entry->button != 1)
3951 if (entry->select_lines)
3954 gdk_event_request_motions (event);
3958 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
3959 gtk_drag_check_threshold (widget,
3960 entry->drag_start_x, entry->drag_start_y,
3961 event->x + entry->scroll_offset, event->y))
3963 GdkDragContext *context;
3964 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
3965 guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
3967 GdkPixmap *pixmap = NULL;
3969 gtk_target_list_add_text_targets (target_list, 0);
3971 text = _gtk_entry_get_selected_text (entry);
3972 pixmap = _gtk_text_util_create_drag_icon (widget, text, -1);
3974 context = gtk_drag_begin (widget, target_list, actions,
3975 entry->button, (GdkEvent *)event);
3978 gtk_drag_set_icon_pixmap (context,
3979 gdk_drawable_get_colormap (pixmap),
3984 gtk_drag_set_icon_default (context);
3987 g_object_unref (pixmap);
3990 entry->in_drag = FALSE;
3993 gtk_target_list_unref (target_list);
3999 gdk_drawable_get_size (entry->text_area, NULL, &height);
4003 else if (event->y >= height)
4004 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
4006 tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
4008 if (entry->select_words)
4011 gint old_min, old_max;
4014 min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
4015 max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
4017 pos = entry->current_pos;
4018 bound = entry->selection_bound;
4020 old_min = MIN(entry->current_pos, entry->selection_bound);
4021 old_max = MAX(entry->current_pos, entry->selection_bound);
4028 else if (old_max < max)
4033 else if (pos == old_min)
4035 if (entry->current_pos != min)
4040 if (entry->current_pos != max)
4044 gtk_entry_set_positions (entry, pos, bound);
4047 gtk_entry_set_positions (entry, tmp_pos, -1);
4054 set_invisible_cursor (GdkWindow *window)
4056 GdkDisplay *display;
4059 display = gdk_drawable_get_display (window);
4060 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
4062 gdk_window_set_cursor (window, cursor);
4064 gdk_cursor_unref (cursor);
4068 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
4070 if (entry->mouse_cursor_obscured)
4073 set_invisible_cursor (entry->text_area);
4075 entry->mouse_cursor_obscured = TRUE;
4079 gtk_entry_key_press (GtkWidget *widget,
4082 GtkEntry *entry = GTK_ENTRY (widget);
4084 gtk_entry_reset_blink_time (entry);
4085 gtk_entry_pend_cursor_blink (entry);
4087 if (entry->editable)
4089 if (gtk_im_context_filter_keypress (entry->im_context, event))
4091 gtk_entry_obscure_mouse_cursor (entry);
4092 entry->need_im_reset = TRUE;
4097 if (event->keyval == GDK_Return ||
4098 event->keyval == GDK_KP_Enter ||
4099 event->keyval == GDK_ISO_Enter ||
4100 event->keyval == GDK_Escape)
4102 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
4104 if (completion && completion->priv->completion_timeout)
4106 g_source_remove (completion->priv->completion_timeout);
4107 completion->priv->completion_timeout = 0;
4110 _gtk_entry_reset_im_context (entry);
4113 if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
4114 /* Activate key bindings
4118 if (!entry->editable && event->length)
4119 gtk_widget_error_bell (widget);
4125 gtk_entry_key_release (GtkWidget *widget,
4128 GtkEntry *entry = GTK_ENTRY (widget);
4130 if (entry->editable)
4132 if (gtk_im_context_filter_keypress (entry->im_context, event))
4134 entry->need_im_reset = TRUE;
4139 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
4143 gtk_entry_focus_in (GtkWidget *widget,
4144 GdkEventFocus *event)
4146 GtkEntry *entry = GTK_ENTRY (widget);
4149 gtk_widget_queue_draw (widget);
4151 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4153 if (entry->editable)
4155 entry->need_im_reset = TRUE;
4156 gtk_im_context_focus_in (entry->im_context);
4157 keymap_state_changed (keymap, entry);
4158 g_signal_connect (keymap, "state-changed",
4159 G_CALLBACK (keymap_state_changed), entry);
4162 g_signal_connect (keymap, "direction-changed",
4163 G_CALLBACK (keymap_direction_changed), entry);
4165 gtk_entry_reset_blink_time (entry);
4166 gtk_entry_check_cursor_blink (entry);
4172 gtk_entry_focus_out (GtkWidget *widget,
4173 GdkEventFocus *event)
4175 GtkEntry *entry = GTK_ENTRY (widget);
4176 GtkEntryCompletion *completion;
4179 gtk_widget_queue_draw (widget);
4181 keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
4183 if (entry->editable)
4185 entry->need_im_reset = TRUE;
4186 gtk_im_context_focus_out (entry->im_context);
4187 remove_capslock_feedback (entry);
4190 gtk_entry_check_cursor_blink (entry);
4192 g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
4193 g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
4195 completion = gtk_entry_get_completion (entry);
4197 _gtk_entry_completion_popdown (completion);
4203 gtk_entry_grab_focus (GtkWidget *widget)
4205 GtkEntry *entry = GTK_ENTRY (widget);
4206 gboolean select_on_focus;
4208 GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
4210 if (entry->editable && !entry->in_click)
4212 g_object_get (gtk_widget_get_settings (widget),
4213 "gtk-entry-select-on-focus",
4217 if (select_on_focus)
4218 gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
4223 gtk_entry_direction_changed (GtkWidget *widget,
4224 GtkTextDirection previous_dir)
4226 GtkEntry *entry = GTK_ENTRY (widget);
4228 gtk_entry_recompute (entry);
4230 GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
4234 gtk_entry_state_changed (GtkWidget *widget,
4235 GtkStateType previous_state)
4237 GtkEntry *entry = GTK_ENTRY (widget);
4238 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
4242 if (GTK_WIDGET_REALIZED (widget))
4244 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4245 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4246 for (i = 0; i < MAX_ICONS; i++)
4248 EntryIconInfo *icon_info = priv->icons[i];
4249 if (icon_info && icon_info->window)
4250 gdk_window_set_background (icon_info->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4253 if (GTK_WIDGET_IS_SENSITIVE (widget))
4254 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
4258 gdk_window_set_cursor (entry->text_area, cursor);
4261 gdk_cursor_unref (cursor);
4263 entry->mouse_cursor_obscured = FALSE;
4265 update_cursors (widget);
4268 if (!GTK_WIDGET_IS_SENSITIVE (widget))
4270 /* Clear any selection */
4271 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
4274 gtk_widget_queue_draw (widget);
4278 gtk_entry_screen_changed (GtkWidget *widget,
4279 GdkScreen *old_screen)
4281 gtk_entry_recompute (GTK_ENTRY (widget));
4284 /* GtkEditable method implementations
4287 gtk_entry_insert_text (GtkEditable *editable,
4288 const gchar *new_text,
4289 gint new_text_length,
4292 g_object_ref (editable);
4295 * The incoming text may a password or other secret. We make sure
4296 * not to copy it into temporary buffers.
4299 g_signal_emit_by_name (editable, "insert-text", new_text, new_text_length, position);
4301 g_object_unref (editable);
4305 gtk_entry_delete_text (GtkEditable *editable,
4309 g_object_ref (editable);
4311 g_signal_emit_by_name (editable, "delete-text", start_pos, end_pos);
4313 g_object_unref (editable);
4317 gtk_entry_get_chars (GtkEditable *editable,
4321 GtkEntry *entry = GTK_ENTRY (editable);
4324 gint start_index, end_index;
4326 text = gtk_entry_buffer_get_text (get_buffer (entry));
4327 text_length = gtk_entry_buffer_get_length (get_buffer (entry));
4330 end_pos = text_length;
4332 start_pos = MIN (text_length, start_pos);
4333 end_pos = MIN (text_length, end_pos);
4335 start_index = g_utf8_offset_to_pointer (text, start_pos) - entry->text;
4336 end_index = g_utf8_offset_to_pointer (text, end_pos) - entry->text;
4338 return g_strndup (text + start_index, end_index - start_index);
4342 gtk_entry_real_set_position (GtkEditable *editable,
4345 GtkEntry *entry = GTK_ENTRY (editable);
4349 length = gtk_entry_buffer_get_length (get_buffer (entry));
4350 if (position < 0 || position > length)
4353 if (position != entry->current_pos ||
4354 position != entry->selection_bound)
4356 _gtk_entry_reset_im_context (entry);
4357 gtk_entry_set_positions (entry, position, position);
4362 gtk_entry_get_position (GtkEditable *editable)
4364 return GTK_ENTRY (editable)->current_pos;
4368 gtk_entry_set_selection_bounds (GtkEditable *editable,
4372 GtkEntry *entry = GTK_ENTRY (editable);
4375 length = gtk_entry_buffer_get_length (get_buffer (entry));
4381 _gtk_entry_reset_im_context (entry);
4383 gtk_entry_set_positions (entry,
4385 MIN (start, length));
4387 gtk_entry_update_primary_selection (entry);
4391 gtk_entry_get_selection_bounds (GtkEditable *editable,
4395 GtkEntry *entry = GTK_ENTRY (editable);
4397 *start = entry->selection_bound;
4398 *end = entry->current_pos;
4400 return (entry->selection_bound != entry->current_pos);
4404 icon_theme_changed (GtkEntry *entry)
4406 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4409 for (i = 0; i < MAX_ICONS; i++)
4411 EntryIconInfo *icon_info = priv->icons[i];
4412 if (icon_info != NULL)
4414 if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
4415 gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
4416 else if (icon_info->storage_type == GTK_IMAGE_STOCK)
4417 gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
4418 else if (icon_info->storage_type == GTK_IMAGE_GICON)
4419 gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
4423 gtk_widget_queue_draw (GTK_WIDGET (entry));
4427 icon_margin_changed (GtkEntry *entry)
4429 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4432 _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
4434 priv->icon_margin = border.left;
4438 gtk_entry_style_set (GtkWidget *widget,
4439 GtkStyle *previous_style)
4441 GtkEntry *entry = GTK_ENTRY (widget);
4442 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
4444 gboolean interior_focus;
4447 gtk_widget_style_get (widget,
4448 "focus-line-width", &focus_width,
4449 "interior-focus", &interior_focus,
4452 priv->focus_width = focus_width;
4453 priv->interior_focus = interior_focus;
4455 if (!priv->invisible_char_set)
4456 entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
4458 gtk_entry_recompute (entry);
4460 if (previous_style && GTK_WIDGET_REALIZED (widget))
4462 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4463 gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4464 for (i = 0; i < MAX_ICONS; i++)
4466 EntryIconInfo *icon_info = priv->icons[i];
4467 if (icon_info && icon_info->window)
4468 gdk_window_set_background (icon_info->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
4472 icon_theme_changed (entry);
4473 icon_margin_changed (entry);
4476 /* GtkCellEditable method implementations
4479 gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
4481 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4482 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4486 gtk_cell_editable_key_press_event (GtkEntry *entry,
4487 GdkEventKey *key_event,
4490 if (key_event->keyval == GDK_Escape)
4492 entry->editing_canceled = TRUE;
4493 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4494 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4499 /* override focus */
4500 if (key_event->keyval == GDK_Up || key_event->keyval == GDK_Down)
4502 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
4503 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
4512 gtk_entry_start_editing (GtkCellEditable *cell_editable,
4515 GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
4517 g_signal_connect (cell_editable, "activate",
4518 G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
4519 g_signal_connect (cell_editable, "key-press-event",
4520 G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
4524 gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
4526 if (password_hint->source_id)
4527 g_source_remove (password_hint->source_id);
4529 g_slice_free (GtkEntryPasswordHint, password_hint);
4534 gtk_entry_remove_password_hint (gpointer data)
4536 GtkEntryPasswordHint *password_hint = g_object_get_qdata (data, quark_password_hint);
4537 password_hint->position = -1;
4539 /* Force the string to be redrawn, but now without a visible character */
4540 gtk_entry_recompute (GTK_ENTRY (data));
4544 /* Default signal handlers
4547 gtk_entry_real_insert_text (GtkEditable *editable,
4548 const gchar *new_text,
4549 gint new_text_length,
4555 n_chars = g_utf8_strlen (new_text, new_text_length);
4558 * The actual insertion into the buffer. This will end up firing the
4559 * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
4560 * buffer_notify_text(), buffer_notify_length()
4562 n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
4564 if (n_inserted != n_chars)
4565 gtk_widget_error_bell (GTK_WIDGET (editable));
4567 *position += n_inserted;
4571 gtk_entry_real_delete_text (GtkEditable *editable,
4576 * The actual deletion from the buffer. This will end up firing the
4577 * following signal handlers: buffer_deleted_text(), buffer_notify_display_text(),
4578 * buffer_notify_text(), buffer_notify_length()
4581 gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
4584 /* GtkEntryBuffer signal handlers
4587 buffer_inserted_text (GtkEntryBuffer *buffer,
4593 guint password_hint_timeout;
4595 if (entry->current_pos > position)
4596 entry->current_pos += n_chars;
4598 if (entry->selection_bound > position)
4599 entry->selection_bound += n_chars;
4601 /* Calculate the password hint if it needs to be displayed. */
4602 if (n_chars == 1 && !entry->visible)
4604 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4605 "gtk-entry-password-hint-timeout", &password_hint_timeout,
4608 if (password_hint_timeout > 0)
4610 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4611 quark_password_hint);
4614 password_hint = g_slice_new0 (GtkEntryPasswordHint);
4615 g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint, password_hint,
4616 (GDestroyNotify)gtk_entry_password_hint_free);
4619 password_hint->position = position;
4620 if (password_hint->source_id)
4621 g_source_remove (password_hint->source_id);
4622 password_hint->source_id = gdk_threads_add_timeout (password_hint_timeout,
4623 (GSourceFunc)gtk_entry_remove_password_hint, entry);
4629 buffer_deleted_text (GtkEntryBuffer *buffer,
4634 guint end_pos = position + n_chars;
4635 gint selection_bound;
4638 current_pos = entry->current_pos;
4639 if (current_pos > position)
4640 current_pos -= MIN (current_pos, end_pos) - position;
4642 selection_bound = entry->selection_bound;
4643 if (selection_bound > position)
4644 selection_bound -= MIN (selection_bound, end_pos) - position;
4646 gtk_entry_set_positions (entry, current_pos, selection_bound);
4648 /* We might have deleted the selection */
4649 gtk_entry_update_primary_selection (entry);
4651 /* Disable the password hint if one exists. */
4652 if (!entry->visible)
4654 GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
4655 quark_password_hint);
4658 if (password_hint->source_id)
4659 g_source_remove (password_hint->source_id);
4660 password_hint->source_id = 0;
4661 password_hint->position = -1;
4667 buffer_notify_text (GtkEntryBuffer *buffer,
4671 /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
4672 entry->text = (gchar*)gtk_entry_buffer_get_text (buffer);
4674 gtk_entry_recompute (entry);
4675 emit_changed (entry);
4676 g_object_notify (G_OBJECT (entry), "text");
4680 buffer_notify_length (GtkEntryBuffer *buffer,
4684 /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
4685 entry->text_length = gtk_entry_buffer_get_length (buffer);
4687 g_object_notify (G_OBJECT (entry), "text-length");
4691 buffer_notify_max_length (GtkEntryBuffer *buffer,
4695 /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
4696 entry->text_max_length = gtk_entry_buffer_get_max_length (buffer);
4698 g_object_notify (G_OBJECT (entry), "max-length");
4702 buffer_connect_signals (GtkEntry *entry)
4704 g_signal_connect (get_buffer (entry), "inserted-text", G_CALLBACK (buffer_inserted_text), entry);
4705 g_signal_connect (get_buffer (entry), "deleted-text", G_CALLBACK (buffer_deleted_text), entry);
4706 g_signal_connect (get_buffer (entry), "notify::text", G_CALLBACK (buffer_notify_text), entry);
4707 g_signal_connect (get_buffer (entry), "notify::length", G_CALLBACK (buffer_notify_length), entry);
4708 g_signal_connect (get_buffer (entry), "notify::max-length", G_CALLBACK (buffer_notify_max_length), entry);
4712 buffer_disconnect_signals (GtkEntry *entry)
4714 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_inserted_text, entry);
4715 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_deleted_text, entry);
4716 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_text, entry);
4717 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_length, entry);
4718 g_signal_handlers_disconnect_by_func (get_buffer (entry), buffer_notify_max_length, entry);
4721 /* Compute the X position for an offset that corresponds to the "more important
4722 * cursor position for that offset. We use this when trying to guess to which
4723 * end of the selection we should go to when the user hits the left or
4727 get_better_cursor_x (GtkEntry *entry,
4730 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
4731 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
4732 gboolean split_cursor;
4734 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
4735 const gchar *text = pango_layout_get_text (layout);
4736 gint index = g_utf8_offset_to_pointer (text, offset) - text;
4738 PangoRectangle strong_pos, weak_pos;
4740 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
4741 "gtk-split-cursor", &split_cursor,
4744 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
4747 return strong_pos.x / PANGO_SCALE;
4749 return (keymap_direction == entry->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
4753 gtk_entry_move_cursor (GtkEntry *entry,
4754 GtkMovementStep step,
4756 gboolean extend_selection)
4758 gint new_pos = entry->current_pos;
4759 GtkEntryPrivate *priv;
4761 _gtk_entry_reset_im_context (entry);
4763 if (entry->current_pos != entry->selection_bound && !extend_selection)
4765 /* If we have a current selection and aren't extending it, move to the
4766 * start/or end of the selection as appropriate
4770 case GTK_MOVEMENT_VISUAL_POSITIONS:
4772 gint current_x = get_better_cursor_x (entry, entry->current_pos);
4773 gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
4776 new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
4778 new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
4781 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4782 case GTK_MOVEMENT_WORDS:
4784 new_pos = MIN (entry->current_pos, entry->selection_bound);
4786 new_pos = MAX (entry->current_pos, entry->selection_bound);
4788 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4789 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4790 case GTK_MOVEMENT_BUFFER_ENDS:
4791 priv = GTK_ENTRY_GET_PRIVATE (entry);
4792 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4794 case GTK_MOVEMENT_DISPLAY_LINES:
4795 case GTK_MOVEMENT_PARAGRAPHS:
4796 case GTK_MOVEMENT_PAGES:
4797 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4805 case GTK_MOVEMENT_LOGICAL_POSITIONS:
4806 new_pos = gtk_entry_move_logically (entry, new_pos, count);
4808 case GTK_MOVEMENT_VISUAL_POSITIONS:
4809 new_pos = gtk_entry_move_visually (entry, new_pos, count);
4810 if (entry->current_pos == new_pos)
4812 if (!extend_selection)
4814 if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
4816 GTK_DIR_RIGHT : GTK_DIR_LEFT))
4818 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
4821 gtk_widget_child_focus (toplevel,
4823 GTK_DIR_RIGHT : GTK_DIR_LEFT);
4828 gtk_widget_error_bell (GTK_WIDGET (entry));
4832 case GTK_MOVEMENT_WORDS:
4835 new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
4840 new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
4843 if (entry->current_pos == new_pos)
4844 gtk_widget_error_bell (GTK_WIDGET (entry));
4846 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
4847 case GTK_MOVEMENT_PARAGRAPH_ENDS:
4848 case GTK_MOVEMENT_BUFFER_ENDS:
4849 priv = GTK_ENTRY_GET_PRIVATE (entry);
4850 new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
4851 if (entry->current_pos == new_pos)
4852 gtk_widget_error_bell (GTK_WIDGET (entry));
4854 case GTK_MOVEMENT_DISPLAY_LINES:
4855 case GTK_MOVEMENT_PARAGRAPHS:
4856 case GTK_MOVEMENT_PAGES:
4857 case GTK_MOVEMENT_HORIZONTAL_PAGES:
4862 if (extend_selection)
4863 gtk_editable_select_region (GTK_EDITABLE (entry), entry->selection_bound, new_pos);
4865 gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
4867 gtk_entry_pend_cursor_blink (entry);
4871 gtk_entry_insert_at_cursor (GtkEntry *entry,
4874 GtkEditable *editable = GTK_EDITABLE (entry);
4875 gint pos = entry->current_pos;
4877 if (entry->editable)
4879 _gtk_entry_reset_im_context (entry);
4881 gtk_editable_insert_text (editable, str, -1, &pos);
4882 gtk_editable_set_position (editable, pos);
4887 gtk_entry_delete_from_cursor (GtkEntry *entry,
4891 GtkEditable *editable = GTK_EDITABLE (entry);
4892 gint start_pos = entry->current_pos;
4893 gint end_pos = entry->current_pos;
4894 gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
4896 _gtk_entry_reset_im_context (entry);
4898 if (!entry->editable)
4900 gtk_widget_error_bell (GTK_WIDGET (entry));
4904 if (entry->selection_bound != entry->current_pos)
4906 gtk_editable_delete_selection (editable);
4912 case GTK_DELETE_CHARS:
4913 end_pos = gtk_entry_move_logically (entry, entry->current_pos, count);
4914 gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
4916 case GTK_DELETE_WORDS:
4919 /* Move to end of current word, or if not on a word, end of previous word */
4920 end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
4921 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4925 /* Move to beginning of current word, or if not on a word, begining of next word */
4926 start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
4927 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4931 case GTK_DELETE_WORD_ENDS:
4934 start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
4939 end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
4942 gtk_editable_delete_text (editable, start_pos, end_pos);
4944 case GTK_DELETE_DISPLAY_LINE_ENDS:
4945 case GTK_DELETE_PARAGRAPH_ENDS:
4947 gtk_editable_delete_text (editable, 0, entry->current_pos);
4949 gtk_editable_delete_text (editable, entry->current_pos, -1);
4951 case GTK_DELETE_DISPLAY_LINES:
4952 case GTK_DELETE_PARAGRAPHS:
4953 gtk_editable_delete_text (editable, 0, -1);
4955 case GTK_DELETE_WHITESPACE:
4956 gtk_entry_delete_whitespace (entry);
4960 if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == old_n_bytes)
4961 gtk_widget_error_bell (GTK_WIDGET (entry));
4963 gtk_entry_pend_cursor_blink (entry);
4967 gtk_entry_backspace (GtkEntry *entry)
4969 GtkEditable *editable = GTK_EDITABLE (entry);
4972 _gtk_entry_reset_im_context (entry);
4974 if (!entry->editable)
4976 gtk_widget_error_bell (GTK_WIDGET (entry));
4980 if (entry->selection_bound != entry->current_pos)
4982 gtk_editable_delete_selection (editable);
4986 prev_pos = gtk_entry_move_logically (entry, entry->current_pos, -1);
4988 if (prev_pos < entry->current_pos)
4990 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
4991 PangoLogAttr *log_attrs;
4994 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
4996 /* Deleting parts of characters */
4997 if (log_attrs[entry->current_pos].backspace_deletes_character)
4999 gchar *cluster_text;
5000 gchar *normalized_text;
5003 cluster_text = gtk_entry_get_display_text (entry, prev_pos,
5004 entry->current_pos);
5005 normalized_text = g_utf8_normalize (cluster_text,
5006 strlen (cluster_text),
5008 len = g_utf8_strlen (normalized_text, -1);
5010 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5013 gint pos = entry->current_pos;
5015 gtk_editable_insert_text (editable, normalized_text,
5016 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
5018 gtk_editable_set_position (editable, pos);
5021 g_free (normalized_text);
5022 g_free (cluster_text);
5026 gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
5033 gtk_widget_error_bell (GTK_WIDGET (entry));
5036 gtk_entry_pend_cursor_blink (entry);
5040 gtk_entry_copy_clipboard (GtkEntry *entry)
5042 GtkEditable *editable = GTK_EDITABLE (entry);
5046 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5048 if (!entry->visible)
5050 gtk_widget_error_bell (GTK_WIDGET (entry));
5054 str = gtk_entry_get_display_text (entry, start, end);
5055 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
5056 GDK_SELECTION_CLIPBOARD),
5063 gtk_entry_cut_clipboard (GtkEntry *entry)
5065 GtkEditable *editable = GTK_EDITABLE (entry);
5068 if (!entry->visible)
5070 gtk_widget_error_bell (GTK_WIDGET (entry));
5074 gtk_entry_copy_clipboard (entry);
5076 if (entry->editable)
5078 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5079 gtk_editable_delete_text (editable, start, end);
5083 gtk_widget_error_bell (GTK_WIDGET (entry));
5088 gtk_entry_paste_clipboard (GtkEntry *entry)
5090 if (entry->editable)
5091 gtk_entry_paste (entry, GDK_NONE);
5093 gtk_widget_error_bell (GTK_WIDGET (entry));
5097 gtk_entry_delete_cb (GtkEntry *entry)
5099 GtkEditable *editable = GTK_EDITABLE (entry);
5102 if (entry->editable)
5104 if (gtk_editable_get_selection_bounds (editable, &start, &end))
5105 gtk_editable_delete_text (editable, start, end);
5110 gtk_entry_toggle_overwrite (GtkEntry *entry)
5112 entry->overwrite_mode = !entry->overwrite_mode;
5113 gtk_entry_pend_cursor_blink (entry);
5114 gtk_widget_queue_draw (GTK_WIDGET (entry));
5118 gtk_entry_select_all (GtkEntry *entry)
5120 gtk_entry_select_line (entry);
5124 gtk_entry_real_activate (GtkEntry *entry)
5127 GtkWidget *toplevel;
5130 widget = GTK_WIDGET (entry);
5132 if (entry->activates_default)
5134 toplevel = gtk_widget_get_toplevel (widget);
5135 if (GTK_IS_WINDOW (toplevel))
5137 window = GTK_WINDOW (toplevel);
5140 widget != window->default_widget &&
5141 !(widget == window->focus_widget &&
5142 (!window->default_widget || !GTK_WIDGET_SENSITIVE (window->default_widget))))
5143 gtk_window_activate_default (window);
5149 keymap_direction_changed (GdkKeymap *keymap,
5152 gtk_entry_recompute (entry);
5155 /* IM Context Callbacks
5159 gtk_entry_commit_cb (GtkIMContext *context,
5163 if (entry->editable)
5164 gtk_entry_enter_text (entry, str);
5168 gtk_entry_preedit_changed_cb (GtkIMContext *context,
5171 if (entry->editable)
5173 gchar *preedit_string;
5176 gtk_im_context_get_preedit_string (entry->im_context,
5177 &preedit_string, NULL,
5179 g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
5180 entry->preedit_length = strlen (preedit_string);
5181 cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
5182 entry->preedit_cursor = cursor_pos;
5183 g_free (preedit_string);
5185 gtk_entry_recompute (entry);
5190 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
5195 /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
5196 text = gtk_entry_get_display_text (entry, 0, -1);
5197 gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
5198 g_utf8_offset_to_pointer (text, entry->current_pos) - text);
5205 gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
5210 if (entry->editable)
5211 gtk_editable_delete_text (GTK_EDITABLE (entry),
5212 entry->current_pos + offset,
5213 entry->current_pos + offset + n_chars);
5218 /* Internal functions
5221 /* Used for im_commit_cb and inserting Unicode chars */
5223 gtk_entry_enter_text (GtkEntry *entry,
5226 GtkEditable *editable = GTK_EDITABLE (entry);
5228 gboolean old_need_im_reset;
5230 old_need_im_reset = entry->need_im_reset;
5231 entry->need_im_reset = FALSE;
5233 if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
5234 gtk_editable_delete_selection (editable);
5237 if (entry->overwrite_mode)
5238 gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
5241 tmp_pos = entry->current_pos;
5242 gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
5243 gtk_editable_set_position (editable, tmp_pos);
5245 entry->need_im_reset = old_need_im_reset;
5248 /* All changes to entry->current_pos and entry->selection_bound
5249 * should go through this function.
5252 gtk_entry_set_positions (GtkEntry *entry,
5254 gint selection_bound)
5256 gboolean changed = FALSE;
5258 g_object_freeze_notify (G_OBJECT (entry));
5260 if (current_pos != -1 &&
5261 entry->current_pos != current_pos)
5263 entry->current_pos = current_pos;
5266 g_object_notify (G_OBJECT (entry), "cursor-position");
5269 if (selection_bound != -1 &&
5270 entry->selection_bound != selection_bound)
5272 entry->selection_bound = selection_bound;
5275 g_object_notify (G_OBJECT (entry), "selection-bound");
5278 g_object_thaw_notify (G_OBJECT (entry));
5282 gtk_entry_move_adjustments (entry);
5283 gtk_entry_recompute (entry);
5288 gtk_entry_reset_layout (GtkEntry *entry)
5290 if (entry->cached_layout)
5292 g_object_unref (entry->cached_layout);
5293 entry->cached_layout = NULL;
5298 update_im_cursor_location (GtkEntry *entry)
5302 gint strong_xoffset;
5303 gint area_width, area_height;
5305 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
5306 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5308 strong_xoffset = strong_x - entry->scroll_offset;
5309 if (strong_xoffset < 0)
5313 else if (strong_xoffset > area_width)
5315 strong_xoffset = area_width;
5317 area.x = strong_xoffset;
5320 area.height = area_height;
5322 gtk_im_context_set_cursor_location (entry->im_context, &area);
5326 recompute_idle_func (gpointer data)
5330 entry = GTK_ENTRY (data);
5332 entry->recompute_idle = 0;
5334 if (gtk_widget_has_screen (GTK_WIDGET (entry)))
5336 gtk_entry_adjust_scroll (entry);
5337 gtk_entry_queue_draw (entry);
5339 update_im_cursor_location (entry);
5346 gtk_entry_recompute (GtkEntry *entry)
5348 gtk_entry_reset_layout (entry);
5349 gtk_entry_check_cursor_blink (entry);
5351 if (!entry->recompute_idle)
5353 entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
5354 recompute_idle_func, entry, NULL);
5358 static PangoLayout *
5359 gtk_entry_create_layout (GtkEntry *entry,
5360 gboolean include_preedit)
5362 GtkWidget *widget = GTK_WIDGET (entry);
5363 PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
5364 PangoAttrList *tmp_attrs = pango_attr_list_new ();
5366 gchar *preedit_string = NULL;
5367 gint preedit_length = 0;
5368 PangoAttrList *preedit_attrs = NULL;
5373 pango_layout_set_single_paragraph_mode (layout, TRUE);
5375 display = gtk_entry_get_display_text (entry, 0, -1);
5376 n_bytes = strlen (display);
5378 if (include_preedit)
5380 gtk_im_context_get_preedit_string (entry->im_context,
5381 &preedit_string, &preedit_attrs, NULL);
5382 preedit_length = entry->preedit_length;
5387 GString *tmp_string = g_string_new (display);
5388 gint cursor_index = g_utf8_offset_to_pointer (display, entry->current_pos) - display;
5390 g_string_insert (tmp_string, cursor_index, preedit_string);
5392 pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
5394 pango_attr_list_splice (tmp_attrs, preedit_attrs,
5395 cursor_index, preedit_length);
5397 g_string_free (tmp_string, TRUE);
5401 PangoDirection pango_dir;
5403 if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL)
5404 pango_dir = pango_find_base_dir (display, n_bytes);
5406 pango_dir = PANGO_DIRECTION_NEUTRAL;
5408 if (pango_dir == PANGO_DIRECTION_NEUTRAL)
5410 if (GTK_WIDGET_HAS_FOCUS (widget))
5412 GdkDisplay *display = gtk_widget_get_display (widget);
5413 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
5414 if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
5415 pango_dir = PANGO_DIRECTION_RTL;
5417 pango_dir = PANGO_DIRECTION_LTR;
5421 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
5422 pango_dir = PANGO_DIRECTION_RTL;
5424 pango_dir = PANGO_DIRECTION_LTR;
5428 pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
5431 entry->resolved_dir = pango_dir;
5433 pango_layout_set_text (layout, display, n_bytes);
5436 pango_layout_set_attributes (layout, tmp_attrs);
5438 g_free (preedit_string);
5442 pango_attr_list_unref (preedit_attrs);
5444 pango_attr_list_unref (tmp_attrs);
5449 static PangoLayout *
5450 gtk_entry_ensure_layout (GtkEntry *entry,
5451 gboolean include_preedit)
5453 if (entry->preedit_length > 0 &&
5454 !include_preedit != !entry->cache_includes_preedit)
5455 gtk_entry_reset_layout (entry);
5457 if (!entry->cached_layout)
5459 entry->cached_layout = gtk_entry_create_layout (entry, include_preedit);
5460 entry->cache_includes_preedit = include_preedit;
5463 return entry->cached_layout;
5467 get_layout_position (GtkEntry *entry,
5471 PangoLayout *layout;
5472 PangoRectangle logical_rect;
5473 gint area_width, area_height;
5474 GtkBorder inner_border;
5476 PangoLayoutLine *line;
5478 layout = gtk_entry_ensure_layout (entry, TRUE);
5480 gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
5481 _gtk_entry_effective_inner_border (entry, &inner_border);
5483 area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
5485 line = pango_layout_get_lines_readonly (layout)->data;
5486 pango_layout_line_get_extents (line, NULL, &logical_rect);
5488 /* Align primarily for locale's ascent/descent */
5489 y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
5490 entry->ascent + logical_rect.y);
5492 /* Now see if we need to adjust to fit in actual drawn string */
5493 if (logical_rect.height > area_height)
5494 y_pos = (area_height - logical_rect.height) / 2;
5497 else if (y_pos + logical_rect.height > area_height)
5498 y_pos = area_height - logical_rect.height;
5500 y_pos = inner_border.top + y_pos / PANGO_SCALE;
5503 *x = inner_border.left - entry->scroll_offset;
5510 draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
5512 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5515 gint start_pos, end_pos;
5517 widget = GTK_WIDGET (entry);
5521 get_layout_position (entry, &x, &y);
5523 cairo_move_to (cr, x, y);
5524 gdk_cairo_set_source_color (cr, default_color);
5525 pango_cairo_show_layout (cr, layout);
5527 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
5531 PangoRectangle logical_rect;
5532 GdkColor *selection_color, *text_color;
5533 GtkBorder inner_border;
5535 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
5536 gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
5538 if (GTK_WIDGET_HAS_FOCUS (entry))
5540 selection_color = &widget->style->base [GTK_STATE_SELECTED];
5541 text_color = &widget->style->text [GTK_STATE_SELECTED];
5545 selection_color = &widget->style->base [GTK_STATE_ACTIVE];
5546 text_color = &widget->style->text [GTK_STATE_ACTIVE];
5549 _gtk_entry_effective_inner_border (entry, &inner_border);
5551 for (i = 0; i < n_ranges; ++i)
5552 cairo_rectangle (cr,
5553 inner_border.left - entry->scroll_offset + ranges[2 * i],
5556 logical_rect.height);
5560 gdk_cairo_set_source_color (cr, selection_color);
5563 cairo_move_to (cr, x, y);
5564 gdk_cairo_set_source_color (cr, text_color);
5565 pango_cairo_show_layout (cr, layout);
5573 gtk_entry_draw_text (GtkEntry *entry)
5575 GtkWidget *widget = GTK_WIDGET (entry);
5578 /* Nothing to display at all */
5579 if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
5582 if (GTK_WIDGET_DRAWABLE (entry))
5584 GdkColor text_color, bar_text_color;
5587 gint progress_x, progress_y, progress_width, progress_height;
5590 state = GTK_STATE_SELECTED;
5591 if (!GTK_WIDGET_SENSITIVE (widget))
5592 state = GTK_STATE_INSENSITIVE;
5593 text_color = widget->style->text[widget->state];
5594 bar_text_color = widget->style->fg[state];
5596 get_progress_area (widget,
5597 &progress_x, &progress_y,
5598 &progress_width, &progress_height);
5600 cr = gdk_cairo_create (entry->text_area);
5602 /* If the color is the same, or the progress area has a zero
5603 * size, then we only need to draw once. */
5604 if ((text_color.pixel == bar_text_color.pixel) ||
5605 ((progress_width == 0) || (progress_height == 0)))
5607 draw_text_with_color (entry, cr, &text_color);
5611 gdk_drawable_get_size (entry->text_area, &width, &height);
5613 cairo_rectangle (cr, 0, 0, width, height);
5617 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
5618 cairo_rectangle (cr, 0, 0, width, height);
5620 gdk_window_get_position (entry->text_area, &pos_x, &pos_y);
5621 progress_x -= pos_x;
5622 progress_y -= pos_y;
5624 cairo_rectangle (cr, progress_x, progress_y,
5625 progress_width, progress_height);
5627 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
5629 draw_text_with_color (entry, cr, &text_color);
5632 cairo_rectangle (cr, progress_x, progress_y,
5633 progress_width, progress_height);
5636 draw_text_with_color (entry, cr, &bar_text_color);
5644 draw_insertion_cursor (GtkEntry *entry,
5645 GdkRectangle *cursor_location,
5646 gboolean is_primary,
5647 PangoDirection direction,
5648 gboolean draw_arrow)
5650 GtkWidget *widget = GTK_WIDGET (entry);
5651 GtkTextDirection text_dir;
5653 if (direction == PANGO_DIRECTION_LTR)
5654 text_dir = GTK_TEXT_DIR_LTR;
5656 text_dir = GTK_TEXT_DIR_RTL;
5658 gtk_draw_insertion_cursor (widget, entry->text_area, NULL,
5660 is_primary, text_dir, draw_arrow);
5664 gtk_entry_draw_cursor (GtkEntry *entry,
5667 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
5668 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
5670 if (GTK_WIDGET_DRAWABLE (entry))
5672 GtkWidget *widget = GTK_WIDGET (entry);
5673 GdkRectangle cursor_location;
5674 gboolean split_cursor;
5675 PangoRectangle cursor_rect;
5676 GtkBorder inner_border;
5678 gint text_area_height;
5681 gboolean block_at_line_end;
5682 PangoLayout *layout;
5685 _gtk_entry_effective_inner_border (entry, &inner_border);
5687 xoffset = inner_border.left - entry->scroll_offset;
5689 gdk_drawable_get_size (entry->text_area, NULL, &text_area_height);
5691 layout = gtk_entry_ensure_layout (entry, TRUE);
5692 text = pango_layout_get_text (layout);
5693 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5694 if (!entry->overwrite_mode)
5697 block = _gtk_text_util_get_block_cursor_location (layout,
5698 cursor_index, &cursor_rect, &block_at_line_end);
5702 gint strong_x, weak_x;
5703 PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
5704 PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
5708 gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
5710 g_object_get (gtk_widget_get_settings (widget),
5711 "gtk-split-cursor", &split_cursor,
5714 dir1 = entry->resolved_dir;
5720 if (weak_x != strong_x)
5722 dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
5728 if (keymap_direction == entry->resolved_dir)
5734 cursor_location.x = xoffset + x1;
5735 cursor_location.y = inner_border.top;
5736 cursor_location.width = 0;
5737 cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
5739 draw_insertion_cursor (entry,
5740 &cursor_location, TRUE, dir1,
5741 dir2 != PANGO_DIRECTION_NEUTRAL);
5743 if (dir2 != PANGO_DIRECTION_NEUTRAL)
5745 cursor_location.x = xoffset + x2;
5746 draw_insertion_cursor (entry,
5747 &cursor_location, FALSE, dir2,
5751 else /* overwrite_mode */
5753 GdkColor cursor_color;
5758 get_layout_position (entry, &x, &y);
5760 rect.x = PANGO_PIXELS (cursor_rect.x) + x;
5761 rect.y = PANGO_PIXELS (cursor_rect.y) + y;
5762 rect.width = PANGO_PIXELS (cursor_rect.width);
5763 rect.height = PANGO_PIXELS (cursor_rect.height);
5765 cr = gdk_cairo_create (entry->text_area);
5767 _gtk_widget_get_cursor_color (widget, &cursor_color);
5768 gdk_cairo_set_source_color (cr, &cursor_color);
5769 gdk_cairo_rectangle (cr, &rect);
5772 if (!block_at_line_end)
5774 gdk_cairo_rectangle (cr, &rect);
5776 cairo_move_to (cr, x, y);
5777 gdk_cairo_set_source_color (cr, &widget->style->base[widget->state]);
5778 pango_cairo_show_layout (cr, layout);
5787 gtk_entry_queue_draw (GtkEntry *entry)
5789 if (GTK_WIDGET_DRAWABLE (entry))
5790 gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
5794 _gtk_entry_reset_im_context (GtkEntry *entry)
5796 if (entry->need_im_reset)
5798 entry->need_im_reset = FALSE;
5799 gtk_im_context_reset (entry->im_context);
5804 gtk_entry_find_position (GtkEntry *entry,
5807 PangoLayout *layout;
5808 PangoLayoutLine *line;
5815 layout = gtk_entry_ensure_layout (entry, TRUE);
5816 text = pango_layout_get_text (layout);
5817 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
5819 line = pango_layout_get_lines_readonly (layout)->data;
5820 pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
5822 if (index >= cursor_index && entry->preedit_length)
5824 if (index >= cursor_index + entry->preedit_length)
5825 index -= entry->preedit_length;
5828 index = cursor_index;
5833 pos = g_utf8_pointer_to_offset (text, text + index);
5840 gtk_entry_get_cursor_locations (GtkEntry *entry,
5845 DisplayMode mode = gtk_entry_get_display_mode (entry);
5847 /* Nothing to display at all, so no cursor is relevant */
5848 if (mode == DISPLAY_BLANK)
5858 PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
5859 const gchar *text = pango_layout_get_text (layout);
5860 PangoRectangle strong_pos, weak_pos;
5863 if (type == CURSOR_STANDARD)
5865 index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
5867 else /* type == CURSOR_DND */
5869 index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
5871 if (entry->dnd_position > entry->current_pos)
5873 if (mode == DISPLAY_NORMAL)
5874 index += entry->preedit_length;
5877 gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
5878 index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
5883 pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
5886 *strong_x = strong_pos.x / PANGO_SCALE;
5889 *weak_x = weak_pos.x / PANGO_SCALE;
5894 gtk_entry_adjust_scroll (GtkEntry *entry)
5896 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
5897 gint min_offset, max_offset;
5898 gint text_area_width, text_width;
5899 GtkBorder inner_border;
5900 gint strong_x, weak_x;
5901 gint strong_xoffset, weak_xoffset;
5903 PangoLayout *layout;
5904 PangoLayoutLine *line;
5905 PangoRectangle logical_rect;
5907 if (!GTK_WIDGET_REALIZED (entry))
5910 _gtk_entry_effective_inner_border (entry, &inner_border);
5912 gdk_drawable_get_size (entry->text_area, &text_area_width, NULL);
5913 text_area_width -= inner_border.left + inner_border.right;
5914 if (text_area_width < 0)
5915 text_area_width = 0;
5917 layout = gtk_entry_ensure_layout (entry, TRUE);
5918 line = pango_layout_get_lines_readonly (layout)->data;
5920 pango_layout_line_get_extents (line, NULL, &logical_rect);
5922 /* Display as much text as we can */
5924 if (entry->resolved_dir == PANGO_DIRECTION_LTR)
5925 xalign = priv->xalign;
5927 xalign = 1.0 - priv->xalign;
5929 text_width = PANGO_PIXELS(logical_rect.width);
5931 if (text_width > text_area_width)
5934 max_offset = text_width - text_area_width;
5938 min_offset = (text_width - text_area_width) * xalign;
5939 max_offset = min_offset;
5942 entry->scroll_offset = CLAMP (entry->scroll_offset, min_offset, max_offset);
5944 /* And make sure cursors are on screen. Note that the cursor is
5945 * actually drawn one pixel into the INNER_BORDER space on
5946 * the right, when the scroll is at the utmost right. This
5947 * looks better to to me than confining the cursor inside the
5948 * border entirely, though it means that the cursor gets one
5949 * pixel closer to the edge of the widget on the right than
5950 * on the left. This might need changing if one changed
5951 * INNER_BORDER from 2 to 1, as one would do on a
5952 * small-screen-real-estate display.
5954 * We always make sure that the strong cursor is on screen, and
5955 * put the weak cursor on screen if possible.
5958 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
5960 strong_xoffset = strong_x - entry->scroll_offset;
5962 if (strong_xoffset < 0)
5964 entry->scroll_offset += strong_xoffset;
5967 else if (strong_xoffset > text_area_width)
5969 entry->scroll_offset += strong_xoffset - text_area_width;
5970 strong_xoffset = text_area_width;
5973 weak_xoffset = weak_x - entry->scroll_offset;
5975 if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
5977 entry->scroll_offset += weak_xoffset;
5979 else if (weak_xoffset > text_area_width &&
5980 strong_xoffset - (weak_xoffset - text_area_width) >= 0)
5982 entry->scroll_offset += weak_xoffset - text_area_width;
5985 g_object_notify (G_OBJECT (entry), "scroll-offset");
5989 gtk_entry_move_adjustments (GtkEntry *entry)
5991 PangoContext *context;
5992 PangoFontMetrics *metrics;
5993 gint x, layout_x, border_x, border_y;
5995 GtkAdjustment *adjustment;
5997 adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
6001 /* Cursor position, layout offset, border width, and widget allocation */
6002 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
6003 get_layout_position (entry, &layout_x, NULL);
6004 _gtk_entry_get_borders (entry, &border_x, &border_y);
6005 x += entry->widget.allocation.x + layout_x + border_x;
6007 /* Approximate width of a char, so user can see what is ahead/behind */
6008 context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
6009 metrics = pango_context_get_metrics (context,
6010 entry->widget.style->font_desc,
6011 pango_context_get_language (context));
6012 char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
6015 gtk_adjustment_clamp_page (adjustment,
6016 x - (char_width + 1), /* one char + one pixel before */
6017 x + (char_width + 2)); /* one char + cursor + one pixel after */
6021 gtk_entry_move_visually (GtkEntry *entry,
6026 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6029 text = pango_layout_get_text (layout);
6031 index = g_utf8_offset_to_pointer (text, start) - text;
6035 int new_index, new_trailing;
6036 gboolean split_cursor;
6039 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
6040 "gtk-split-cursor", &split_cursor,
6047 GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
6048 PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
6050 strong = keymap_direction == entry->resolved_dir;
6055 pango_layout_move_cursor_visually (layout, strong, index, 0, 1, &new_index, &new_trailing);
6060 pango_layout_move_cursor_visually (layout, strong, index, 0, -1, &new_index, &new_trailing);
6066 else if (new_index != G_MAXINT)
6069 while (new_trailing--)
6070 index = g_utf8_next_char (text + index) - text;
6073 return g_utf8_pointer_to_offset (text, text + index);
6077 gtk_entry_move_logically (GtkEntry *entry,
6081 gint new_pos = start;
6084 length = gtk_entry_buffer_get_length (get_buffer (entry));
6086 /* Prevent any leak of information */
6087 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6089 new_pos = CLAMP (start + count, 0, length);
6093 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6094 PangoLogAttr *log_attrs;
6097 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6099 while (count > 0 && new_pos < length)
6103 while (new_pos < length && !log_attrs[new_pos].is_cursor_position);
6107 while (count < 0 && new_pos > 0)
6111 while (new_pos > 0 && !log_attrs[new_pos].is_cursor_position);
6123 gtk_entry_move_forward_word (GtkEntry *entry,
6125 gboolean allow_whitespace)
6127 gint new_pos = start;
6130 length = gtk_entry_buffer_get_length (get_buffer (entry));
6132 /* Prevent any leak of information */
6133 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6137 else if (new_pos < length)
6139 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6140 PangoLogAttr *log_attrs;
6143 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6145 /* Find the next word boundary */
6147 while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
6148 (log_attrs[new_pos].is_word_start && allow_whitespace)))
6159 gtk_entry_move_backward_word (GtkEntry *entry,
6161 gboolean allow_whitespace)
6163 gint new_pos = start;
6165 /* Prevent any leak of information */
6166 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL)
6172 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6173 PangoLogAttr *log_attrs;
6176 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6178 new_pos = start - 1;
6180 /* Find the previous word boundary */
6181 while (new_pos > 0 && !(log_attrs[new_pos].is_word_start ||
6182 (log_attrs[new_pos].is_word_end && allow_whitespace)))
6192 gtk_entry_delete_whitespace (GtkEntry *entry)
6194 PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
6195 PangoLogAttr *log_attrs;
6199 pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
6201 start = end = entry->current_pos;
6203 while (start > 0 && log_attrs[start-1].is_white)
6206 while (end < n_attrs && log_attrs[end].is_white)
6212 gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
6217 gtk_entry_select_word (GtkEntry *entry)
6219 gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos, TRUE);
6220 gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
6222 gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
6226 gtk_entry_select_line (GtkEntry *entry)
6228 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
6232 truncate_multiline (const gchar *text)
6237 text[length] && text[length] != '\n' && text[length] != '\r';
6244 paste_received (GtkClipboard *clipboard,
6248 GtkEntry *entry = GTK_ENTRY (data);
6249 GtkEditable *editable = GTK_EDITABLE (entry);
6250 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6252 if (entry->button == 2)
6254 gint pos, start, end;
6255 pos = priv->insert_pos;
6256 gtk_editable_get_selection_bounds (editable, &start, &end);
6257 if (!((start <= pos && pos <= end) || (end <= pos && pos <= start)))
6258 gtk_editable_select_region (editable, pos, pos);
6263 gint pos, start, end;
6265 gboolean popup_completion;
6266 GtkEntryCompletion *completion;
6268 completion = gtk_entry_get_completion (entry);
6270 if (entry->truncate_multiline)
6271 length = truncate_multiline (text);
6273 /* only complete if the selection is at the end */
6274 popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
6275 MAX (entry->current_pos, entry->selection_bound));
6279 if (GTK_WIDGET_MAPPED (completion->priv->popup_window))
6280 _gtk_entry_completion_popdown (completion);
6282 if (!popup_completion && completion->priv->changed_id > 0)
6283 g_signal_handler_block (entry, completion->priv->changed_id);
6286 begin_change (entry);
6287 g_object_freeze_notify (G_OBJECT (entry));
6288 if (gtk_editable_get_selection_bounds (editable, &start, &end))
6289 gtk_editable_delete_text (editable, start, end);
6291 pos = entry->current_pos;
6292 gtk_editable_insert_text (editable, text, length, &pos);
6293 gtk_editable_set_position (editable, pos);
6294 g_object_thaw_notify (G_OBJECT (entry));
6298 !popup_completion && completion->priv->changed_id > 0)
6299 g_signal_handler_unblock (entry, completion->priv->changed_id);
6302 g_object_unref (entry);
6306 gtk_entry_paste (GtkEntry *entry,
6309 g_object_ref (entry);
6310 gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
6311 paste_received, entry);
6315 primary_get_cb (GtkClipboard *clipboard,
6316 GtkSelectionData *selection_data,
6320 GtkEntry *entry = GTK_ENTRY (data);
6323 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6325 gchar *str = gtk_entry_get_display_text (entry, start, end);
6326 gtk_selection_data_set_text (selection_data, str, -1);
6332 primary_clear_cb (GtkClipboard *clipboard,
6335 GtkEntry *entry = GTK_ENTRY (data);
6337 gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
6341 gtk_entry_update_primary_selection (GtkEntry *entry)
6343 GtkTargetList *list;
6344 GtkTargetEntry *targets;
6345 GtkClipboard *clipboard;
6349 if (!GTK_WIDGET_REALIZED (entry))
6352 list = gtk_target_list_new (NULL, 0);
6353 gtk_target_list_add_text_targets (list, 0);
6355 targets = gtk_target_table_new_from_list (list, &n_targets);
6357 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
6359 if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
6361 if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
6362 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
6363 primary_clear_cb (clipboard, entry);
6367 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
6368 gtk_clipboard_clear (clipboard);
6371 gtk_target_table_free (targets, n_targets);
6372 gtk_target_list_unref (list);
6376 gtk_entry_clear (GtkEntry *entry,
6377 GtkEntryIconPosition icon_pos)
6379 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6380 EntryIconInfo *icon_info = priv->icons[icon_pos];
6382 if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
6385 g_object_freeze_notify (G_OBJECT (entry));
6387 /* Explicitly check, as the pointer may become invalidated
6388 * during destruction.
6390 if (GDK_IS_WINDOW (icon_info->window))
6391 gdk_window_hide (icon_info->window);
6393 if (icon_info->pixbuf)
6395 g_object_unref (icon_info->pixbuf);
6396 icon_info->pixbuf = NULL;
6399 switch (icon_info->storage_type)
6401 case GTK_IMAGE_PIXBUF:
6402 g_object_notify (G_OBJECT (entry),
6403 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-pixbuf" : "secondary-icon-pixbuf");
6406 case GTK_IMAGE_STOCK:
6407 g_free (icon_info->stock_id);
6408 icon_info->stock_id = NULL;
6409 g_object_notify (G_OBJECT (entry),
6410 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
6413 case GTK_IMAGE_ICON_NAME:
6414 g_free (icon_info->icon_name);
6415 icon_info->icon_name = NULL;
6416 g_object_notify (G_OBJECT (entry),
6417 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
6420 case GTK_IMAGE_GICON:
6421 if (icon_info->gicon)
6423 g_object_unref (icon_info->gicon);
6424 icon_info->gicon = NULL;
6426 g_object_notify (G_OBJECT (entry),
6427 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
6431 g_assert_not_reached ();
6435 icon_info->storage_type = GTK_IMAGE_EMPTY;
6436 g_object_notify (G_OBJECT (entry),
6437 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
6439 g_object_thaw_notify (G_OBJECT (entry));
6443 gtk_entry_ensure_pixbuf (GtkEntry *entry,
6444 GtkEntryIconPosition icon_pos)
6446 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6447 EntryIconInfo *icon_info = priv->icons[icon_pos];
6449 GtkIconTheme *icon_theme;
6450 GtkSettings *settings;
6455 if (!icon_info || icon_info->pixbuf)
6458 switch (icon_info->storage_type)
6460 case GTK_IMAGE_EMPTY:
6461 case GTK_IMAGE_PIXBUF:
6463 case GTK_IMAGE_STOCK:
6464 state = GTK_WIDGET_STATE (entry);
6465 GTK_WIDGET_STATE (entry) = GTK_STATE_NORMAL;
6466 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6467 icon_info->stock_id,
6470 if (!icon_info->pixbuf)
6471 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6472 GTK_STOCK_MISSING_IMAGE,
6475 GTK_WIDGET_STATE (entry) = state;
6478 case GTK_IMAGE_ICON_NAME:
6479 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
6482 icon_theme = gtk_icon_theme_get_for_screen (screen);
6483 settings = gtk_settings_get_for_screen (screen);
6485 gtk_icon_size_lookup_for_settings (settings,
6489 icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
6490 icon_info->icon_name,
6491 MIN (width, height),
6494 if (icon_info->pixbuf == NULL)
6496 state = GTK_WIDGET_STATE (entry);
6497 GTK_WIDGET_STATE (entry) = GTK_STATE_NORMAL;
6498 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6499 GTK_STOCK_MISSING_IMAGE,
6502 GTK_WIDGET_STATE (entry) = state;
6507 case GTK_IMAGE_GICON:
6508 screen = gtk_widget_get_screen (GTK_WIDGET (entry));
6511 icon_theme = gtk_icon_theme_get_for_screen (screen);
6512 settings = gtk_settings_get_for_screen (screen);
6514 gtk_icon_size_lookup_for_settings (settings,
6518 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
6520 MIN (width, height),
6521 GTK_ICON_LOOKUP_USE_BUILTIN);
6524 icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
6525 gtk_icon_info_free (info);
6528 if (icon_info->pixbuf == NULL)
6530 state = GTK_WIDGET_STATE (entry);
6531 GTK_WIDGET_STATE (entry) = GTK_STATE_NORMAL;
6532 icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
6533 GTK_STOCK_MISSING_IMAGE,
6536 GTK_WIDGET_STATE (entry) = state;
6542 g_assert_not_reached ();
6546 if (icon_info->pixbuf != NULL && icon_info->window != NULL)
6547 gdk_window_show_unraised (icon_info->window);
6557 * Creates a new entry.
6559 * Return value: a new #GtkEntry.
6562 gtk_entry_new (void)
6564 return g_object_new (GTK_TYPE_ENTRY, NULL);
6568 * gtk_entry_new_with_buffer:
6569 * @buffer: The buffer to use for the new #GtkEntry.
6571 * Creates a new entry with the specified text buffer.
6573 * Return value: a new #GtkEntry
6578 gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
6580 g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (buffer), NULL);
6581 return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
6585 * gtk_entry_new_with_max_length:
6586 * @max: the maximum length of the entry, or 0 for no maximum.
6587 * (other than the maximum length of entries.) The value passed in will
6588 * be clamped to the range 0-65536.
6590 * Creates a new #GtkEntry widget with the given maximum length.
6592 * Return value: a new #GtkEntry
6594 * Deprecated: 2.0: Use gtk_entry_set_max_length() instead.
6597 gtk_entry_new_with_max_length (gint max)
6601 max = CLAMP (max, 0, GTK_ENTRY_BUFFER_MAX_SIZE);
6603 entry = g_object_new (GTK_TYPE_ENTRY, NULL);
6604 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
6606 return GTK_WIDGET (entry);
6610 static GtkEntryBuffer*
6611 get_buffer (GtkEntry *entry)
6613 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
6615 if (priv->buffer == NULL)
6617 GtkEntryBuffer *buffer;
6618 buffer = gtk_entry_buffer_new (NULL, 0);
6619 gtk_entry_set_buffer (entry, buffer);
6620 g_object_unref (buffer);
6623 return priv->buffer;
6627 * gtk_entry_get_buffer:
6628 * @entry: a #GtkEntry
6630 * Get the #GtkEntryBuffer object which holds the text for
6635 * Returns: A #GtkEntryBuffer object.
6638 gtk_entry_get_buffer (GtkEntry *entry)
6640 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6642 return get_buffer (entry);
6646 * gtk_entry_set_buffer:
6647 * @entry: a #GtkEntry
6648 * @buffer: a #GtkEntryBuffer
6650 * Set the #GtkEntryBuffer object which holds the text for
6656 gtk_entry_set_buffer (GtkEntry *entry,
6657 GtkEntryBuffer *buffer)
6659 GtkEntryPrivate *priv;
6662 g_return_if_fail (GTK_IS_ENTRY (entry));
6663 priv = GTK_ENTRY_GET_PRIVATE (entry);
6667 g_return_if_fail (GTK_IS_ENTRY_BUFFER (buffer));
6668 g_object_ref (buffer);
6673 buffer_disconnect_signals (entry);
6674 g_object_unref (priv->buffer);
6676 /* COMPAT: Deprecated. Not used. Setting these fields no longer necessary in GTK 3.x */
6678 entry->text_length = 0;
6679 entry->text_max_length = 0;
6682 priv->buffer = buffer;
6686 buffer_connect_signals (entry);
6688 /* COMPAT: Deprecated. Not used. Setting these fields no longer necessary in GTK 3.x */
6689 entry->text = (char*)gtk_entry_buffer_get_text (priv->buffer);
6690 entry->text_length = gtk_entry_buffer_get_length (priv->buffer);
6691 entry->text_max_length = gtk_entry_buffer_get_max_length (priv->buffer);
6694 obj = G_OBJECT (entry);
6695 g_object_freeze_notify (obj);
6696 g_object_notify (obj, "buffer");
6697 g_object_notify (obj, "text");
6698 g_object_notify (obj, "text-length");
6699 g_object_notify (obj, "max-length");
6700 g_object_notify (obj, "visibility");
6701 g_object_notify (obj, "invisible-char");
6702 g_object_notify (obj, "invisible-char-set");
6703 g_object_thaw_notify (obj);
6707 * gtk_entry_get_text_window:
6708 * @entry: a #GtkEntry
6710 * Returns the #GdkWindow which contains the text. This function is
6711 * useful when drawing something to the entry in an expose-event
6712 * callback because it enables the callback to distinguish between
6713 * the text window and entry's icon windows.
6715 * See also gtk_entry_get_icon_window().
6717 * Return value: the entry's text window.
6722 gtk_entry_get_text_window (GtkEntry *entry)
6724 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
6726 return entry->text_area;
6731 * gtk_entry_set_text:
6732 * @entry: a #GtkEntry
6733 * @text: the new text
6735 * Sets the text in the widget to the given
6736 * value, replacing the current contents.
6738 * See gtk_entry_buffer_set_text().
6741 gtk_entry_set_text (GtkEntry *entry,
6745 GtkEntryCompletion *completion;
6746 GtkEntryPrivate *priv;
6748 g_return_if_fail (GTK_IS_ENTRY (entry));
6749 g_return_if_fail (text != NULL);
6750 priv = GTK_ENTRY_GET_PRIVATE (entry);
6752 /* Actually setting the text will affect the cursor and selection;
6753 * if the contents don't actually change, this will look odd to the user.
6755 if (strcmp (gtk_entry_buffer_get_text (get_buffer (entry)), text) == 0)
6758 completion = gtk_entry_get_completion (entry);
6759 if (completion && completion->priv->changed_id > 0)
6760 g_signal_handler_block (entry, completion->priv->changed_id);
6762 begin_change (entry);
6763 g_object_freeze_notify (G_OBJECT (entry));
6764 gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
6766 gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
6767 g_object_thaw_notify (G_OBJECT (entry));
6770 if (completion && completion->priv->changed_id > 0)
6771 g_signal_handler_unblock (entry, completion->priv->changed_id);
6775 * gtk_entry_append_text:
6776 * @entry: a #GtkEntry
6777 * @text: the text to append
6779 * Appends the given text to the contents of the widget.
6781 * Deprecated: 2.0: Use gtk_editable_insert_text() instead.
6784 gtk_entry_append_text (GtkEntry *entry,
6787 GtkEntryPrivate *priv;
6790 g_return_if_fail (GTK_IS_ENTRY (entry));
6791 g_return_if_fail (text != NULL);
6792 priv = GTK_ENTRY_GET_PRIVATE (entry);
6794 tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
6795 gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
6799 * gtk_entry_prepend_text:
6800 * @entry: a #GtkEntry
6801 * @text: the text to prepend
6803 * Prepends the given text to the contents of the widget.
6805 * Deprecated: 2.0: Use gtk_editable_insert_text() instead.
6808 gtk_entry_prepend_text (GtkEntry *entry,
6813 g_return_if_fail (GTK_IS_ENTRY (entry));
6814 g_return_if_fail (text != NULL);
6817 gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
6821 * gtk_entry_set_position:
6822 * @entry: a #GtkEntry
6823 * @position: the position of the cursor. The cursor is displayed
6824 * before the character with the given (base 0) index in the widget.
6825 * The value must be less than or equal to the number of characters
6826 * in the widget. A value of -1 indicates that the position should
6827 * be set after the last character in the entry. Note that this
6828 * position is in characters, not in bytes.
6830 * Sets the cursor position in an entry to the given value.
6832 * Deprecated: 2.0: Use gtk_editable_set_position() instead.
6835 gtk_entry_set_position (GtkEntry *entry,
6838 g_return_if_fail (GTK_IS_ENTRY (entry));
6840 gtk_editable_set_position (GTK_EDITABLE (entry), position);
6844 * gtk_entry_set_visibility:
6845 * @entry: a #GtkEntry
6846 * @visible: %TRUE if the contents of the entry are displayed
6849 * Sets whether the contents of the entry are visible or not.
6850 * When visibility is set to %FALSE, characters are displayed
6851 * as the invisible char, and will also appear that way when
6852 * the text in the entry widget is copied elsewhere.
6854 * By default, GTK+ picks the best invisible character available
6855 * in the current font, but it can be changed with
6856 * gtk_entry_set_invisible_char().
6859 gtk_entry_set_visibility (GtkEntry *entry,
6862 g_return_if_fail (GTK_IS_ENTRY (entry));
6864 visible = visible != FALSE;
6866 if (entry->visible != visible)
6868 entry->visible = visible;
6870 g_object_notify (G_OBJECT (entry), "visibility");
6871 gtk_entry_recompute (entry);
6876 * gtk_entry_get_visibility:
6877 * @entry: a #GtkEntry
6879 * Retrieves whether the text in @entry is visible. See
6880 * gtk_entry_set_visibility().
6882 * Return value: %TRUE if the text is currently visible
6885 gtk_entry_get_visibility (GtkEntry *entry)
6887 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
6889 return entry->visible;
6893 * gtk_entry_set_invisible_char:
6894 * @entry: a #GtkEntry
6895 * @ch: a Unicode character
6897 * Sets the character to use in place of the actual text when
6898 * gtk_entry_set_visibility() has been called to set text visibility
6899 * to %FALSE. i.e. this is the character used in "password mode" to
6900 * show the user how many characters have been typed. By default, GTK+
6901 * picks the best invisible char available in the current font. If you
6902 * set the invisible char to 0, then the user will get no feedback
6903 * at all; there will be no text on the screen as they type.
6906 gtk_entry_set_invisible_char (GtkEntry *entry,
6909 GtkEntryPrivate *priv;
6911 g_return_if_fail (GTK_IS_ENTRY (entry));
6913 priv = GTK_ENTRY_GET_PRIVATE (entry);
6915 if (!priv->invisible_char_set)
6917 priv->invisible_char_set = TRUE;
6918 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6921 if (ch == entry->invisible_char)
6924 entry->invisible_char = ch;
6925 g_object_notify (G_OBJECT (entry), "invisible-char");
6926 gtk_entry_recompute (entry);
6930 * gtk_entry_get_invisible_char:
6931 * @entry: a #GtkEntry
6933 * Retrieves the character displayed in place of the real characters
6934 * for entries with visibility set to false. See gtk_entry_set_invisible_char().
6936 * Return value: the current invisible char, or 0, if the entry does not
6937 * show invisible text at all.
6940 gtk_entry_get_invisible_char (GtkEntry *entry)
6942 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
6944 return entry->invisible_char;
6948 * gtk_entry_unset_invisible_char:
6949 * @entry: a #GtkEntry
6951 * Unsets the invisible char previously set with
6952 * gtk_entry_set_invisible_char(). So that the
6953 * default invisible char is used again.
6958 gtk_entry_unset_invisible_char (GtkEntry *entry)
6960 GtkEntryPrivate *priv;
6963 g_return_if_fail (GTK_IS_ENTRY (entry));
6965 priv = GTK_ENTRY_GET_PRIVATE (entry);
6967 if (!priv->invisible_char_set)
6970 priv->invisible_char_set = FALSE;
6971 ch = find_invisible_char (GTK_WIDGET (entry));
6973 if (entry->invisible_char != ch)
6975 entry->invisible_char = ch;
6976 g_object_notify (G_OBJECT (entry), "invisible-char");
6979 g_object_notify (G_OBJECT (entry), "invisible-char-set");
6980 gtk_entry_recompute (entry);
6984 * gtk_entry_set_editable:
6985 * @entry: a #GtkEntry
6986 * @editable: %TRUE if the user is allowed to edit the text
6989 * Determines if the user can edit the text in the editable
6992 * Deprecated: 2.0: Use gtk_editable_set_editable() instead.
6995 gtk_entry_set_editable (GtkEntry *entry,
6998 g_return_if_fail (GTK_IS_ENTRY (entry));
7000 gtk_editable_set_editable (GTK_EDITABLE (entry), editable);
7004 * gtk_entry_set_overwrite_mode:
7005 * @entry: a #GtkEntry
7006 * @overwrite: new value
7008 * Sets whether the text is overwritten when typing in the #GtkEntry.
7013 gtk_entry_set_overwrite_mode (GtkEntry *entry,
7016 g_return_if_fail (GTK_IS_ENTRY (entry));
7018 if (entry->overwrite_mode == overwrite)
7021 gtk_entry_toggle_overwrite (entry);
7023 g_object_notify (G_OBJECT (entry), "overwrite-mode");
7027 * gtk_entry_get_overwrite_mode:
7028 * @entry: a #GtkEntry
7030 * Gets the value set by gtk_entry_set_overwrite_mode().
7032 * Return value: whether the text is overwritten when typing.
7037 gtk_entry_get_overwrite_mode (GtkEntry *entry)
7039 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7041 return entry->overwrite_mode;
7045 * gtk_entry_get_text:
7046 * @entry: a #GtkEntry
7048 * Retrieves the contents of the entry widget.
7049 * See also gtk_editable_get_chars().
7051 * This is equivalent to:
7053 * <informalexample><programlisting>
7054 * gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
7055 * </programlisting></informalexample>
7057 * Return value: a pointer to the contents of the widget as a
7058 * string. This string points to internally allocated
7059 * storage in the widget and must not be freed, modified or
7062 G_CONST_RETURN gchar*
7063 gtk_entry_get_text (GtkEntry *entry)
7065 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7066 return gtk_entry_buffer_get_text (get_buffer (entry));
7070 * gtk_entry_select_region:
7071 * @entry: a #GtkEntry
7072 * @start: the starting position
7073 * @end: the end position
7075 * Selects a region of text. The characters that are selected are
7076 * those characters at positions from @start_pos up to, but not
7077 * including @end_pos. If @end_pos is negative, then the the characters
7078 * selected will be those characters from @start_pos to the end of
7081 * Deprecated: 2.0: Use gtk_editable_select_region() instead.
7084 gtk_entry_select_region (GtkEntry *entry,
7088 gtk_editable_select_region (GTK_EDITABLE (entry), start, end);
7092 * gtk_entry_set_max_length:
7093 * @entry: a #GtkEntry
7094 * @max: the maximum length of the entry, or 0 for no maximum.
7095 * (other than the maximum length of entries.) The value passed in will
7096 * be clamped to the range 0-65536.
7098 * Sets the maximum allowed length of the contents of the widget. If
7099 * the current contents are longer than the given length, then they
7100 * will be truncated to fit.
7102 * This is equivalent to:
7104 * <informalexample><programlisting>
7105 * gtk_entry_buffer_set_max_length (gtk_entry_get_buffer (entry), max);
7106 * </programlisting></informalexample>
7109 gtk_entry_set_max_length (GtkEntry *entry,
7112 g_return_if_fail (GTK_IS_ENTRY (entry));
7113 gtk_entry_buffer_set_max_length (get_buffer (entry), max);
7117 * gtk_entry_get_max_length:
7118 * @entry: a #GtkEntry
7120 * Retrieves the maximum allowed length of the text in
7121 * @entry. See gtk_entry_set_max_length().
7123 * This is equivalent to:
7125 * <informalexample><programlisting>
7126 * gtk_entry_buffer_get_max_length (gtk_entry_get_buffer (entry));
7127 * </programlisting></informalexample>
7129 * Return value: the maximum allowed number of characters
7130 * in #GtkEntry, or 0 if there is no maximum.
7133 gtk_entry_get_max_length (GtkEntry *entry)
7135 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7136 return gtk_entry_buffer_get_max_length (get_buffer (entry));
7140 * gtk_entry_get_text_length:
7141 * @entry: a #GtkEntry
7143 * Retrieves the current length of the text in
7146 * This is equivalent to:
7148 * <informalexample><programlisting>
7149 * gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry));
7150 * </programlisting></informalexample>
7152 * Return value: the current number of characters
7153 * in #GtkEntry, or 0 if there are none.
7158 gtk_entry_get_text_length (GtkEntry *entry)
7160 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7161 return gtk_entry_buffer_get_length (get_buffer (entry));
7165 * gtk_entry_set_activates_default:
7166 * @entry: a #GtkEntry
7167 * @setting: %TRUE to activate window's default widget on Enter keypress
7169 * If @setting is %TRUE, pressing Enter in the @entry will activate the default
7170 * widget for the window containing the entry. This usually means that
7171 * the dialog box containing the entry will be closed, since the default
7172 * widget is usually one of the dialog buttons.
7174 * (For experts: if @setting is %TRUE, the entry calls
7175 * gtk_window_activate_default() on the window containing the entry, in
7176 * the default handler for the #GtkWidget::activate signal.)
7179 gtk_entry_set_activates_default (GtkEntry *entry,
7182 g_return_if_fail (GTK_IS_ENTRY (entry));
7183 setting = setting != FALSE;
7185 if (setting != entry->activates_default)
7187 entry->activates_default = setting;
7188 g_object_notify (G_OBJECT (entry), "activates-default");
7193 * gtk_entry_get_activates_default:
7194 * @entry: a #GtkEntry
7196 * Retrieves the value set by gtk_entry_set_activates_default().
7198 * Return value: %TRUE if the entry will activate the default widget
7201 gtk_entry_get_activates_default (GtkEntry *entry)
7203 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7205 return entry->activates_default;
7209 * gtk_entry_set_width_chars:
7210 * @entry: a #GtkEntry
7211 * @n_chars: width in chars
7213 * Changes the size request of the entry to be about the right size
7214 * for @n_chars characters. Note that it changes the size
7215 * <emphasis>request</emphasis>, the size can still be affected by
7216 * how you pack the widget into containers. If @n_chars is -1, the
7217 * size reverts to the default entry size.
7220 gtk_entry_set_width_chars (GtkEntry *entry,
7223 g_return_if_fail (GTK_IS_ENTRY (entry));
7225 if (entry->width_chars != n_chars)
7227 entry->width_chars = n_chars;
7228 g_object_notify (G_OBJECT (entry), "width-chars");
7229 gtk_widget_queue_resize (GTK_WIDGET (entry));
7234 * gtk_entry_get_width_chars:
7235 * @entry: a #GtkEntry
7237 * Gets the value set by gtk_entry_set_width_chars().
7239 * Return value: number of chars to request space for, or negative if unset
7242 gtk_entry_get_width_chars (GtkEntry *entry)
7244 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7246 return entry->width_chars;
7250 * gtk_entry_set_has_frame:
7251 * @entry: a #GtkEntry
7252 * @setting: new value
7254 * Sets whether the entry has a beveled frame around it.
7257 gtk_entry_set_has_frame (GtkEntry *entry,
7260 g_return_if_fail (GTK_IS_ENTRY (entry));
7262 setting = (setting != FALSE);
7264 if (entry->has_frame == setting)
7267 gtk_widget_queue_resize (GTK_WIDGET (entry));
7268 entry->has_frame = setting;
7269 g_object_notify (G_OBJECT (entry), "has-frame");
7273 * gtk_entry_get_has_frame:
7274 * @entry: a #GtkEntry
7276 * Gets the value set by gtk_entry_set_has_frame().
7278 * Return value: whether the entry has a beveled frame
7281 gtk_entry_get_has_frame (GtkEntry *entry)
7283 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7285 return entry->has_frame;
7289 * gtk_entry_set_inner_border:
7290 * @entry: a #GtkEntry
7291 * @border: (allow-none): a #GtkBorder, or %NULL
7293 * Sets %entry's inner-border property to %border, or clears it if %NULL
7294 * is passed. The inner-border is the area around the entry's text, but
7297 * If set, this property overrides the inner-border style property.
7298 * Overriding the style-provided border is useful when you want to do
7299 * in-place editing of some text in a canvas or list widget, where
7300 * pixel-exact positioning of the entry is important.
7305 gtk_entry_set_inner_border (GtkEntry *entry,
7306 const GtkBorder *border)
7308 g_return_if_fail (GTK_IS_ENTRY (entry));
7310 gtk_widget_queue_resize (GTK_WIDGET (entry));
7313 g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
7314 gtk_border_copy (border),
7315 (GDestroyNotify) gtk_border_free);
7317 g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
7319 g_object_notify (G_OBJECT (entry), "inner-border");
7323 * gtk_entry_get_inner_border:
7324 * @entry: a #GtkEntry
7326 * This function returns the entry's #GtkEntry:inner-border property. See
7327 * gtk_entry_set_inner_border() for more information.
7329 * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
7333 G_CONST_RETURN GtkBorder *
7334 gtk_entry_get_inner_border (GtkEntry *entry)
7336 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7338 return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
7342 * gtk_entry_get_layout:
7343 * @entry: a #GtkEntry
7345 * Gets the #PangoLayout used to display the entry.
7346 * The layout is useful to e.g. convert text positions to
7347 * pixel positions, in combination with gtk_entry_get_layout_offsets().
7348 * The returned layout is owned by the entry and must not be
7349 * modified or freed by the caller.
7351 * Keep in mind that the layout text may contain a preedit string, so
7352 * gtk_entry_layout_index_to_text_index() and
7353 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7354 * indices in the layout to byte indices in the entry contents.
7356 * Return value: (transfer none): the #PangoLayout for this entry
7359 gtk_entry_get_layout (GtkEntry *entry)
7361 PangoLayout *layout;
7363 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7365 layout = gtk_entry_ensure_layout (entry, TRUE);
7372 * gtk_entry_layout_index_to_text_index:
7373 * @entry: a #GtkEntry
7374 * @layout_index: byte index into the entry layout text
7376 * Converts from a position in the entry contents (returned
7377 * by gtk_entry_get_text()) to a position in the
7378 * entry's #PangoLayout (returned by gtk_entry_get_layout(),
7379 * with text retrieved via pango_layout_get_text()).
7381 * Return value: byte index into the entry contents
7384 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
7387 PangoLayout *layout;
7391 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7393 layout = gtk_entry_ensure_layout (entry, TRUE);
7394 text = pango_layout_get_text (layout);
7395 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7397 if (layout_index >= cursor_index && entry->preedit_length)
7399 if (layout_index >= cursor_index + entry->preedit_length)
7400 layout_index -= entry->preedit_length;
7402 layout_index = cursor_index;
7405 return layout_index;
7409 * gtk_entry_text_index_to_layout_index:
7410 * @entry: a #GtkEntry
7411 * @text_index: byte index into the entry contents
7413 * Converts from a position in the entry's #PangoLayout (returned by
7414 * gtk_entry_get_layout()) to a position in the entry contents
7415 * (returned by gtk_entry_get_text()).
7417 * Return value: byte index into the entry layout text
7420 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
7423 PangoLayout *layout;
7426 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
7428 layout = gtk_entry_ensure_layout (entry, TRUE);
7429 text = pango_layout_get_text (layout);
7430 cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
7432 if (text_index > cursor_index)
7433 text_index += entry->preedit_length;
7439 * gtk_entry_get_layout_offsets:
7440 * @entry: a #GtkEntry
7441 * @x: location to store X offset of layout, or %NULL
7442 * @y: location to store Y offset of layout, or %NULL
7445 * Obtains the position of the #PangoLayout used to render text
7446 * in the entry, in widget coordinates. Useful if you want to line
7447 * up the text in an entry with some other text, e.g. when using the
7448 * entry to implement editable cells in a sheet widget.
7450 * Also useful to convert mouse events into coordinates inside the
7451 * #PangoLayout, e.g. to take some action if some part of the entry text
7454 * Note that as the user scrolls around in the entry the offsets will
7455 * change; you'll need to connect to the "notify::scroll-offset"
7456 * signal to track this. Remember when using the #PangoLayout
7457 * functions you need to convert to and from pixels using
7458 * PANGO_PIXELS() or #PANGO_SCALE.
7460 * Keep in mind that the layout text may contain a preedit string, so
7461 * gtk_entry_layout_index_to_text_index() and
7462 * gtk_entry_text_index_to_layout_index() are needed to convert byte
7463 * indices in the layout to byte indices in the entry contents.
7466 gtk_entry_get_layout_offsets (GtkEntry *entry,
7470 gint text_area_x, text_area_y;
7472 g_return_if_fail (GTK_IS_ENTRY (entry));
7474 /* this gets coords relative to text area */
7475 get_layout_position (entry, x, y);
7477 /* convert to widget coords */
7478 gtk_entry_get_text_area_size (entry, &text_area_x, &text_area_y, NULL, NULL);
7489 * gtk_entry_set_alignment:
7490 * @entry: a #GtkEntry
7491 * @xalign: The horizontal alignment, from 0 (left) to 1 (right).
7492 * Reversed for RTL layouts
7494 * Sets the alignment for the contents of the entry. This controls
7495 * the horizontal positioning of the contents when the displayed
7496 * text is shorter than the width of the entry.
7501 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
7503 GtkEntryPrivate *priv;
7505 g_return_if_fail (GTK_IS_ENTRY (entry));
7507 priv = GTK_ENTRY_GET_PRIVATE (entry);
7511 else if (xalign > 1.0)
7514 if (xalign != priv->xalign)
7516 priv->xalign = xalign;
7518 gtk_entry_recompute (entry);
7520 g_object_notify (G_OBJECT (entry), "xalign");
7525 * gtk_entry_get_alignment:
7526 * @entry: a #GtkEntry
7528 * Gets the value set by gtk_entry_set_alignment().
7530 * Return value: the alignment
7535 gtk_entry_get_alignment (GtkEntry *entry)
7537 GtkEntryPrivate *priv;
7539 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
7541 priv = GTK_ENTRY_GET_PRIVATE (entry);
7543 return priv->xalign;
7547 * gtk_entry_set_icon_from_pixbuf:
7548 * @entry: a #GtkEntry
7549 * @icon_pos: Icon position
7550 * @pixbuf: A #GdkPixbuf, or %NULL
7552 * Sets the icon shown in the specified position using a pixbuf.
7554 * If @pixbuf is %NULL, no icon will be shown in the specified position.
7559 gtk_entry_set_icon_from_pixbuf (GtkEntry *entry,
7560 GtkEntryIconPosition icon_pos,
7563 GtkEntryPrivate *priv;
7564 EntryIconInfo *icon_info;
7566 g_return_if_fail (GTK_IS_ENTRY (entry));
7567 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7569 priv = GTK_ENTRY_GET_PRIVATE (entry);
7571 if ((icon_info = priv->icons[icon_pos]) == NULL)
7572 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7574 g_object_freeze_notify (G_OBJECT (entry));
7577 g_object_ref (pixbuf);
7579 gtk_entry_clear (entry, icon_pos);
7583 icon_info->storage_type = GTK_IMAGE_PIXBUF;
7584 icon_info->pixbuf = pixbuf;
7586 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7588 g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
7589 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7593 g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
7594 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7597 if (GTK_WIDGET_MAPPED (entry))
7598 gdk_window_show_unraised (icon_info->window);
7601 gtk_entry_ensure_pixbuf (entry, icon_pos);
7603 if (GTK_WIDGET_VISIBLE (entry))
7604 gtk_widget_queue_resize (GTK_WIDGET (entry));
7606 g_object_thaw_notify (G_OBJECT (entry));
7610 * gtk_entry_set_icon_from_stock:
7611 * @entry: A #GtkEntry
7612 * @icon_pos: Icon position
7613 * @stock_id: The name of the stock item, or %NULL
7615 * Sets the icon shown in the entry at the specified position from
7618 * If @stock_id is %NULL, no icon will be shown in the specified position.
7623 gtk_entry_set_icon_from_stock (GtkEntry *entry,
7624 GtkEntryIconPosition icon_pos,
7625 const gchar *stock_id)
7627 GtkEntryPrivate *priv;
7628 EntryIconInfo *icon_info;
7631 g_return_if_fail (GTK_IS_ENTRY (entry));
7632 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7634 priv = GTK_ENTRY_GET_PRIVATE (entry);
7636 if ((icon_info = priv->icons[icon_pos]) == NULL)
7637 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7639 g_object_freeze_notify (G_OBJECT (entry));
7641 gtk_widget_ensure_style (GTK_WIDGET (entry));
7643 /* need to dup before clearing */
7644 new_id = g_strdup (stock_id);
7646 gtk_entry_clear (entry, icon_pos);
7650 icon_info->storage_type = GTK_IMAGE_STOCK;
7651 icon_info->stock_id = new_id;
7653 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7655 g_object_notify (G_OBJECT (entry), "primary-icon-stock");
7656 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7660 g_object_notify (G_OBJECT (entry), "secondary-icon-stock");
7661 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7664 if (GTK_WIDGET_MAPPED (entry))
7665 gdk_window_show_unraised (icon_info->window);
7668 gtk_entry_ensure_pixbuf (entry, icon_pos);
7670 if (GTK_WIDGET_VISIBLE (entry))
7671 gtk_widget_queue_resize (GTK_WIDGET (entry));
7673 g_object_thaw_notify (G_OBJECT (entry));
7677 * gtk_entry_set_icon_from_icon_name:
7678 * @entry: A #GtkEntry
7679 * @icon_pos: The position at which to set the icon
7680 * @icon_name: An icon name, or %NULL
7682 * Sets the icon shown in the entry at the specified position
7683 * from the current icon theme.
7685 * If the icon name isn't known, a "broken image" icon will be displayed
7688 * If @icon_name is %NULL, no icon will be shown in the specified position.
7693 gtk_entry_set_icon_from_icon_name (GtkEntry *entry,
7694 GtkEntryIconPosition icon_pos,
7695 const gchar *icon_name)
7697 GtkEntryPrivate *priv;
7698 EntryIconInfo *icon_info;
7701 g_return_if_fail (GTK_IS_ENTRY (entry));
7702 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7704 priv = GTK_ENTRY_GET_PRIVATE (entry);
7706 if ((icon_info = priv->icons[icon_pos]) == NULL)
7707 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7709 g_object_freeze_notify (G_OBJECT (entry));
7711 gtk_widget_ensure_style (GTK_WIDGET (entry));
7713 /* need to dup before clearing */
7714 new_name = g_strdup (icon_name);
7716 gtk_entry_clear (entry, icon_pos);
7718 if (new_name != NULL)
7720 icon_info->storage_type = GTK_IMAGE_ICON_NAME;
7721 icon_info->icon_name = new_name;
7723 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7725 g_object_notify (G_OBJECT (entry), "primary-icon-name");
7726 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7730 g_object_notify (G_OBJECT (entry), "secondary-icon-name");
7731 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7734 if (GTK_WIDGET_MAPPED (entry))
7735 gdk_window_show_unraised (icon_info->window);
7738 gtk_entry_ensure_pixbuf (entry, icon_pos);
7740 if (GTK_WIDGET_VISIBLE (entry))
7741 gtk_widget_queue_resize (GTK_WIDGET (entry));
7743 g_object_thaw_notify (G_OBJECT (entry));
7747 * gtk_entry_set_icon_from_gicon:
7748 * @entry: A #GtkEntry
7749 * @icon_pos: The position at which to set the icon
7750 * @icon: The icon to set, or %NULL
7752 * Sets the icon shown in the entry at the specified position
7753 * from the current icon theme.
7754 * If the icon isn't known, a "broken image" icon will be displayed
7757 * If @icon is %NULL, no icon will be shown in the specified position.
7762 gtk_entry_set_icon_from_gicon (GtkEntry *entry,
7763 GtkEntryIconPosition icon_pos,
7766 GtkEntryPrivate *priv;
7767 EntryIconInfo *icon_info;
7769 g_return_if_fail (GTK_IS_ENTRY (entry));
7770 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7772 priv = GTK_ENTRY_GET_PRIVATE (entry);
7774 if ((icon_info = priv->icons[icon_pos]) == NULL)
7775 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7777 g_object_freeze_notify (G_OBJECT (entry));
7779 /* need to ref before clearing */
7781 g_object_ref (icon);
7783 gtk_entry_clear (entry, icon_pos);
7787 icon_info->storage_type = GTK_IMAGE_GICON;
7788 icon_info->gicon = icon;
7790 if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
7792 g_object_notify (G_OBJECT (entry), "primary-icon-gicon");
7793 g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
7797 g_object_notify (G_OBJECT (entry), "secondary-icon-gicon");
7798 g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
7801 if (GTK_WIDGET_MAPPED (entry))
7802 gdk_window_show_unraised (icon_info->window);
7805 gtk_entry_ensure_pixbuf (entry, icon_pos);
7807 if (GTK_WIDGET_VISIBLE (entry))
7808 gtk_widget_queue_resize (GTK_WIDGET (entry));
7810 g_object_thaw_notify (G_OBJECT (entry));
7814 * gtk_entry_set_icon_activatable:
7815 * @entry: A #GtkEntry
7816 * @icon_pos: Icon position
7817 * @activatable: %TRUE if the icon should be activatable
7819 * Sets whether the icon is activatable.
7824 gtk_entry_set_icon_activatable (GtkEntry *entry,
7825 GtkEntryIconPosition icon_pos,
7826 gboolean activatable)
7828 GtkEntryPrivate *priv;
7829 EntryIconInfo *icon_info;
7831 g_return_if_fail (GTK_IS_ENTRY (entry));
7832 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
7834 priv = GTK_ENTRY_GET_PRIVATE (entry);
7836 if ((icon_info = priv->icons[icon_pos]) == NULL)
7837 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
7839 activatable = activatable != FALSE;
7841 if (icon_info->nonactivatable != !activatable)
7843 icon_info->nonactivatable = !activatable;
7845 if (GTK_WIDGET_REALIZED (GTK_WIDGET (entry)))
7846 update_cursors (GTK_WIDGET (entry));
7848 g_object_notify (G_OBJECT (entry),
7849 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-activatable" : "secondary-icon-activatable");
7854 * gtk_entry_get_icon_activatable:
7855 * @entry: a #GtkEntry
7856 * @icon_pos: Icon position
7858 * Returns whether the icon is activatable.
7860 * Returns: %TRUE if the icon is activatable.
7865 gtk_entry_get_icon_activatable (GtkEntry *entry,
7866 GtkEntryIconPosition icon_pos)
7868 GtkEntryPrivate *priv;
7869 EntryIconInfo *icon_info;
7871 g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
7872 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
7874 priv = GTK_ENTRY_GET_PRIVATE (entry);
7875 icon_info = priv->icons[icon_pos];
7877 return (icon_info != NULL && !icon_info->nonactivatable);
7881 * gtk_entry_get_icon_pixbuf:
7882 * @entry: A #GtkEntry
7883 * @icon_pos: Icon position
7885 * Retrieves the image used for the icon.
7887 * Unlike the other methods of setting and getting icon data, this
7888 * method will work regardless of whether the icon was set using a
7889 * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
7891 * Returns: A #GdkPixbuf, or %NULL if no icon is set for this position.
7896 gtk_entry_get_icon_pixbuf (GtkEntry *entry,
7897 GtkEntryIconPosition icon_pos)
7899 GtkEntryPrivate *priv;
7900 EntryIconInfo *icon_info;
7902 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7903 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7905 priv = GTK_ENTRY_GET_PRIVATE (entry);
7906 icon_info = priv->icons[icon_pos];
7911 gtk_entry_ensure_pixbuf (entry, icon_pos);
7913 return icon_info->pixbuf;
7917 * gtk_entry_get_icon_gicon:
7918 * @entry: A #GtkEntry
7919 * @icon_pos: Icon position
7921 * Retrieves the #GIcon used for the icon, or %NULL if there is
7922 * no icon or if the icon was set by some other method (e.g., by
7923 * stock, pixbuf, or icon name).
7925 * Returns: A #GIcon, or %NULL if no icon is set or if the icon
7931 gtk_entry_get_icon_gicon (GtkEntry *entry,
7932 GtkEntryIconPosition icon_pos)
7934 GtkEntryPrivate *priv;
7935 EntryIconInfo *icon_info;
7937 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7938 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7940 priv = GTK_ENTRY_GET_PRIVATE (entry);
7941 icon_info = priv->icons[icon_pos];
7946 return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
7950 * gtk_entry_get_icon_stock:
7951 * @entry: A #GtkEntry
7952 * @icon_pos: Icon position
7954 * Retrieves the stock id used for the icon, or %NULL if there is
7955 * no icon or if the icon was set by some other method (e.g., by
7956 * pixbuf, icon name or gicon).
7958 * Returns: A stock id, or %NULL if no icon is set or if the icon
7959 * wasn't set from a stock id
7964 gtk_entry_get_icon_stock (GtkEntry *entry,
7965 GtkEntryIconPosition icon_pos)
7967 GtkEntryPrivate *priv;
7968 EntryIconInfo *icon_info;
7970 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
7971 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
7973 priv = GTK_ENTRY_GET_PRIVATE (entry);
7974 icon_info = priv->icons[icon_pos];
7979 return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
7983 * gtk_entry_get_icon_name:
7984 * @entry: A #GtkEntry
7985 * @icon_pos: Icon position
7987 * Retrieves the icon name used for the icon, or %NULL if there is
7988 * no icon or if the icon was set by some other method (e.g., by
7989 * pixbuf, stock or gicon).
7991 * Returns: An icon name, or %NULL if no icon is set or if the icon
7992 * wasn't set from an icon name
7997 gtk_entry_get_icon_name (GtkEntry *entry,
7998 GtkEntryIconPosition icon_pos)
8000 GtkEntryPrivate *priv;
8001 EntryIconInfo *icon_info;
8003 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8004 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8006 priv = GTK_ENTRY_GET_PRIVATE (entry);
8007 icon_info = priv->icons[icon_pos];
8012 return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
8016 * gtk_entry_set_icon_sensitive:
8017 * @entry: A #GtkEntry
8018 * @icon_pos: Icon position
8019 * @sensitive: Specifies whether the icon should appear
8020 * sensitive or insensitive
8022 * Sets the sensitivity for the specified icon.
8027 gtk_entry_set_icon_sensitive (GtkEntry *entry,
8028 GtkEntryIconPosition icon_pos,
8031 GtkEntryPrivate *priv;
8032 EntryIconInfo *icon_info;
8034 g_return_if_fail (GTK_IS_ENTRY (entry));
8035 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8037 priv = GTK_ENTRY_GET_PRIVATE (entry);
8039 if ((icon_info = priv->icons[icon_pos]) == NULL)
8040 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8042 if (icon_info->insensitive != !sensitive)
8044 icon_info->insensitive = !sensitive;
8046 icon_info->pressed = FALSE;
8047 icon_info->prelight = FALSE;
8049 if (GTK_WIDGET_REALIZED (GTK_WIDGET (entry)))
8050 update_cursors (GTK_WIDGET (entry));
8052 gtk_widget_queue_draw (GTK_WIDGET (entry));
8054 g_object_notify (G_OBJECT (entry),
8055 icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-sensitive" : "secondary-icon-sensitive");
8060 * gtk_entry_get_icon_sensitive:
8061 * @entry: a #GtkEntry
8062 * @icon_pos: Icon position
8064 * Returns whether the icon appears sensitive or insensitive.
8066 * Returns: %TRUE if the icon is sensitive.
8071 gtk_entry_get_icon_sensitive (GtkEntry *entry,
8072 GtkEntryIconPosition icon_pos)
8074 GtkEntryPrivate *priv;
8075 EntryIconInfo *icon_info;
8077 g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
8078 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
8080 priv = GTK_ENTRY_GET_PRIVATE (entry);
8081 icon_info = priv->icons[icon_pos];
8083 return (!icon_info || !icon_info->insensitive);
8088 * gtk_entry_get_icon_storage_type:
8089 * @entry: a #GtkEntry
8090 * @icon_pos: Icon position
8092 * Gets the type of representation being used by the icon
8093 * to store image data. If the icon has no image data,
8094 * the return value will be %GTK_IMAGE_EMPTY.
8096 * Return value: image representation being used
8101 gtk_entry_get_icon_storage_type (GtkEntry *entry,
8102 GtkEntryIconPosition icon_pos)
8104 GtkEntryPrivate *priv;
8105 EntryIconInfo *icon_info;
8107 g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
8108 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
8110 priv = GTK_ENTRY_GET_PRIVATE (entry);
8111 icon_info = priv->icons[icon_pos];
8114 return GTK_IMAGE_EMPTY;
8116 return icon_info->storage_type;
8120 * gtk_entry_get_icon_at_pos:
8121 * @entry: a #GtkEntry
8122 * @x: the x coordinate of the position to find
8123 * @y: the y coordinate of the position to find
8125 * Finds the icon at the given position and return its index.
8126 * If @x, @y doesn't lie inside an icon, -1 is returned.
8127 * This function is intended for use in a #GtkWidget::query-tooltip
8130 * Returns: the index of the icon at the given position, or -1
8135 gtk_entry_get_icon_at_pos (GtkEntry *entry,
8139 GtkAllocation primary;
8140 GtkAllocation secondary;
8142 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8144 get_icon_allocations (entry, &primary, &secondary);
8146 if (primary.x <= x && x < primary.x + primary.width &&
8147 primary.y <= y && y < primary.y + primary.height)
8148 return GTK_ENTRY_ICON_PRIMARY;
8150 if (secondary.x <= x && x < secondary.x + secondary.width &&
8151 secondary.y <= y && y < secondary.y + secondary.height)
8152 return GTK_ENTRY_ICON_SECONDARY;
8158 * gtk_entry_set_icon_drag_source:
8159 * @entry: a #GtkIconEntry
8160 * @icon_pos: icon position
8161 * @target_list: the targets (data formats) in which the data can be provided
8162 * @actions: a bitmask of the allowed drag actions
8164 * Sets up the icon at the given position so that GTK+ will start a drag
8165 * operation when the user clicks and drags the icon.
8167 * To handle the drag operation, you need to connect to the usual
8168 * #GtkWidget::drag-data-get (or possibly #GtkWidget::drag-data-delete)
8169 * signal, and use gtk_entry_get_current_icon_drag_source() in
8170 * your signal handler to find out if the drag was started from
8173 * By default, GTK+ uses the icon as the drag icon. You can use the
8174 * #GtkWidget::drag-begin signal to set a different icon. Note that you
8175 * have to use g_signal_connect_after() to ensure that your signal handler
8176 * gets executed after the default handler.
8181 gtk_entry_set_icon_drag_source (GtkEntry *entry,
8182 GtkEntryIconPosition icon_pos,
8183 GtkTargetList *target_list,
8184 GdkDragAction actions)
8186 GtkEntryPrivate *priv;
8187 EntryIconInfo *icon_info;
8189 g_return_if_fail (GTK_IS_ENTRY (entry));
8190 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8192 priv = GTK_ENTRY_GET_PRIVATE (entry);
8194 if ((icon_info = priv->icons[icon_pos]) == NULL)
8195 icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
8197 if (icon_info->target_list)
8198 gtk_target_list_unref (icon_info->target_list);
8199 icon_info->target_list = target_list;
8200 if (icon_info->target_list)
8201 gtk_target_list_ref (icon_info->target_list);
8203 icon_info->actions = actions;
8207 * gtk_entry_get_current_icon_drag_source:
8208 * @entry: a #GtkIconEntry
8210 * Returns the index of the icon which is the source of the current
8211 * DND operation, or -1.
8213 * This function is meant to be used in a #GtkWidget::drag-data-get
8216 * Returns: index of the icon which is the source of the current
8217 * DND operation, or -1.
8222 gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
8224 GtkEntryPrivate *priv;
8225 EntryIconInfo *icon_info = NULL;
8228 g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
8230 priv = GTK_ENTRY_GET_PRIVATE (entry);
8232 for (i = 0; i < MAX_ICONS; i++)
8234 if ((icon_info = priv->icons[i]))
8236 if (icon_info->in_drag)
8245 * gtk_entry_get_icon_window:
8246 * @entry: A #GtkEntry
8247 * @icon_pos: Icon position
8249 * Returns the #GdkWindow which contains the entry's icon at
8250 * @icon_pos. This function is useful when drawing something to the
8251 * entry in an expose-event callback because it enables the callback
8252 * to distinguish between the text window and entry's icon windows.
8254 * See also gtk_entry_get_text_window().
8256 * Return value: the entry's icon window at @icon_pos.
8261 gtk_entry_get_icon_window (GtkEntry *entry,
8262 GtkEntryIconPosition icon_pos)
8264 GtkEntryPrivate *priv;
8265 EntryIconInfo *icon_info;
8267 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8269 priv = GTK_ENTRY_GET_PRIVATE (entry);
8271 icon_info = priv->icons[icon_pos];
8274 return icon_info->window;
8280 ensure_has_tooltip (GtkEntry *entry)
8282 GtkEntryPrivate *priv;
8283 EntryIconInfo *icon_info;
8285 gboolean has_tooltip = FALSE;
8287 priv = GTK_ENTRY_GET_PRIVATE (entry);
8289 for (i = 0; i < MAX_ICONS; i++)
8291 if ((icon_info = priv->icons[i]) != NULL)
8293 if (icon_info->tooltip != NULL)
8301 gtk_widget_set_has_tooltip (GTK_WIDGET (entry), has_tooltip);
8305 * gtk_entry_get_icon_tooltip_text:
8306 * @entry: a #GtkEntry
8307 * @icon_pos: the icon position
8309 * Gets the contents of the tooltip on the icon at the specified
8310 * position in @entry.
8312 * Returns: the tooltip text, or %NULL. Free the returned string
8313 * with g_free() when done.
8318 gtk_entry_get_icon_tooltip_text (GtkEntry *entry,
8319 GtkEntryIconPosition icon_pos)
8321 GtkEntryPrivate *priv;
8322 EntryIconInfo *icon_info;
8325 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8326 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8328 priv = GTK_ENTRY_GET_PRIVATE (entry);
8329 icon_info = priv->icons[icon_pos];
8334 if (icon_info->tooltip &&
8335 !pango_parse_markup (icon_info->tooltip, -1, 0, NULL, &text, NULL, NULL))
8336 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
8342 * gtk_entry_set_icon_tooltip_text:
8343 * @entry: a #GtkEntry
8344 * @icon_pos: the icon position
8345 * @tooltip: the contents of the tooltip for the icon, or %NULL
8347 * Sets @tooltip as the contents of the tooltip for the icon
8348 * at the specified position.
8350 * Use %NULL for @tooltip to remove an existing tooltip.
8352 * See also gtk_widget_set_tooltip_text() and
8353 * gtk_entry_set_icon_tooltip_markup().
8358 gtk_entry_set_icon_tooltip_text (GtkEntry *entry,
8359 GtkEntryIconPosition icon_pos,
8360 const gchar *tooltip)
8362 GtkEntryPrivate *priv;
8363 EntryIconInfo *icon_info;
8365 g_return_if_fail (GTK_IS_ENTRY (entry));
8366 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8368 priv = GTK_ENTRY_GET_PRIVATE (entry);
8370 if (!(icon_info = priv->icons[icon_pos]))
8371 icon_info = priv->icons[icon_pos];
8373 if (icon_info->tooltip)
8374 g_free (icon_info->tooltip);
8376 /* Treat an empty string as a NULL string,
8377 * because an empty string would be useless for a tooltip:
8379 if (tooltip && tooltip[0] == '\0')
8382 icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
8384 ensure_has_tooltip (entry);
8388 * gtk_entry_get_icon_tooltip_markup:
8389 * @entry: a #GtkEntry
8390 * @icon_pos: the icon position
8392 * Gets the contents of the tooltip on the icon at the specified
8393 * position in @entry.
8395 * Returns: the tooltip text, or %NULL. Free the returned string
8396 * with g_free() when done.
8401 gtk_entry_get_icon_tooltip_markup (GtkEntry *entry,
8402 GtkEntryIconPosition icon_pos)
8404 GtkEntryPrivate *priv;
8405 EntryIconInfo *icon_info;
8407 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
8408 g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
8410 priv = GTK_ENTRY_GET_PRIVATE (entry);
8411 icon_info = priv->icons[icon_pos];
8416 return g_strdup (icon_info->tooltip);
8420 * gtk_entry_set_icon_tooltip_markup:
8421 * @entry: a #GtkEntry
8422 * @icon_pos: the icon position
8423 * @tooltip: the contents of the tooltip for the icon, or %NULL
8425 * Sets @tooltip as the contents of the tooltip for the icon at
8426 * the specified position. @tooltip is assumed to be marked up with
8427 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
8429 * Use %NULL for @tooltip to remove an existing tooltip.
8431 * See also gtk_widget_set_tooltip_markup() and
8432 * gtk_enty_set_icon_tooltip_text().
8437 gtk_entry_set_icon_tooltip_markup (GtkEntry *entry,
8438 GtkEntryIconPosition icon_pos,
8439 const gchar *tooltip)
8441 GtkEntryPrivate *priv;
8442 EntryIconInfo *icon_info;
8444 g_return_if_fail (GTK_IS_ENTRY (entry));
8445 g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
8447 priv = GTK_ENTRY_GET_PRIVATE (entry);
8449 if (!(icon_info = priv->icons[icon_pos]))
8450 icon_info = priv->icons[icon_pos];
8452 if (icon_info->tooltip)
8453 g_free (icon_info->tooltip);
8455 /* Treat an empty string as a NULL string,
8456 * because an empty string would be useless for a tooltip:
8458 if (tooltip && tooltip[0] == '\0')
8461 icon_info->tooltip = g_strdup (tooltip);
8463 ensure_has_tooltip (entry);
8467 gtk_entry_query_tooltip (GtkWidget *widget,
8470 gboolean keyboard_tip,
8471 GtkTooltip *tooltip)
8474 GtkEntryPrivate *priv;
8475 EntryIconInfo *icon_info;
8478 entry = GTK_ENTRY (widget);
8479 priv = GTK_ENTRY_GET_PRIVATE (entry);
8483 icon_pos = gtk_entry_get_icon_at_pos (entry, x, y);
8486 if ((icon_info = priv->icons[icon_pos]) != NULL)
8488 if (icon_info->tooltip)
8490 gtk_tooltip_set_markup (tooltip, icon_info->tooltip);
8499 return GTK_WIDGET_CLASS (gtk_entry_parent_class)->query_tooltip (widget,
8506 /* Quick hack of a popup menu
8509 activate_cb (GtkWidget *menuitem,
8512 const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
8513 g_signal_emit_by_name (entry, signal);
8518 gtk_entry_mnemonic_activate (GtkWidget *widget,
8519 gboolean group_cycling)
8521 gtk_widget_grab_focus (widget);
8526 append_action_signal (GtkEntry *entry,
8528 const gchar *stock_id,
8529 const gchar *signal,
8532 GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
8534 g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
8535 g_signal_connect (menuitem, "activate",
8536 G_CALLBACK (activate_cb), entry);
8538 gtk_widget_set_sensitive (menuitem, sensitive);
8540 gtk_widget_show (menuitem);
8541 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8545 popup_menu_detach (GtkWidget *attach_widget,
8548 GTK_ENTRY (attach_widget)->popup_menu = NULL;
8552 popup_position_func (GtkMenu *menu,
8558 GtkEntry *entry = GTK_ENTRY (user_data);
8559 GtkWidget *widget = GTK_WIDGET (entry);
8561 GtkRequisition menu_req;
8562 GdkRectangle monitor;
8563 GtkBorder inner_border;
8564 gint monitor_num, strong_x, height;
8566 g_return_if_fail (GTK_WIDGET_REALIZED (entry));
8568 gdk_window_get_origin (entry->text_area, x, y);
8570 screen = gtk_widget_get_screen (widget);
8571 monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
8572 if (monitor_num < 0)
8574 gtk_menu_set_monitor (menu, monitor_num);
8576 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8577 gtk_widget_size_request (entry->popup_menu, &menu_req);
8578 gdk_drawable_get_size (entry->text_area, NULL, &height);
8579 gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
8580 _gtk_entry_effective_inner_border (entry, &inner_border);
8582 *x += inner_border.left + strong_x - entry->scroll_offset;
8583 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
8584 *x -= menu_req.width;
8586 if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
8588 else if ((*y - menu_req.height) >= monitor.y)
8589 *y -= menu_req.height;
8590 else if (monitor.y + monitor.height - (*y + height) > *y)
8593 *y -= menu_req.height;
8599 unichar_chosen_func (const char *text,
8602 GtkEntry *entry = GTK_ENTRY (data);
8604 if (entry->editable)
8605 gtk_entry_enter_text (entry, text);
8616 popup_targets_received (GtkClipboard *clipboard,
8617 GtkSelectionData *data,
8620 PopupInfo *info = user_data;
8621 GtkEntry *entry = info->entry;
8623 if (GTK_WIDGET_REALIZED (entry))
8626 gboolean clipboard_contains_text;
8627 GtkWidget *menuitem;
8629 gboolean show_input_method_menu;
8630 gboolean show_unicode_menu;
8632 clipboard_contains_text = gtk_selection_data_targets_include_text (data);
8633 if (entry->popup_menu)
8634 gtk_widget_destroy (entry->popup_menu);
8636 entry->popup_menu = gtk_menu_new ();
8638 gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
8642 mode = gtk_entry_get_display_mode (entry);
8643 append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
8644 entry->editable && mode == DISPLAY_NORMAL &&
8645 entry->current_pos != entry->selection_bound);
8647 append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
8648 mode == DISPLAY_NORMAL &&
8649 entry->current_pos != entry->selection_bound);
8651 append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
8652 entry->editable && clipboard_contains_text);
8654 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
8655 gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
8656 g_signal_connect_swapped (menuitem, "activate",
8657 G_CALLBACK (gtk_entry_delete_cb), entry);
8658 gtk_widget_show (menuitem);
8659 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8661 menuitem = gtk_separator_menu_item_new ();
8662 gtk_widget_show (menuitem);
8663 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8665 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
8666 g_signal_connect_swapped (menuitem, "activate",
8667 G_CALLBACK (gtk_entry_select_all), entry);
8668 gtk_widget_show (menuitem);
8669 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8671 g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
8672 "gtk-show-input-method-menu", &show_input_method_menu,
8673 "gtk-show-unicode-menu", &show_unicode_menu,
8676 if (show_input_method_menu || show_unicode_menu)
8678 menuitem = gtk_separator_menu_item_new ();
8679 gtk_widget_show (menuitem);
8680 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8683 if (show_input_method_menu)
8685 menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
8686 gtk_widget_set_sensitive (menuitem, entry->editable);
8687 gtk_widget_show (menuitem);
8688 submenu = gtk_menu_new ();
8689 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8691 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8693 gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
8694 GTK_MENU_SHELL (submenu));
8697 if (show_unicode_menu)
8699 menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
8700 gtk_widget_set_sensitive (menuitem, entry->editable);
8701 gtk_widget_show (menuitem);
8703 submenu = gtk_menu_new ();
8704 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
8705 gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
8707 _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
8708 unichar_chosen_func,
8712 g_signal_emit (entry,
8713 signals[POPULATE_POPUP],
8719 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8721 info->button, info->time);
8724 gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
8725 popup_position_func, entry,
8726 info->button, info->time);
8727 gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
8731 g_object_unref (entry);
8732 g_slice_free (PopupInfo, info);
8736 gtk_entry_do_popup (GtkEntry *entry,
8737 GdkEventButton *event)
8739 PopupInfo *info = g_slice_new (PopupInfo);
8741 /* In order to know what entries we should make sensitive, we
8742 * ask for the current targets of the clipboard, and when
8743 * we get them, then we actually pop up the menu.
8745 info->entry = g_object_ref (entry);
8749 info->button = event->button;
8750 info->time = event->time;
8755 info->time = gtk_get_current_event_time ();
8758 gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
8759 gdk_atom_intern_static_string ("TARGETS"),
8760 popup_targets_received,
8765 gtk_entry_popup_menu (GtkWidget *widget)
8767 gtk_entry_do_popup (GTK_ENTRY (widget), NULL);
8772 gtk_entry_drag_begin (GtkWidget *widget,
8773 GdkDragContext *context)
8775 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8778 for (i = 0; i < MAX_ICONS; i++)
8780 EntryIconInfo *icon_info = priv->icons[i];
8782 if (icon_info != NULL)
8784 if (icon_info->in_drag)
8786 switch (icon_info->storage_type)
8788 case GTK_IMAGE_STOCK:
8789 gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
8792 case GTK_IMAGE_ICON_NAME:
8793 gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
8796 /* FIXME: No GIcon support for dnd icons */
8797 case GTK_IMAGE_GICON:
8798 case GTK_IMAGE_PIXBUF:
8799 gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
8802 g_assert_not_reached ();
8810 gtk_entry_drag_end (GtkWidget *widget,
8811 GdkDragContext *context)
8813 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8816 for (i = 0; i < MAX_ICONS; i++)
8818 EntryIconInfo *icon_info = priv->icons[i];
8820 if (icon_info != NULL)
8821 icon_info->in_drag = 0;
8826 gtk_entry_drag_leave (GtkWidget *widget,
8827 GdkDragContext *context,
8830 GtkEntry *entry = GTK_ENTRY (widget);
8832 entry->dnd_position = -1;
8833 gtk_widget_queue_draw (widget);
8837 gtk_entry_drag_drop (GtkWidget *widget,
8838 GdkDragContext *context,
8843 GtkEntry *entry = GTK_ENTRY (widget);
8844 GdkAtom target = GDK_NONE;
8846 if (entry->editable)
8847 target = gtk_drag_dest_find_target (widget, context, NULL);
8849 if (target != GDK_NONE)
8850 gtk_drag_get_data (widget, context, target, time);
8852 gtk_drag_finish (context, FALSE, FALSE, time);
8858 gtk_entry_drag_motion (GtkWidget *widget,
8859 GdkDragContext *context,
8864 GtkEntry *entry = GTK_ENTRY (widget);
8865 GtkWidget *source_widget;
8866 GdkDragAction suggested_action;
8867 gint new_position, old_position;
8870 x -= widget->style->xthickness;
8871 y -= widget->style->ythickness;
8873 old_position = entry->dnd_position;
8874 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8876 if (entry->editable &&
8877 gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
8879 source_widget = gtk_drag_get_source_widget (context);
8880 suggested_action = context->suggested_action;
8882 if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
8883 new_position < sel1 || new_position > sel2)
8885 if (source_widget == widget)
8887 /* Default to MOVE, unless the user has
8888 * pressed ctrl or alt to affect available actions
8890 if ((context->actions & GDK_ACTION_MOVE) != 0)
8891 suggested_action = GDK_ACTION_MOVE;
8894 entry->dnd_position = new_position;
8898 if (source_widget == widget)
8899 suggested_action = 0; /* Can't drop in selection where drag started */
8901 entry->dnd_position = -1;
8906 /* Entry not editable, or no text */
8907 suggested_action = 0;
8908 entry->dnd_position = -1;
8911 gdk_drag_status (context, suggested_action, time);
8913 if (entry->dnd_position != old_position)
8914 gtk_widget_queue_draw (widget);
8920 gtk_entry_drag_data_received (GtkWidget *widget,
8921 GdkDragContext *context,
8924 GtkSelectionData *selection_data,
8928 GtkEntry *entry = GTK_ENTRY (widget);
8929 GtkEditable *editable = GTK_EDITABLE (widget);
8932 str = (gchar *) gtk_selection_data_get_text (selection_data);
8934 x -= widget->style->xthickness;
8935 y -= widget->style->ythickness;
8937 if (str && entry->editable)
8943 if (entry->truncate_multiline)
8944 length = truncate_multiline (str);
8946 new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
8948 if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
8949 new_position < sel1 || new_position > sel2)
8951 gtk_editable_insert_text (editable, str, length, &new_position);
8955 /* Replacing selection */
8956 begin_change (entry);
8957 g_object_freeze_notify (G_OBJECT (entry));
8958 gtk_editable_delete_text (editable, sel1, sel2);
8959 gtk_editable_insert_text (editable, str, length, &sel1);
8960 g_object_thaw_notify (G_OBJECT (entry));
8964 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
8968 /* Drag and drop didn't happen! */
8969 gtk_drag_finish (context, FALSE, FALSE, time);
8976 gtk_entry_drag_data_get (GtkWidget *widget,
8977 GdkDragContext *context,
8978 GtkSelectionData *selection_data,
8982 gint sel_start, sel_end;
8985 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
8986 GtkEditable *editable = GTK_EDITABLE (widget);
8988 /* If there is an icon drag going on, exit early. */
8989 for (i = 0; i < MAX_ICONS; i++)
8991 EntryIconInfo *icon_info = priv->icons[i];
8993 if (icon_info != NULL)
8995 if (icon_info->in_drag)
9000 if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9002 gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
9004 gtk_selection_data_set_text (selection_data, str, -1);
9012 gtk_entry_drag_data_delete (GtkWidget *widget,
9013 GdkDragContext *context)
9015 gint sel_start, sel_end;
9018 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
9019 GtkEditable *editable = GTK_EDITABLE (widget);
9021 /* If there is an icon drag going on, exit early. */
9022 for (i = 0; i < MAX_ICONS; i++)
9024 EntryIconInfo *icon_info = priv->icons[i];
9026 if (icon_info != NULL)
9028 if (icon_info->in_drag)
9033 if (GTK_ENTRY (widget)->editable &&
9034 gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
9035 gtk_editable_delete_text (editable, sel_start, sel_end);
9038 /* We display the cursor when
9040 * - the selection is empty, AND
9041 * - the widget has focus
9044 #define CURSOR_ON_MULTIPLIER 2
9045 #define CURSOR_OFF_MULTIPLIER 1
9046 #define CURSOR_PEND_MULTIPLIER 3
9047 #define CURSOR_DIVIDER 3
9050 cursor_blinks (GtkEntry *entry)
9052 if (GTK_WIDGET_HAS_FOCUS (entry) &&
9054 entry->selection_bound == entry->current_pos)
9056 GtkSettings *settings;
9059 settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9060 g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
9069 get_cursor_time (GtkEntry *entry)
9071 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9074 g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
9080 get_cursor_blink_timeout (GtkEntry *entry)
9082 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
9085 g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
9091 show_cursor (GtkEntry *entry)
9093 if (!entry->cursor_visible)
9095 entry->cursor_visible = TRUE;
9097 if (GTK_WIDGET_HAS_FOCUS (entry) && entry->selection_bound == entry->current_pos)
9098 gtk_widget_queue_draw (GTK_WIDGET (entry));
9103 hide_cursor (GtkEntry *entry)
9105 if (entry->cursor_visible)
9107 entry->cursor_visible = FALSE;
9109 if (GTK_WIDGET_HAS_FOCUS (entry) && entry->selection_bound == entry->current_pos)
9110 gtk_widget_queue_draw (GTK_WIDGET (entry));
9118 blink_cb (gpointer data)
9121 GtkEntryPrivate *priv;
9124 entry = GTK_ENTRY (data);
9125 priv = GTK_ENTRY_GET_PRIVATE (entry);
9127 if (!GTK_WIDGET_HAS_FOCUS (entry))
9129 g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
9130 "connect a handler to this signal, it must return\n"
9131 "FALSE so the entry gets the event as well");
9133 gtk_entry_check_cursor_blink (entry);
9138 g_assert (entry->selection_bound == entry->current_pos);
9140 blink_timeout = get_cursor_blink_timeout (entry);
9141 if (priv->blink_time > 1000 * blink_timeout &&
9142 blink_timeout < G_MAXINT/1000)
9144 /* we've blinked enough without the user doing anything, stop blinking */
9145 show_cursor (entry);
9146 entry->blink_timeout = 0;
9148 else if (entry->cursor_visible)
9150 hide_cursor (entry);
9151 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
9157 show_cursor (entry);
9158 priv->blink_time += get_cursor_time (entry);
9159 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9164 /* Remove ourselves */
9169 gtk_entry_check_cursor_blink (GtkEntry *entry)
9171 GtkEntryPrivate *priv;
9173 priv = GTK_ENTRY_GET_PRIVATE (entry);
9175 if (cursor_blinks (entry))
9177 if (!entry->blink_timeout)
9179 show_cursor (entry);
9180 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
9187 if (entry->blink_timeout)
9189 g_source_remove (entry->blink_timeout);
9190 entry->blink_timeout = 0;
9193 entry->cursor_visible = TRUE;
9199 gtk_entry_pend_cursor_blink (GtkEntry *entry)
9201 if (cursor_blinks (entry))
9203 if (entry->blink_timeout != 0)
9204 g_source_remove (entry->blink_timeout);
9206 entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
9209 show_cursor (entry);
9214 gtk_entry_reset_blink_time (GtkEntry *entry)
9216 GtkEntryPrivate *priv;
9218 priv = GTK_ENTRY_GET_PRIVATE (entry);
9220 priv->blink_time = 0;
9226 gtk_entry_completion_timeout (gpointer data)
9228 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
9230 completion->priv->completion_timeout = 0;
9232 if (completion->priv->filter_model &&
9233 g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
9234 >= completion->priv->minimum_key_length)
9238 GtkTreeSelection *s;
9239 gboolean popup_single;
9241 gtk_entry_completion_complete (completion);
9242 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9244 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9246 s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9248 gtk_tree_selection_unselect_all (s);
9250 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9252 g_object_get (completion, "popup-single-match", &popup_single, NULL);
9253 if ((matches > (popup_single ? 0: 1)) || actions > 0)
9255 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
9256 _gtk_entry_completion_resize_popup (completion);
9258 _gtk_entry_completion_popup (completion);
9261 _gtk_entry_completion_popdown (completion);
9263 else if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
9264 _gtk_entry_completion_popdown (completion);
9269 static inline gboolean
9270 keyval_is_cursor_move (guint keyval)
9272 if (keyval == GDK_Up || keyval == GDK_KP_Up)
9275 if (keyval == GDK_Down || keyval == GDK_KP_Down)
9278 if (keyval == GDK_Page_Up)
9281 if (keyval == GDK_Page_Down)
9288 gtk_entry_completion_key_press (GtkWidget *widget,
9292 gint matches, actions = 0;
9293 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9295 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
9298 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
9300 if (completion->priv->actions)
9301 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
9303 if (keyval_is_cursor_move (event->keyval))
9305 GtkTreePath *path = NULL;
9307 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
9309 if (completion->priv->current_selected < 0)
9310 completion->priv->current_selected = matches + actions - 1;
9312 completion->priv->current_selected--;
9314 else if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
9316 if (completion->priv->current_selected < matches + actions - 1)
9317 completion->priv->current_selected++;
9319 completion->priv->current_selected = -1;
9321 else if (event->keyval == GDK_Page_Up)
9323 if (completion->priv->current_selected < 0)
9324 completion->priv->current_selected = matches + actions - 1;
9325 else if (completion->priv->current_selected == 0)
9326 completion->priv->current_selected = -1;
9327 else if (completion->priv->current_selected < matches)
9329 completion->priv->current_selected -= 14;
9330 if (completion->priv->current_selected < 0)
9331 completion->priv->current_selected = 0;
9335 completion->priv->current_selected -= 14;
9336 if (completion->priv->current_selected < matches - 1)
9337 completion->priv->current_selected = matches - 1;
9340 else if (event->keyval == GDK_Page_Down)
9342 if (completion->priv->current_selected < 0)
9343 completion->priv->current_selected = 0;
9344 else if (completion->priv->current_selected < matches - 1)
9346 completion->priv->current_selected += 14;
9347 if (completion->priv->current_selected > matches - 1)
9348 completion->priv->current_selected = matches - 1;
9350 else if (completion->priv->current_selected == matches + actions - 1)
9352 completion->priv->current_selected = -1;
9356 completion->priv->current_selected += 14;
9357 if (completion->priv->current_selected > matches + actions - 1)
9358 completion->priv->current_selected = matches + actions - 1;
9362 if (completion->priv->current_selected < 0)
9364 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9365 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9367 if (completion->priv->inline_selection &&
9368 completion->priv->completion_prefix)
9370 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9371 completion->priv->completion_prefix);
9372 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9375 else if (completion->priv->current_selected < matches)
9377 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
9379 path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
9380 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
9383 if (completion->priv->inline_selection)
9387 GtkTreeModel *model = NULL;
9388 GtkTreeSelection *sel;
9391 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9392 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
9395 if (completion->priv->completion_prefix == NULL)
9396 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
9398 g_signal_emit_by_name (completion, "cursor-on-match", model,
9402 else if (completion->priv->current_selected - matches >= 0)
9404 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
9406 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9407 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
9410 if (completion->priv->inline_selection &&
9411 completion->priv->completion_prefix)
9413 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9414 completion->priv->completion_prefix);
9415 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9419 gtk_tree_path_free (path);
9423 else if (event->keyval == GDK_Escape ||
9424 event->keyval == GDK_Left ||
9425 event->keyval == GDK_KP_Left ||
9426 event->keyval == GDK_Right ||
9427 event->keyval == GDK_KP_Right)
9429 gboolean retval = TRUE;
9431 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9432 _gtk_entry_completion_popdown (completion);
9434 if (completion->priv->current_selected < 0)
9437 goto keypress_completion_out;
9439 else if (completion->priv->inline_selection)
9441 /* Escape rejects the tentative completion */
9442 if (event->keyval == GDK_Escape)
9444 if (completion->priv->completion_prefix)
9445 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
9446 completion->priv->completion_prefix);
9448 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
9451 /* Move the cursor to the end for Right/Esc, to the
9452 beginning for Left */
9453 if (event->keyval == GDK_Right ||
9454 event->keyval == GDK_KP_Right ||
9455 event->keyval == GDK_Escape)
9456 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9458 gtk_editable_set_position (GTK_EDITABLE (widget), 0);
9461 keypress_completion_out:
9462 if (completion->priv->inline_selection)
9464 g_free (completion->priv->completion_prefix);
9465 completion->priv->completion_prefix = NULL;
9470 else if (event->keyval == GDK_Tab ||
9471 event->keyval == GDK_KP_Tab ||
9472 event->keyval == GDK_ISO_Left_Tab)
9474 GtkDirectionType dir = event->keyval == GDK_ISO_Left_Tab ?
9475 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
9477 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9478 _gtk_entry_completion_popdown (completion);
9480 g_free (completion->priv->completion_prefix);
9481 completion->priv->completion_prefix = NULL;
9483 gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
9487 else if (event->keyval == GDK_ISO_Enter ||
9488 event->keyval == GDK_KP_Enter ||
9489 event->keyval == GDK_Return)
9492 GtkTreeModel *model = NULL;
9493 GtkTreeSelection *sel;
9494 gboolean retval = TRUE;
9496 _gtk_entry_reset_im_context (GTK_ENTRY (widget));
9497 _gtk_entry_completion_popdown (completion);
9499 if (completion->priv->current_selected < matches)
9503 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
9504 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9506 g_signal_handler_block (widget, completion->priv->changed_id);
9507 g_signal_emit_by_name (completion, "match-selected",
9508 model, &iter, &entry_set);
9509 g_signal_handler_unblock (widget, completion->priv->changed_id);
9515 gtk_tree_model_get (model, &iter,
9516 completion->priv->text_column, &str,
9519 gtk_entry_set_text (GTK_ENTRY (widget), str);
9521 /* move the cursor to the end */
9522 gtk_editable_set_position (GTK_EDITABLE (widget), -1);
9530 else if (completion->priv->current_selected - matches >= 0)
9532 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
9533 if (gtk_tree_selection_get_selected (sel, &model, &iter))
9537 path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
9538 g_signal_emit_by_name (completion, "action-activated",
9539 gtk_tree_path_get_indices (path)[0]);
9540 gtk_tree_path_free (path);
9546 g_free (completion->priv->completion_prefix);
9547 completion->priv->completion_prefix = NULL;
9556 gtk_entry_completion_changed (GtkWidget *entry,
9559 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
9561 /* (re)install completion timeout */
9562 if (completion->priv->completion_timeout)
9563 g_source_remove (completion->priv->completion_timeout);
9565 if (!gtk_entry_get_text (GTK_ENTRY (entry)))
9568 /* no need to normalize for this test */
9569 if (completion->priv->minimum_key_length > 0 &&
9570 strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
9572 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
9573 _gtk_entry_completion_popdown (completion);
9577 completion->priv->completion_timeout =
9578 gdk_threads_add_timeout (COMPLETION_TIMEOUT,
9579 gtk_entry_completion_timeout,
9584 check_completion_callback (GtkEntryCompletion *completion)
9586 completion->priv->check_completion_idle = NULL;
9588 gtk_entry_completion_complete (completion);
9589 gtk_entry_completion_insert_prefix (completion);
9595 clear_completion_callback (GtkEntry *entry,
9598 if (pspec->name == I_("cursor-position") ||
9599 pspec->name == I_("selection-bound"))
9601 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9603 completion->priv->has_completion = FALSE;
9608 accept_completion_callback (GtkEntry *entry)
9610 GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
9612 if (completion->priv->has_completion)
9613 gtk_editable_set_position (GTK_EDITABLE (entry),
9614 gtk_entry_buffer_get_length (get_buffer (entry)));
9620 completion_insert_text_callback (GtkEntry *entry,
9624 GtkEntryCompletion *completion)
9626 /* idle to update the selection based on the file list */
9627 if (completion->priv->check_completion_idle == NULL)
9629 completion->priv->check_completion_idle = g_idle_source_new ();
9630 g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
9631 g_source_set_closure (completion->priv->check_completion_idle,
9632 g_cclosure_new_object (G_CALLBACK (check_completion_callback),
9633 G_OBJECT (completion)));
9634 g_source_attach (completion->priv->check_completion_idle, NULL);
9639 completion_changed (GtkEntryCompletion *completion,
9643 GtkEntry *entry = GTK_ENTRY (data);
9645 if (pspec->name == I_("popup-completion") ||
9646 pspec->name == I_("inline-completion"))
9648 disconnect_completion_signals (entry, completion);
9649 connect_completion_signals (entry, completion);
9654 disconnect_completion_signals (GtkEntry *entry,
9655 GtkEntryCompletion *completion)
9657 g_signal_handlers_disconnect_by_func (completion,
9658 G_CALLBACK (completion_changed), entry);
9659 if (completion->priv->changed_id > 0 &&
9660 g_signal_handler_is_connected (entry, completion->priv->changed_id))
9662 g_signal_handler_disconnect (entry, completion->priv->changed_id);
9663 completion->priv->changed_id = 0;
9665 g_signal_handlers_disconnect_by_func (entry,
9666 G_CALLBACK (gtk_entry_completion_key_press), completion);
9667 if (completion->priv->insert_text_id > 0 &&
9668 g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
9670 g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
9671 completion->priv->insert_text_id = 0;
9673 g_signal_handlers_disconnect_by_func (entry,
9674 G_CALLBACK (completion_insert_text_callback), completion);
9675 g_signal_handlers_disconnect_by_func (entry,
9676 G_CALLBACK (clear_completion_callback), completion);
9677 g_signal_handlers_disconnect_by_func (entry,
9678 G_CALLBACK (accept_completion_callback), completion);
9682 connect_completion_signals (GtkEntry *entry,
9683 GtkEntryCompletion *completion)
9685 if (completion->priv->popup_completion)
9687 completion->priv->changed_id =
9688 g_signal_connect (entry, "changed",
9689 G_CALLBACK (gtk_entry_completion_changed), completion);
9690 g_signal_connect (entry, "key-press-event",
9691 G_CALLBACK (gtk_entry_completion_key_press), completion);
9694 if (completion->priv->inline_completion)
9696 completion->priv->insert_text_id =
9697 g_signal_connect (entry, "insert-text",
9698 G_CALLBACK (completion_insert_text_callback), completion);
9699 g_signal_connect (entry, "notify",
9700 G_CALLBACK (clear_completion_callback), completion);
9701 g_signal_connect (entry, "activate",
9702 G_CALLBACK (accept_completion_callback), completion);
9703 g_signal_connect (entry, "focus-out-event",
9704 G_CALLBACK (accept_completion_callback), completion);
9707 g_signal_connect (completion, "notify",
9708 G_CALLBACK (completion_changed), entry);
9712 * gtk_entry_set_completion:
9713 * @entry: A #GtkEntry
9714 * @completion: (allow-none): The #GtkEntryCompletion or %NULL
9716 * Sets @completion to be the auxiliary completion object to use with @entry.
9717 * All further configuration of the completion mechanism is done on
9718 * @completion using the #GtkEntryCompletion API. Completion is disabled if
9719 * @completion is set to %NULL.
9724 gtk_entry_set_completion (GtkEntry *entry,
9725 GtkEntryCompletion *completion)
9727 GtkEntryCompletion *old;
9729 g_return_if_fail (GTK_IS_ENTRY (entry));
9730 g_return_if_fail (!completion || GTK_IS_ENTRY_COMPLETION (completion));
9732 old = gtk_entry_get_completion (entry);
9734 if (old == completion)
9739 if (old->priv->completion_timeout)
9741 g_source_remove (old->priv->completion_timeout);
9742 old->priv->completion_timeout = 0;
9745 if (GTK_WIDGET_MAPPED (old->priv->popup_window))
9746 _gtk_entry_completion_popdown (old);
9748 disconnect_completion_signals (entry, old);
9749 old->priv->entry = NULL;
9751 g_object_unref (old);
9756 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
9760 /* hook into the entry */
9761 g_object_ref (completion);
9763 connect_completion_signals (entry, completion);
9764 completion->priv->entry = GTK_WIDGET (entry);
9765 g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
9769 * gtk_entry_get_completion:
9770 * @entry: A #GtkEntry
9772 * Returns the auxiliary completion object currently in use by @entry.
9774 * Return value: The auxiliary completion object currently in use by @entry.
9778 GtkEntryCompletion *
9779 gtk_entry_get_completion (GtkEntry *entry)
9781 GtkEntryCompletion *completion;
9783 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9785 completion = GTK_ENTRY_COMPLETION (g_object_get_data (G_OBJECT (entry),
9786 GTK_ENTRY_COMPLETION_KEY));
9792 * gtk_entry_set_cursor_hadjustment:
9793 * @entry: a #GtkEntry
9794 * @adjustment: an adjustment which should be adjusted when the cursor
9795 * is moved, or %NULL
9797 * Hooks up an adjustment to the cursor position in an entry, so that when
9798 * the cursor is moved, the adjustment is scrolled to show that position.
9799 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
9802 * The adjustment has to be in pixel units and in the same coordinate system
9808 gtk_entry_set_cursor_hadjustment (GtkEntry *entry,
9809 GtkAdjustment *adjustment)
9811 g_return_if_fail (GTK_IS_ENTRY (entry));
9813 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
9816 g_object_ref (adjustment);
9818 g_object_set_qdata_full (G_OBJECT (entry),
9819 quark_cursor_hadjustment,
9825 * gtk_entry_get_cursor_hadjustment:
9826 * @entry: a #GtkEntry
9828 * Retrieves the horizontal cursor adjustment for the entry.
9829 * See gtk_entry_set_cursor_hadjustment().
9831 * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
9832 * if none has been set.
9837 gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
9839 g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
9841 return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
9845 * gtk_entry_set_progress_fraction:
9846 * @entry: a #GtkEntry
9847 * @fraction: fraction of the task that's been completed
9849 * Causes the entry's progress indicator to "fill in" the given
9850 * fraction of the bar. The fraction should be between 0.0 and 1.0,
9856 gtk_entry_set_progress_fraction (GtkEntry *entry,
9859 GtkEntryPrivate *private;
9860 gdouble old_fraction;
9861 gint x, y, width, height;
9862 gint old_x, old_y, old_width, old_height;
9864 g_return_if_fail (GTK_IS_ENTRY (entry));
9866 private = GTK_ENTRY_GET_PRIVATE (entry);
9868 if (private->progress_pulse_mode)
9871 old_fraction = private->progress_fraction;
9873 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (entry)))
9874 get_progress_area (GTK_WIDGET(entry), &old_x, &old_y, &old_width, &old_height);
9876 fraction = CLAMP (fraction, 0.0, 1.0);
9878 private->progress_fraction = fraction;
9879 private->progress_pulse_mode = FALSE;
9880 private->progress_pulse_current = 0.0;
9882 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (entry)))
9884 get_progress_area (GTK_WIDGET(entry), &x, &y, &width, &height);
9886 if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
9887 gtk_widget_queue_draw (GTK_WIDGET (entry));
9890 if (fraction != old_fraction)
9891 g_object_notify (G_OBJECT (entry), "progress-fraction");
9895 * gtk_entry_get_progress_fraction:
9896 * @entry: a #GtkEntry
9898 * Returns the current fraction of the task that's been completed.
9899 * See gtk_entry_set_progress_fraction().
9901 * Return value: a fraction from 0.0 to 1.0
9906 gtk_entry_get_progress_fraction (GtkEntry *entry)
9908 GtkEntryPrivate *private;
9910 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9912 private = GTK_ENTRY_GET_PRIVATE (entry);
9914 return private->progress_fraction;
9918 * gtk_entry_set_progress_pulse_step:
9919 * @entry: a #GtkEntry
9920 * @fraction: fraction between 0.0 and 1.0
9922 * Sets the fraction of total entry width to move the progress
9923 * bouncing block for each call to gtk_entry_progress_pulse().
9928 gtk_entry_set_progress_pulse_step (GtkEntry *entry,
9931 GtkEntryPrivate *private;
9933 g_return_if_fail (GTK_IS_ENTRY (entry));
9935 private = GTK_ENTRY_GET_PRIVATE (entry);
9937 fraction = CLAMP (fraction, 0.0, 1.0);
9939 if (fraction != private->progress_pulse_fraction)
9941 private->progress_pulse_fraction = fraction;
9943 gtk_widget_queue_draw (GTK_WIDGET (entry));
9945 g_object_notify (G_OBJECT (entry), "progress-pulse-step");
9950 * gtk_entry_get_progress_pulse_step:
9951 * @entry: a #GtkEntry
9953 * Retrieves the pulse step set with gtk_entry_set_progress_pulse_step().
9955 * Return value: a fraction from 0.0 to 1.0
9960 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
9962 GtkEntryPrivate *private;
9964 g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
9966 private = GTK_ENTRY_GET_PRIVATE (entry);
9968 return private->progress_pulse_fraction;
9972 * gtk_entry_progress_pulse:
9973 * @entry: a #GtkEntry
9975 * Indicates that some progress is made, but you don't know how much.
9976 * Causes the entry's progress indicator to enter "activity mode,"
9977 * where a block bounces back and forth. Each call to
9978 * gtk_entry_progress_pulse() causes the block to move by a little bit
9979 * (the amount of movement per pulse is determined by
9980 * gtk_entry_set_progress_pulse_step()).
9985 gtk_entry_progress_pulse (GtkEntry *entry)
9987 GtkEntryPrivate *private;
9989 g_return_if_fail (GTK_IS_ENTRY (entry));
9991 private = GTK_ENTRY_GET_PRIVATE (entry);
9993 if (private->progress_pulse_mode)
9995 if (private->progress_pulse_way_back)
9997 private->progress_pulse_current -= private->progress_pulse_fraction;
9999 if (private->progress_pulse_current < 0.0)
10001 private->progress_pulse_current = 0.0;
10002 private->progress_pulse_way_back = FALSE;
10007 private->progress_pulse_current += private->progress_pulse_fraction;
10009 if (private->progress_pulse_current > 1.0 - private->progress_pulse_fraction)
10011 private->progress_pulse_current = 1.0 - private->progress_pulse_fraction;
10012 private->progress_pulse_way_back = TRUE;
10018 private->progress_fraction = 0.0;
10019 private->progress_pulse_mode = TRUE;
10020 private->progress_pulse_way_back = FALSE;
10021 private->progress_pulse_current = 0.0;
10024 gtk_widget_queue_draw (GTK_WIDGET (entry));
10027 /* Caps Lock warning for password entries */
10030 show_capslock_feedback (GtkEntry *entry,
10033 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10035 if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
10037 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CAPS_LOCK_WARNING);
10038 gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
10039 priv->caps_lock_warning_shown = TRUE;
10042 if (priv->caps_lock_warning_shown)
10043 gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, text);
10045 g_warning ("Can't show Caps Lock warning, since secondary icon is set");
10049 remove_capslock_feedback (GtkEntry *entry)
10051 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10053 if (priv->caps_lock_warning_shown)
10055 gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
10056 priv->caps_lock_warning_shown = FALSE;
10061 keymap_state_changed (GdkKeymap *keymap,
10064 GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
10067 if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
10069 if (gdk_keymap_get_caps_lock_state (keymap))
10070 text = _("Caps Lock is on");
10074 show_capslock_feedback (entry, text);
10076 remove_capslock_feedback (entry);
10079 #define __GTK_ENTRY_C__
10080 #include "gtkaliasdef.c"