#include "gtktooltip.h"
#include "gtkiconfactory.h"
#include "gtkicontheme.h"
-#include "gtkalias.h"
+
+
+/**
+ * SECTION:gtkentry
+ * @Short_description: A single line text entry field
+ * @Title: GtkEntry
+ * @See_also: #GtkTextView, #GtkEntryCompletion
+ *
+ * The #GtkEntry widget is a single line text entry
+ * widget. A fairly large set of key bindings are supported
+ * by default. If the entered text is longer than the allocation
+ * of the widget, the widget will scroll so that the cursor
+ * position is visible.
+ *
+ * When using an entry for passwords and other sensitive information,
+ * it can be put into "password mode" using gtk_entry_set_visibility().
+ * In this mode, entered text is displayed using a 'invisible' character.
+ * By default, GTK+ picks the best invisible character that is available
+ * in the current font, but it can be changed with
+ * gtk_entry_set_invisible_char(). Since 2.16, GTK+ displays a warning
+ * when Caps Lock or input methods might interfere with entering text in
+ * a password entry. The warning can be turned off with the
+ * #GtkEntry:caps-lock-warning property.
+ *
+ * Since 2.16, GtkEntry has the ability to display progress or activity
+ * information behind the text. To make an entry display such information,
+ * use gtk_entry_set_progress_fraction() or gtk_entry_set_progress_pulse_step().
+ *
+ * Additionally, GtkEntry can show icons at either side of the entry. These
+ * icons can be activatable by clicking, can be set up as drag source and
+ * can have tooltips. To add an icon, use gtk_entry_set_icon_from_gicon() or
+ * one of the various other functions that set an icon from a stock id, an
+ * icon name or a pixbuf. To trigger an action when the user clicks an icon,
+ * connect to the #GtkEntry::icon-press signal. To allow DND operations
+ * from an icon, use gtk_entry_set_icon_drag_source(). To set a tooltip on
+ * an icon, use gtk_entry_set_icon_tooltip_text() or the corresponding function
+ * for markup.
+ *
+ * Note that functionality or information that is only available by clicking
+ * on an icon in an entry may not be accessible at all to users which are not
+ * able to use a mouse or other pointing device. It is therefore recommended
+ * that any such functionality should also be available by other means, e.g.
+ * via the context menu of the entry.
+ */
+
#define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
gint start_y;
gchar *im_module;
+
+ GdkDevice *completion_device;
};
typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
TOGGLE_OVERWRITE,
ICON_PRESS,
ICON_RELEASE,
+ PREEDIT_CHANGED,
LAST_SIGNAL
};
PROP_TOOLTIP_TEXT_SECONDARY,
PROP_TOOLTIP_MARKUP_PRIMARY,
PROP_TOOLTIP_MARKUP_SECONDARY,
- PROP_IM_MODULE
+ PROP_IM_MODULE,
+ PROP_EDITING_CANCELED
};
static guint signals[LAST_SIGNAL] = { 0 };
DISPLAY_BLANK /* In invisible mode, nothing shown at all */
} DisplayMode;
-/* GObject, GtkObject methods
+/* GObject methods
*/
-static void gtk_entry_editable_init (GtkEditableClass *iface);
+static void gtk_entry_editable_init (GtkEditableInterface *iface);
static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
static void gtk_entry_set_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void gtk_entry_finalize (GObject *object);
-static void gtk_entry_destroy (GtkObject *object);
static void gtk_entry_dispose (GObject *object);
/* GtkWidget methods
*/
+static void gtk_entry_destroy (GtkWidget *widget);
static void gtk_entry_realize (GtkWidget *widget);
static void gtk_entry_unrealize (GtkWidget *widget);
static void gtk_entry_map (GtkWidget *widget);
static void gtk_entry_unmap (GtkWidget *widget);
-static void gtk_entry_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
+static void gtk_entry_get_preferred_width (GtkWidget *widget,
+ gint *minimum,
+ gint *natural);
+static void gtk_entry_get_preferred_height (GtkWidget *widget,
+ gint *minimum,
+ gint *natural);
static void gtk_entry_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void gtk_entry_draw_frame (GtkWidget *widget,
- GdkEventExpose *event);
+ cairo_t *cr);
static void gtk_entry_draw_progress (GtkWidget *widget,
- GdkEventExpose *event);
-static gint gtk_entry_expose (GtkWidget *widget,
- GdkEventExpose *event);
+ cairo_t *cr);
+static gint gtk_entry_draw (GtkWidget *widget,
+ cairo_t *cr);
static gint gtk_entry_button_press (GtkWidget *widget,
GdkEventButton *event);
static gint gtk_entry_button_release (GtkWidget *widget,
static void gtk_entry_set_positions (GtkEntry *entry,
gint current_pos,
gint selection_bound);
-static void gtk_entry_draw_text (GtkEntry *entry);
+static void gtk_entry_draw_text (GtkEntry *entry,
+ cairo_t *cr);
static void gtk_entry_draw_cursor (GtkEntry *entry,
+ cairo_t *cr,
CursorType type);
static PangoLayout *gtk_entry_ensure_layout (GtkEntry *entry,
gboolean include_preedit);
gint *y,
gint *width,
gint *height);
-static void get_widget_window_size (GtkEntry *entry,
+static void get_frame_size (GtkEntry *entry,
gint *x,
gint *y,
gint *width,
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class;
- GtkObjectClass *gtk_object_class;
GtkBindingSet *binding_set;
widget_class = (GtkWidgetClass*) class;
- gtk_object_class = (GtkObjectClass *)class;
gobject_class->dispose = gtk_entry_dispose;
gobject_class->finalize = gtk_entry_finalize;
gobject_class->set_property = gtk_entry_set_property;
gobject_class->get_property = gtk_entry_get_property;
+ widget_class->destroy = gtk_entry_destroy;
widget_class->map = gtk_entry_map;
widget_class->unmap = gtk_entry_unmap;
widget_class->realize = gtk_entry_realize;
widget_class->unrealize = gtk_entry_unrealize;
- widget_class->size_request = gtk_entry_size_request;
+ widget_class->get_preferred_width = gtk_entry_get_preferred_width;
+ widget_class->get_preferred_height = gtk_entry_get_preferred_height;
widget_class->size_allocate = gtk_entry_size_allocate;
- widget_class->expose_event = gtk_entry_expose;
+ widget_class->draw = gtk_entry_draw;
widget_class->enter_notify_event = gtk_entry_enter_notify;
widget_class->leave_notify_event = gtk_entry_leave_notify;
widget_class->button_press_event = gtk_entry_button_press;
widget_class->popup_menu = gtk_entry_popup_menu;
- gtk_object_class->destroy = gtk_entry_destroy;
-
class->move_cursor = gtk_entry_move_cursor;
class->insert_at_cursor = gtk_entry_insert_at_cursor;
class->delete_from_cursor = gtk_entry_delete_from_cursor;
quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
quark_capslock_feedback = g_quark_from_static_string ("gtk-entry-capslock-feedback");
+ g_object_class_override_property (gobject_class,
+ PROP_EDITING_CANCELED,
+ "editing-canceled");
+
g_object_class_install_property (gobject_class,
PROP_BUFFER,
g_param_spec_object ("buffer",
g_object_class_install_property (gobject_class,
PROP_INVISIBLE_CHAR_SET,
g_param_spec_boolean ("invisible-char-set",
- P_("Invisible char set"),
- P_("Whether the invisible char has been set"),
+ P_("Invisible character set"),
+ P_("Whether the invisible character has been set"),
FALSE,
GTK_PARAM_READWRITE));
GTK_PARAM_READABLE));
/**
- * GtkEntry::progress-border:
+ * GtkEntry:progress-border:
*
* The border around the progress bar in the entry.
*
GTK_PARAM_READABLE));
/**
- * GtkEntry::invisible-char:
+ * GtkEntry:invisible-char:
*
* The invisible character is used when masking entry contents (in
* \"password mode\")"). When it is not explicitly set with the
* This style property allows the theme to prepend a character
* to the list of candidates.
*
- * Since: 2.22
+ * Since: 2.18
*/
gtk_widget_class_install_style_property (widget_class,
g_param_spec_unichar ("invisible-char",
GTK_TYPE_ENTRY_ICON_POSITION,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+ /**
+ * GtkEntry::preedit-changed:
+ * @entry: the object which received the signal
+ * @preedit: the current preedit string
+ *
+ * If an input method is used, the typed text will not immediately
+ * be committed to the buffer. So if you are interested in the text,
+ * connect to this signal.
+ *
+ * Since: 2.20
+ */
+ signals[PREEDIT_CHANGED] =
+ g_signal_new_class_handler (I_("preedit-changed"),
+ G_OBJECT_CLASS_TYPE (gobject_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ NULL,
+ NULL, NULL,
+ _gtk_marshal_VOID__STRING,
+ G_TYPE_NONE, 1,
+ G_TYPE_STRING);
+
/*
* Key bindings
binding_set = gtk_binding_set_by_class (class);
/* Moving the insertion point */
- add_move_binding (binding_set, GDK_Right, 0,
+ add_move_binding (binding_set, GDK_KEY_Right, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, 1);
- add_move_binding (binding_set, GDK_Left, 0,
+ add_move_binding (binding_set, GDK_KEY_Left, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, -1);
- add_move_binding (binding_set, GDK_KP_Right, 0,
+ add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, 1);
- add_move_binding (binding_set, GDK_KP_Left, 0,
+ add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
GTK_MOVEMENT_VISUAL_POSITIONS, -1);
- add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK,
+ add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, 1);
- add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK,
+ add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, -1);
- add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK,
+ add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, 1);
- add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
+ add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
GTK_MOVEMENT_WORDS, -1);
- add_move_binding (binding_set, GDK_Home, 0,
+ add_move_binding (binding_set, GDK_KEY_Home, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
- add_move_binding (binding_set, GDK_End, 0,
+ add_move_binding (binding_set, GDK_KEY_End, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
- add_move_binding (binding_set, GDK_KP_Home, 0,
+ add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
- add_move_binding (binding_set, GDK_KP_End, 0,
+ add_move_binding (binding_set, GDK_KEY_KP_End, 0,
GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
- add_move_binding (binding_set, GDK_Home, GDK_CONTROL_MASK,
+ add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
GTK_MOVEMENT_BUFFER_ENDS, -1);
- add_move_binding (binding_set, GDK_End, GDK_CONTROL_MASK,
+ add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
GTK_MOVEMENT_BUFFER_ENDS, 1);
- add_move_binding (binding_set, GDK_KP_Home, GDK_CONTROL_MASK,
+ add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
GTK_MOVEMENT_BUFFER_ENDS, -1);
- add_move_binding (binding_set, GDK_KP_End, GDK_CONTROL_MASK,
+ add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
GTK_MOVEMENT_BUFFER_ENDS, 1);
/* Select all
*/
- gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
"move-cursor", 3,
GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
G_TYPE_INT, -1,
G_TYPE_BOOLEAN, FALSE);
- gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
"move-cursor", 3,
GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
G_TYPE_INT, 1,
G_TYPE_BOOLEAN, TRUE);
- gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
"move-cursor", 3,
GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
G_TYPE_INT, -1,
G_TYPE_BOOLEAN, FALSE);
- gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK,
"move-cursor", 3,
GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
G_TYPE_INT, 1,
G_TYPE_BOOLEAN, TRUE);
/* Unselect all
*/
- gtk_binding_entry_add_signal (binding_set, GDK_backslash, GDK_CONTROL_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
"move-cursor", 3,
GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
G_TYPE_INT, 0,
G_TYPE_BOOLEAN, FALSE);
- gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"move-cursor", 3,
GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
G_TYPE_INT, 0,
/* Activate
*/
- gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
"activate", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
"activate", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
"activate", 0);
/* Deleting text */
- gtk_binding_entry_add_signal (binding_set, GDK_Delete, 0,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
"delete-from-cursor", 2,
G_TYPE_ENUM, GTK_DELETE_CHARS,
G_TYPE_INT, 1);
- gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, 0,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
"delete-from-cursor", 2,
G_TYPE_ENUM, GTK_DELETE_CHARS,
G_TYPE_INT, 1);
- gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
"backspace", 0);
/* Make this do the same as Backspace, to help with mis-typing */
- gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_SHIFT_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
"backspace", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_CONTROL_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
"delete-from-cursor", 2,
G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
G_TYPE_INT, 1);
- gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, GDK_CONTROL_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
"delete-from-cursor", 2,
G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
G_TYPE_INT, 1);
- gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_CONTROL_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
"delete-from-cursor", 2,
G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
G_TYPE_INT, -1);
/* Cut/copy/paste */
- gtk_binding_entry_add_signal (binding_set, GDK_x, GDK_CONTROL_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
"cut-clipboard", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_c, GDK_CONTROL_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
"copy-clipboard", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_v, GDK_CONTROL_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
"paste-clipboard", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_SHIFT_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
"cut-clipboard", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_CONTROL_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
"copy-clipboard", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_SHIFT_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
"paste-clipboard", 0);
/* Overwrite */
- gtk_binding_entry_add_signal (binding_set, GDK_Insert, 0,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
"toggle-overwrite", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, 0,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
"toggle-overwrite", 0);
/**
P_("Inner Border"),
P_("Border between text and frame."),
GTK_TYPE_BORDER,
- GTK_PARAM_READABLE));
-
- /**
- * GtkEntry:state-hint:
- *
- * Indicates whether to pass a proper widget state when
- * drawing the shadow and the widget background.
- *
- * Since: 2.16
- */
- gtk_widget_class_install_style_property (widget_class,
- g_param_spec_boolean ("state-hint",
- P_("State Hint"),
- P_("Whether to pass a proper state when drawing shadow or background"),
- FALSE,
- GTK_PARAM_READABLE));
-
- gtk_settings_install_property (g_param_spec_boolean ("gtk-entry-select-on-focus",
- P_("Select on focus"),
- P_("Whether to select the contents of an entry when it is focused"),
- TRUE,
- GTK_PARAM_READWRITE));
-
- /**
- * GtkSettings:gtk-entry-password-hint-timeout:
- *
- * How long to show the last input character in hidden
- * entries. This value is in milliseconds. 0 disables showing the
- * last char. 600 is a good value for enabling it.
- *
- * Since: 2.10
- */
- gtk_settings_install_property (g_param_spec_uint ("gtk-entry-password-hint-timeout",
- P_("Password Hint Timeout"),
- P_("How long to show the last input character in hidden entries"),
- 0, G_MAXUINT, 0,
- GTK_PARAM_READWRITE));
+ GTK_PARAM_READABLE));
g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
}
static void
-gtk_entry_editable_init (GtkEditableClass *iface)
+gtk_entry_editable_init (GtkEditableInterface *iface)
{
iface->do_insert_text = gtk_entry_insert_text;
iface->do_delete_text = gtk_entry_delete_text;
{
GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
GtkEntry *entry = GTK_ENTRY (object);
+ GtkWidget *widget;
switch (prop_id)
{
if (new_value != entry->editable)
{
+ widget = GTK_WIDGET (entry);
if (!new_value)
{
_gtk_entry_reset_im_context (entry);
- if (GTK_WIDGET_HAS_FOCUS (entry))
+ if (gtk_widget_has_focus (widget))
gtk_im_context_focus_out (entry->im_context);
entry->preedit_length = 0;
entry->editable = new_value;
- if (new_value && GTK_WIDGET_HAS_FOCUS (entry))
+ if (new_value && gtk_widget_has_focus (widget))
gtk_im_context_focus_in (entry->im_context);
gtk_entry_queue_draw (entry);
case PROP_IM_MODULE:
g_free (priv->im_module);
- priv->im_module = g_strdup (g_value_get_string (value));
+ priv->im_module = g_value_dup_string (value);
if (GTK_IS_IM_MULTICONTEXT (entry->im_context))
gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module);
break;
+ case PROP_EDITING_CANCELED:
+ entry->editing_canceled = g_value_get_boolean (value);
+ break;
+
case PROP_SCROLL_OFFSET:
case PROP_CURSOR_POSITION:
default:
gtk_entry_get_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY));
break;
+ case PROP_EDITING_CANCELED:
+ g_value_set_boolean (value,
+ entry->editing_canceled);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
0x273a /* SIXTEEN POINTED ASTERISK */
};
- if (widget->style)
+ if (gtk_widget_get_style (widget))
gtk_widget_style_get (widget,
"invisible-char", &invisible_chars[0],
NULL);
{
GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
- GTK_WIDGET_SET_FLAGS (entry, GTK_CAN_FOCUS);
+ gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
+ gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
entry->editable = TRUE;
entry->visible = TRUE;
get_text_area_size (entry, &x, &y, &width, &height);
- if (GTK_WIDGET_HAS_FOCUS (entry) && !priv->interior_focus)
+ if (gtk_widget_has_focus (GTK_WIDGET (entry)) && !priv->interior_focus)
y += priv->focus_width;
primary->y = y;
}
static void
-gtk_entry_destroy (GtkObject *object)
+gtk_entry_destroy (GtkWidget *widget)
{
- GtkEntry *entry = GTK_ENTRY (object);
+ GtkEntry *entry = GTK_ENTRY (widget);
entry->current_pos = entry->selection_bound = 0;
_gtk_entry_reset_im_context (entry);
entry->recompute_idle = 0;
}
- GTK_OBJECT_CLASS (gtk_entry_parent_class)->destroy (object);
+ GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
}
static void
gtk_entry_dispose (GObject *object)
{
GtkEntry *entry = GTK_ENTRY (object);
+ GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
+ if (priv->buffer)
+ {
+ buffer_disconnect_signals (entry);
+ g_object_unref (priv->buffer);
+ priv->buffer = NULL;
+ }
+
G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
}
g_free (priv->im_module);
- /* COMPAT: entry->text is a deprecated field, and the allocation
- is owned by the buffer. */
-
- gtk_entry_set_buffer (entry, NULL);
-
G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
}
* here is that for the entry, insensitive => arrow cursor, but for
* an icon in a sensitive entry, insensitive => xterm cursor.
*/
- if (GTK_WIDGET_IS_SENSITIVE (widget) &&
+ if (gtk_widget_is_sensitive (widget) &&
(icon_info->insensitive ||
(icon_info->nonactivatable && icon_info->target_list == NULL)))
{
attributes.width = 1;
attributes.height = 1;
attributes.window_type = GDK_WINDOW_CHILD;
- attributes.wclass = GDK_INPUT_OUTPUT;
- attributes.visual = gtk_widget_get_visual (widget);
- attributes.colormap = gtk_widget_get_colormap (widget);
+ attributes.wclass = GDK_INPUT_ONLY;
attributes.event_mask = gtk_widget_get_events (widget);
- attributes.event_mask |= (GDK_EXPOSURE_MASK |
- GDK_BUTTON_PRESS_MASK |
+ attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON3_MOTION_MASK |
GDK_POINTER_MOTION_MASK |
GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK);
- attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+ attributes_mask = GDK_WA_X | GDK_WA_Y;
- icon_info->window = gdk_window_new (widget->window,
+ icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
&attributes,
attributes_mask);
gdk_window_set_user_data (icon_info->window, widget);
- gdk_window_set_background (icon_info->window,
- &widget->style->base[GTK_WIDGET_STATE (widget)]);
gtk_widget_queue_resize (widget);
}
icon_info = g_slice_new0 (EntryIconInfo);
priv->icons[icon_pos] = icon_info;
- if (GTK_WIDGET_REALIZED (widget))
+ if (gtk_widget_get_realized (widget))
realize_icon_info (widget, icon_pos);
return icon_info;
EntryIconInfo *icon_info = NULL;
gint i;
- if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_MAPPED (widget))
- {
- GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
+ GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
- for (i = 0; i < MAX_ICONS; i++)
+ for (i = 0; i < MAX_ICONS; i++)
+ {
+ if ((icon_info = priv->icons[i]) != NULL)
{
- if ((icon_info = priv->icons[i]) != NULL)
- {
- if (icon_info->pixbuf != NULL && icon_info->window != NULL)
- gdk_window_show (icon_info->window);
- }
+ if (icon_info->pixbuf != NULL && icon_info->window != NULL)
+ gdk_window_show (icon_info->window);
}
-
- update_cursors (widget);
}
+
+ update_cursors (widget);
}
static void
EntryIconInfo *icon_info = NULL;
gint i;
- if (GTK_WIDGET_MAPPED (widget))
+ for (i = 0; i < MAX_ICONS; i++)
{
- for (i = 0; i < MAX_ICONS; i++)
+ if ((icon_info = priv->icons[i]) != NULL)
{
- if ((icon_info = priv->icons[i]) != NULL)
- {
- if (icon_info->pixbuf != NULL && icon_info->window != NULL)
- gdk_window_hide (icon_info->window);
- }
+ if (icon_info->pixbuf != NULL && icon_info->window != NULL)
+ gdk_window_hide (icon_info->window);
}
-
- GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
}
+
+ GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
}
static void
GtkEntry *entry;
GtkEntryPrivate *priv;
EntryIconInfo *icon_info;
+ GdkWindow *window;
GdkWindowAttr attributes;
gint attributes_mask;
+ gint frame_x, frame_y;
int i;
- GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+ gtk_widget_set_realized (widget, TRUE);
+ window = gtk_widget_get_parent_window (widget);
+ gtk_widget_set_window (widget, window);
+ g_object_ref (window);
+
entry = GTK_ENTRY (widget);
priv = GTK_ENTRY_GET_PRIVATE (entry);
attributes.window_type = GDK_WINDOW_CHILD;
-
- get_widget_window_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
-
- attributes.wclass = GDK_INPUT_OUTPUT;
- attributes.visual = gtk_widget_get_visual (widget);
- attributes.colormap = gtk_widget_get_colormap (widget);
+ attributes.wclass = GDK_INPUT_ONLY;
attributes.event_mask = gtk_widget_get_events (widget);
- attributes.event_mask |= (GDK_EXPOSURE_MASK |
- GDK_BUTTON_PRESS_MASK |
+ attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON3_MOTION_MASK |
GDK_POINTER_MOTION_MASK |
GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK);
- attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
-
- widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
- gdk_window_set_user_data (widget->window, entry);
+ attributes_mask = GDK_WA_X | GDK_WA_Y;
get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
-
- if (GTK_WIDGET_IS_SENSITIVE (widget))
+
+ get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
+ attributes.x += frame_x;
+ attributes.y += frame_y;
+
+ if (gtk_widget_is_sensitive (widget))
{
attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
attributes_mask |= GDK_WA_CURSOR;
}
- entry->text_area = gdk_window_new (widget->window, &attributes, attributes_mask);
+ entry->text_area = gdk_window_new (gtk_widget_get_window (widget),
+ &attributes,
+ attributes_mask);
gdk_window_set_user_data (entry->text_area, entry);
if (attributes_mask & GDK_WA_CURSOR)
gdk_cursor_unref (attributes.cursor);
- widget->style = gtk_style_attach (widget->style, widget->window);
-
- gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
- gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
+ gtk_widget_style_attach (widget);
gdk_window_show (entry->text_area);
{
GtkWidget *widget = GTK_WIDGET (entry);
GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
+ GtkStyle *style;
if (entry->has_frame)
{
- *xborder = widget->style->xthickness;
- *yborder = widget->style->ythickness;
+ style = gtk_widget_get_style (widget);
+
+ *xborder = style->xthickness;
+ *yborder = style->ythickness;
}
else
{
}
static void
-gtk_entry_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
+gtk_entry_get_preferred_width (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
{
GtkEntry *entry = GTK_ENTRY (widget);
GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
gint xborder, yborder;
GtkBorder inner_border;
PangoContext *context;
- int icon_widths = 0;
- int icon_width, i;
-
+ gint icon_widths = 0;
+ gint icon_width, i;
+ gint width;
+
gtk_widget_ensure_style (widget);
context = gtk_widget_get_pango_context (widget);
metrics = pango_context_get_metrics (context,
- widget->style->font_desc,
- pango_context_get_language (context));
+ gtk_widget_get_style (widget)->font_desc,
+ pango_context_get_language (context));
- entry->ascent = pango_font_metrics_get_ascent (metrics);
- entry->descent = pango_font_metrics_get_descent (metrics);
-
_gtk_entry_get_borders (entry, &xborder, &yborder);
_gtk_entry_effective_inner_border (entry, &inner_border);
if (entry->width_chars < 0)
- requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
+ width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
else
{
gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
-
- requisition->width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
+
+ width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
}
-
- requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
for (i = 0; i < MAX_ICONS; i++)
{
icon_widths += icon_width + 2 * priv->icon_margin;
}
- if (icon_widths > requisition->width)
- requisition->width += icon_widths;
+ if (icon_widths > width)
+ width += icon_widths;
pango_font_metrics_unref (metrics);
+
+ *minimum = width;
+ *natural = width;
+}
+
+static void
+gtk_entry_get_preferred_height (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
+{
+ GtkEntry *entry = GTK_ENTRY (widget);
+ PangoFontMetrics *metrics;
+ gint xborder, yborder;
+ GtkBorder inner_border;
+ PangoContext *context;
+ gint height;
+
+ gtk_widget_ensure_style (widget);
+ context = gtk_widget_get_pango_context (widget);
+ metrics = pango_context_get_metrics (context,
+ gtk_widget_get_style (widget)->font_desc,
+ pango_context_get_language (context));
+
+ entry->ascent = pango_font_metrics_get_ascent (metrics);
+ entry->descent = pango_font_metrics_get_descent (metrics);
+
+ _gtk_entry_get_borders (entry, &xborder, &yborder);
+ _gtk_entry_effective_inner_border (entry, &inner_border);
+
+ height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
+
+ pango_font_metrics_unref (metrics);
+
+ *minimum = height;
+ *natural = height;
}
static void
place_windows (GtkEntry *entry)
{
+ GtkWidget *widget = GTK_WIDGET (entry);
GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
gint x, y, width, height;
+ gint frame_x, frame_y;
GtkAllocation primary;
GtkAllocation secondary;
EntryIconInfo *icon_info = NULL;
+ get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
get_text_area_size (entry, &x, &y, &width, &height);
get_icon_allocations (entry, &primary, &secondary);
- if (GTK_WIDGET_HAS_FOCUS (entry) && !priv->interior_focus)
+ if (gtk_widget_has_focus (widget) && !priv->interior_focus)
y += priv->focus_width;
- if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
+ if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
x += secondary.width;
else
x += primary.width;
width -= primary.width + secondary.width;
+ x += frame_x;
+ y += frame_y;
+ primary.x += frame_x;
+ primary.y += frame_y;
+ secondary.x += frame_x;
+ secondary.y += frame_y;
+
if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
gdk_window_move_resize (icon_info->window,
primary.x, primary.y,
secondary.x, secondary.y,
secondary.width, secondary.height);
- gdk_window_move_resize (GTK_ENTRY (entry)->text_area, x, y, width, height);
+ gdk_window_move_resize (entry->text_area, x, y, width, height);
}
static void
{
GtkWidget *widget = GTK_WIDGET (entry);
GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
+ GtkAllocation allocation;
+ GtkRequisition requisition;
gint frame_height;
gint xborder, yborder;
- GtkRequisition requisition;
- gtk_widget_get_child_requisition (widget, &requisition);
+ gtk_widget_get_preferred_size (widget, &requisition, NULL);
+ gtk_widget_get_allocation (widget, &allocation);
_gtk_entry_get_borders (entry, &xborder, &yborder);
- if (GTK_WIDGET_REALIZED (widget))
- gdk_drawable_get_size (widget->window, NULL, &frame_height);
+ if (gtk_widget_get_realized (widget))
+ get_frame_size (entry, NULL, NULL, NULL, &frame_height);
else
frame_height = requisition.height;
- if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
+ if (gtk_widget_has_focus (widget) && !priv->interior_focus)
frame_height -= 2 * priv->focus_width;
if (x)
*y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
if (width)
- *width = GTK_WIDGET (entry)->allocation.width - xborder * 2;
+ *width = allocation.width - xborder * 2;
if (height)
*height = requisition.height - yborder * 2;
static void
-get_widget_window_size (GtkEntry *entry,
- gint *x,
- gint *y,
- gint *width,
- gint *height)
+get_frame_size (GtkEntry *entry,
+ gint *x,
+ gint *y,
+ gint *width,
+ gint *height)
{
+ GtkAllocation allocation;
GtkRequisition requisition;
GtkWidget *widget = GTK_WIDGET (entry);
-
- gtk_widget_get_child_requisition (widget, &requisition);
+
+ gtk_widget_get_preferred_size (widget, &requisition, NULL);
+ gtk_widget_get_allocation (widget, &allocation);
if (x)
- *x = widget->allocation.x;
+ *x = allocation.x;
if (y)
{
if (entry->is_cell_renderer)
- *y = widget->allocation.y;
+ *y = allocation.y;
else
- *y = widget->allocation.y + (widget->allocation.height - requisition.height) / 2;
+ *y = allocation.y + (allocation.height - requisition.height) / 2;
}
if (width)
- *width = widget->allocation.width;
+ *width = allocation.width;
if (height)
{
if (entry->is_cell_renderer)
- *height = widget->allocation.height;
+ *height = allocation.height;
else
*height = requisition.height;
}
GtkAllocation *allocation)
{
GtkEntry *entry = GTK_ENTRY (widget);
-
- widget->allocation = *allocation;
-
- if (GTK_WIDGET_REALIZED (widget))
+
+ gtk_widget_set_allocation (widget, allocation);
+
+ if (gtk_widget_get_realized (widget))
{
- /* We call gtk_widget_get_child_requisition, since we want (for
- * backwards compatibility reasons) the realization here to
- * be affected by the usize of the entry, if set
- */
- gint x, y, width, height;
GtkEntryCompletion* completion;
- get_widget_window_size (entry, &x, &y, &width, &height);
- gdk_window_move_resize (widget->window, x, y, width, height);
-
place_windows (entry);
gtk_entry_recompute (entry);
completion = gtk_entry_get_completion (entry);
- if (completion && GTK_WIDGET_MAPPED (completion->priv->popup_window))
+ if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
_gtk_entry_completion_resize_popup (completion);
}
}
static void
draw_icon (GtkWidget *widget,
+ cairo_t *cr,
GtkEntryIconPosition icon_pos)
{
GtkEntry *entry = GTK_ENTRY (widget);
if (icon_info->pixbuf == NULL)
return;
- gdk_drawable_get_size (icon_info->window, &width, &height);
+ width = gdk_window_get_width (icon_info->window);
+ height = gdk_window_get_height (icon_info->window);
/* size_allocate hasn't been called yet. These are the default values.
*/
x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
- if (!GTK_WIDGET_IS_SENSITIVE (widget) ||
+ if (!gtk_widget_is_sensitive (widget) ||
icon_info->insensitive)
{
GdkPixbuf *temp_pixbuf;
pixbuf = temp_pixbuf;
}
- gdk_draw_pixbuf (icon_info->window, widget->style->black_gc, pixbuf,
- 0, 0, x, y, -1, -1,
- GDK_RGB_DITHER_NORMAL, 0, 0);
+ gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
+ cairo_paint (cr);
g_object_unref (pixbuf);
}
static void
gtk_entry_draw_frame (GtkWidget *widget,
- GdkEventExpose *event)
+ cairo_t *cr)
{
GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
+ GtkStyle *style;
+ GdkWindow *window;
gint x = 0, y = 0, width, height;
- gboolean state_hint;
GtkStateType state;
+ GtkAllocation allocation;
+ gint frame_x, frame_y;
+
+ cairo_save (cr);
+
+ window = gtk_widget_get_window (widget);
+
+ get_frame_size (GTK_ENTRY (widget), &frame_x, &frame_y, &width, &height);
+ gtk_widget_get_allocation (widget, &allocation);
- gdk_drawable_get_size (widget->window, &width, &height);
+ cairo_translate (cr, frame_x - allocation.x, frame_y - allocation.y);
/* Fix a problem with some themes which assume that entry->text_area's
- * width equals widget->window's width */
+ * width equals widget->window's width
+ * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
if (GTK_IS_SPIN_BUTTON (widget))
{
gint xborder, yborder;
width += xborder * 2;
}
- if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
+ if (gtk_widget_has_focus (widget) && !priv->interior_focus)
{
x += priv->focus_width;
y += priv->focus_width;
height -= 2 * priv->focus_width;
}
- gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
- if (state_hint)
- state = GTK_WIDGET_HAS_FOCUS (widget) ?
- GTK_STATE_ACTIVE : GTK_WIDGET_STATE (widget);
- else
- state = GTK_STATE_NORMAL;
+ style = gtk_widget_get_style (widget);
+ state = gtk_widget_has_focus (widget) ?
+ GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
- gtk_paint_shadow (widget->style, widget->window,
- state, priv->shadow_type,
- &event->area, widget, "entry", x, y, width, height);
+ gtk_paint_flat_box (style, cr,
+ state, GTK_SHADOW_NONE,
+ widget, "entry_bg",
+ x, y, width, height);
+ if (GTK_ENTRY (widget)->has_frame)
+ gtk_paint_shadow (style, cr,
+ state, priv->shadow_type,
+ widget, "entry", x, y, width, height);
- gtk_entry_draw_progress (widget, event);
+ gtk_entry_draw_progress (widget, cr);
- if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
+ if (gtk_widget_has_focus (widget) && !priv->interior_focus)
{
x -= priv->focus_width;
y -= priv->focus_width;
width += 2 * priv->focus_width;
height += 2 * priv->focus_width;
-
- gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
- &event->area, widget, "entry",
+
+ gtk_paint_focus (style, cr,
+ gtk_widget_get_state (widget),
+ widget, "entry",
0, 0, width, height);
}
-}
-static void
-gtk_entry_get_progress_border (GtkWidget *widget,
- GtkBorder *progress_border)
-{
- GtkBorder *tmp_border;
-
- gtk_widget_style_get (widget, "progress-border", &tmp_border, NULL);
- if (tmp_border)
- {
- *progress_border = *tmp_border;
- gtk_border_free (tmp_border);
- }
- else
- {
- progress_border->left = widget->style->xthickness;
- progress_border->right = widget->style->xthickness;
- progress_border->top = widget->style->ythickness;
- progress_border->bottom = widget->style->ythickness;
- }
+ cairo_restore (cr);
}
static void
get_progress_area (GtkWidget *widget,
- gint *x,
- gint *y,
- gint *width,
- gint *height)
+ gint *x,
+ gint *y,
+ gint *width,
+ gint *height)
{
GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
GtkEntry *entry = GTK_ENTRY (widget);
- GtkBorder progress_border;
+ GtkBorder *progress_border;
- gtk_entry_get_progress_border (widget, &progress_border);
+ get_text_area_size (entry, x, y, width, height);
- *x = progress_border.left;
- *y = progress_border.top;
-
- gdk_drawable_get_size (widget->window, width, height);
+ if (!private->interior_focus)
+ {
+ *x -= private->focus_width;
+ *y -= private->focus_width;
+ *width += 2 * private->focus_width;
+ *height += 2 * private->focus_width;
+ }
- *width -= progress_border.left + progress_border.right;
- *height -= progress_border.top + progress_border.bottom;
+ gtk_widget_style_get (widget, "progress-border", &progress_border, NULL);
- if (GTK_WIDGET_HAS_FOCUS (widget) && !private->interior_focus)
+ if (progress_border)
{
- *x += private->focus_width;
- *y += private->focus_width;
- *width -= 2 * private->focus_width;
- *height -= 2 * private->focus_width;
+ *x += progress_border->left;
+ *y += progress_border->top;
+ *width -= progress_border->left + progress_border->right;
+ *height -= progress_border->top + progress_border->bottom;
+
+ gtk_border_free (progress_border);
}
if (private->progress_pulse_mode)
static void
gtk_entry_draw_progress (GtkWidget *widget,
- GdkEventExpose *event)
+ cairo_t *cr)
{
gint x, y, width, height;
GtkStateType state;
if ((width <= 0) || (height <= 0))
return;
- if (event->window != widget->window)
- {
- gint pos_x, pos_y;
-
- gdk_window_get_position (event->window, &pos_x, &pos_y);
-
- x -= pos_x;
- y -= pos_y;
- }
-
state = GTK_STATE_SELECTED;
- if (!GTK_WIDGET_SENSITIVE (widget))
+ if (!gtk_widget_get_sensitive (widget))
state = GTK_STATE_INSENSITIVE;
- gtk_paint_box (widget->style, event->window,
+ gtk_paint_box (gtk_widget_get_style (widget), cr,
state, GTK_SHADOW_OUT,
- &event->area, widget, "entry-progress",
+ widget, "entry-progress",
x, y,
width, height);
}
static gint
-gtk_entry_expose (GtkWidget *widget,
- GdkEventExpose *event)
+gtk_entry_draw (GtkWidget *widget,
+ cairo_t *cr)
{
GtkEntry *entry = GTK_ENTRY (widget);
- gboolean state_hint;
+ GtkStyle *style;
GtkStateType state;
GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+ int i;
- gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
- if (state_hint)
- state = GTK_WIDGET_HAS_FOCUS (widget) ?
- GTK_STATE_ACTIVE : GTK_WIDGET_STATE (widget);
- else
- state = GTK_WIDGET_STATE(widget);
+ style = gtk_widget_get_style (widget);
- if (widget->window == event->window)
- {
- gtk_entry_draw_frame (widget, event);
- }
- else if (entry->text_area == event->window)
- {
- gint width, height;
+ state = gtk_widget_has_focus (widget) ?
+ GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
- gdk_drawable_get_size (entry->text_area, &width, &height);
+ if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
+ {
+ /* Draw entry_bg, shadow, progress and focus */
+ gtk_entry_draw_frame (widget, cr);
- gtk_paint_flat_box (widget->style, entry->text_area,
- state, GTK_SHADOW_NONE,
- &event->area, widget, "entry_bg",
- 0, 0, width, height);
+ /* Draw text and cursor */
+ cairo_save (cr);
- gtk_entry_draw_progress (widget, event);
+ gtk_cairo_transform_to_window (cr, widget, entry->text_area);
if (entry->dnd_position != -1)
- gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_DND);
+ gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
- gtk_entry_draw_text (GTK_ENTRY (widget));
+ gtk_entry_draw_text (GTK_ENTRY (widget), cr);
/* When no text is being displayed at all, don't show the cursor */
if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
- GTK_WIDGET_HAS_FOCUS (widget) &&
- entry->selection_bound == entry->current_pos && entry->cursor_visible)
- gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_STANDARD);
- }
- else
- {
- int i;
+ gtk_widget_has_focus (widget) &&
+ entry->selection_bound == entry->current_pos && entry->cursor_visible)
+ gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
+
+ cairo_restore (cr);
+ /* Draw icons */
for (i = 0; i < MAX_ICONS; i++)
{
EntryIconInfo *icon_info = priv->icons[i];
- if (icon_info != NULL && event->window == icon_info->window)
+ if (icon_info != NULL)
{
- gint width, height;
+ cairo_save (cr);
- gdk_drawable_get_size (icon_info->window, &width, &height);
+ gtk_cairo_transform_to_window (cr, widget, icon_info->window);
- gtk_paint_flat_box (widget->style, icon_info->window,
- GTK_WIDGET_STATE (widget), GTK_SHADOW_NONE,
- NULL, widget, "entry_bg",
- 0, 0, width, height);
+ draw_icon (widget, cr, i);
- gtk_entry_draw_progress (widget, event);
- draw_icon (widget, i);
-
- break;
+ cairo_restore (cr);
}
}
}
entry->button = event->button;
- if (!GTK_WIDGET_HAS_FOCUS (widget))
+ if (!gtk_widget_has_focus (widget))
{
entry->in_click = TRUE;
gtk_widget_grab_focus (widget);
if (event->window == icon_info->window)
{
- gint width, height;
-
- gdk_drawable_get_size (icon_info->window, &width, &height);
-
icon_info->pressed = FALSE;
if (should_prelight (entry, i) &&
event->x >= 0 && event->y >= 0 &&
- event->x < width && event->y < height)
+ event->x < gdk_window_get_width (icon_info->window) &&
+ event->y < gdk_window_get_height (icon_info->window))
{
icon_info->prelight = TRUE;
gtk_widget_queue_draw (widget);
GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
gchar *text = NULL;
- GdkPixmap *pixmap = NULL;
+ cairo_surface_t *surface;
gtk_target_list_add_text_targets (target_list, 0);
text = _gtk_entry_get_selected_text (entry);
- pixmap = _gtk_text_util_create_drag_icon (widget, text, -1);
+ surface = _gtk_text_util_create_drag_icon (widget, text, -1);
context = gtk_drag_begin (widget, target_list, actions,
entry->button, (GdkEvent *)event);
- if (pixmap)
- gtk_drag_set_icon_pixmap (context,
- gdk_drawable_get_colormap (pixmap),
- pixmap,
- NULL,
- -2, -2);
+ if (surface)
+ gtk_drag_set_icon_surface (context, surface);
else
gtk_drag_set_icon_default (context);
- if (pixmap)
- g_object_unref (pixmap);
+ if (surface)
+ cairo_surface_destroy (surface);
g_free (text);
entry->in_drag = FALSE;
}
else
{
- gint height;
- gdk_drawable_get_size (entry->text_area, NULL, &height);
-
if (event->y < 0)
tmp_pos = 0;
- else if (event->y >= height)
+ else if (event->y >= gdk_window_get_height (entry->text_area))
tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
else
tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
GdkDisplay *display;
GdkCursor *cursor;
- display = gdk_drawable_get_display (window);
+ display = gdk_window_get_display (window);
cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
gdk_window_set_cursor (window, cursor);
}
}
- if (event->keyval == GDK_Return ||
- event->keyval == GDK_KP_Enter ||
- event->keyval == GDK_ISO_Enter ||
- event->keyval == GDK_Escape)
+ if (event->keyval == GDK_KEY_Return ||
+ event->keyval == GDK_KEY_KP_Enter ||
+ event->keyval == GDK_KEY_ISO_Enter ||
+ event->keyval == GDK_KEY_Escape)
{
GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
GtkStateType previous_state)
{
GtkEntry *entry = GTK_ENTRY (widget);
- GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
GdkCursor *cursor;
- gint i;
- if (GTK_WIDGET_REALIZED (widget))
+ if (gtk_widget_get_realized (widget))
{
- gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
- gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
- for (i = 0; i < MAX_ICONS; i++)
- {
- EntryIconInfo *icon_info = priv->icons[i];
- if (icon_info && icon_info->window)
- gdk_window_set_background (icon_info->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
- }
-
- if (GTK_WIDGET_IS_SENSITIVE (widget))
+ if (gtk_widget_is_sensitive (widget))
cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
else
cursor = NULL;
update_cursors (widget);
}
- if (!GTK_WIDGET_IS_SENSITIVE (widget))
+ if (!gtk_widget_is_sensitive (widget))
{
/* Clear any selection */
gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
start_pos = MIN (text_length, start_pos);
end_pos = MIN (text_length, end_pos);
- start_index = g_utf8_offset_to_pointer (text, start_pos) - entry->text;
- end_index = g_utf8_offset_to_pointer (text, end_pos) - entry->text;
+ start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
+ end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
return g_strndup (text + start_index, end_index - start_index);
}
GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
gint focus_width;
gboolean interior_focus;
- gint i;
gtk_widget_style_get (widget,
"focus-line-width", &focus_width,
gtk_entry_recompute (entry);
- if (previous_style && GTK_WIDGET_REALIZED (widget))
- {
- gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
- gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
- for (i = 0; i < MAX_ICONS; i++)
- {
- EntryIconInfo *icon_info = priv->icons[i];
- if (icon_info && icon_info->window)
- gdk_window_set_background (icon_info->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
- }
- }
-
icon_theme_changed (entry);
icon_margin_changed (entry);
}
GdkEventKey *key_event,
gpointer data)
{
- if (key_event->keyval == GDK_Escape)
+ if (key_event->keyval == GDK_KEY_Escape)
{
entry->editing_canceled = TRUE;
gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
}
/* override focus */
- if (key_event->keyval == GDK_Up || key_event->keyval == GDK_Down)
+ if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
{
gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
* following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
* buffer_notify_text(), buffer_notify_length()
*/
- n_inserted = gtk_entry_buffer_insert_text (GTK_ENTRY_GET_PRIVATE (editable)->buffer, *position, new_text, n_chars);
+ n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
if (n_inserted != n_chars)
gtk_widget_error_bell (GTK_WIDGET (editable));
GParamSpec *spec,
GtkEntry *entry)
{
- /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
- entry->text = (gchar*)gtk_entry_buffer_get_text (buffer);
-
gtk_entry_recompute (entry);
emit_changed (entry);
g_object_notify (G_OBJECT (entry), "text");
GParamSpec *spec,
GtkEntry *entry)
{
- /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
- entry->text_length = gtk_entry_buffer_get_length (buffer);
-
g_object_notify (G_OBJECT (entry), "text-length");
}
GParamSpec *spec,
GtkEntry *entry)
{
- /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
- entry->text_max_length = gtk_entry_buffer_get_max_length (buffer);
-
g_object_notify (G_OBJECT (entry), "max-length");
}
gtk_entry_real_activate (GtkEntry *entry)
{
GtkWindow *window;
+ GtkWidget *default_widget, *focus_widget;
GtkWidget *toplevel;
GtkWidget *widget;
if (GTK_IS_WINDOW (toplevel))
{
window = GTK_WINDOW (toplevel);
-
- if (window &&
- widget != window->default_widget &&
- !(widget == window->focus_widget &&
- (!window->default_widget || !GTK_WIDGET_SENSITIVE (window->default_widget))))
- gtk_window_activate_default (window);
+
+ if (window)
+ {
+ default_widget = gtk_window_get_default_widget (window);
+ focus_widget = gtk_window_get_focus (window);
+ if (widget != default_widget &&
+ !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
+ gtk_window_activate_default (window);
+ }
}
}
}
gtk_im_context_get_preedit_string (entry->im_context,
&preedit_string, NULL,
&cursor_pos);
+ g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
entry->preedit_length = strlen (preedit_string);
cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
entry->preedit_cursor = cursor_pos;
if (pango_dir == PANGO_DIRECTION_NEUTRAL)
{
- if (GTK_WIDGET_HAS_FOCUS (widget))
+ if (gtk_widget_has_focus (widget))
{
GdkDisplay *display = gtk_widget_get_display (widget);
GdkKeymap *keymap = gdk_keymap_get_for_display (display);
PangoRectangle logical_rect;
GdkColor *selection_color, *text_color;
GtkBorder inner_border;
+ GtkStyle *style;
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
- if (GTK_WIDGET_HAS_FOCUS (entry))
+ style = gtk_widget_get_style (widget);
+
+ if (gtk_widget_has_focus (widget))
{
- selection_color = &widget->style->base [GTK_STATE_SELECTED];
- text_color = &widget->style->text [GTK_STATE_SELECTED];
+ selection_color = &style->base [GTK_STATE_SELECTED];
+ text_color = &style->text [GTK_STATE_SELECTED];
}
else
{
- selection_color = &widget->style->base [GTK_STATE_ACTIVE];
- text_color = &widget->style->text [GTK_STATE_ACTIVE];
+ selection_color = &style->base [GTK_STATE_ACTIVE];
+ text_color = &style->text [GTK_STATE_ACTIVE];
}
_gtk_entry_effective_inner_border (entry, &inner_border);
}
static void
-gtk_entry_draw_text (GtkEntry *entry)
+gtk_entry_draw_text (GtkEntry *entry,
+ cairo_t *cr)
{
GtkWidget *widget = GTK_WIDGET (entry);
- cairo_t *cr;
+ GtkStateType state;
+ GtkStyle *style;
+ GdkColor text_color, bar_text_color;
+ gint pos_x, pos_y;
+ gint width, height;
+ gint progress_x, progress_y, progress_width, progress_height;
+ gint clip_width, clip_height;
/* Nothing to display at all */
if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
return;
- if (GTK_WIDGET_DRAWABLE (entry))
- {
- GdkColor text_color, bar_text_color;
- gint pos_x, pos_y;
- gint width, height;
- gint progress_x, progress_y, progress_width, progress_height;
- GtkStateType state;
-
- state = GTK_STATE_SELECTED;
- if (!GTK_WIDGET_SENSITIVE (widget))
- state = GTK_STATE_INSENSITIVE;
- text_color = widget->style->text[widget->state];
- bar_text_color = widget->style->fg[state];
-
- get_progress_area (widget,
- &progress_x, &progress_y,
- &progress_width, &progress_height);
-
- cr = gdk_cairo_create (entry->text_area);
-
- /* If the color is the same, or the progress area has a zero
- * size, then we only need to draw once. */
- if ((text_color.pixel == bar_text_color.pixel) ||
- ((progress_width == 0) || (progress_height == 0)))
- {
- draw_text_with_color (entry, cr, &text_color);
- }
- else
- {
- gdk_drawable_get_size (entry->text_area, &width, &height);
+ state = GTK_STATE_SELECTED;
+ if (!gtk_widget_get_sensitive (widget))
+ state = GTK_STATE_INSENSITIVE;
+ style = gtk_widget_get_style (widget);
+ text_color = style->text[gtk_widget_get_state (widget)];
+ bar_text_color = style->fg[state];
- cairo_rectangle (cr, 0, 0, width, height);
- cairo_clip (cr);
- cairo_save (cr);
+ get_progress_area (widget,
+ &progress_x, &progress_y,
+ &progress_width, &progress_height);
- cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
- cairo_rectangle (cr, 0, 0, width, height);
+ clip_width = gdk_window_get_width (entry->text_area);
+ clip_height = gdk_window_get_height (entry->text_area);
+ cairo_rectangle (cr, 0, 0, clip_width, clip_height);
+ cairo_clip (cr);
- gdk_window_get_position (entry->text_area, &pos_x, &pos_y);
- progress_x -= pos_x;
- progress_y -= pos_y;
+ /* If the color is the same, or the progress area has a zero
+ * size, then we only need to draw once. */
+ if ((text_color.pixel == bar_text_color.pixel) ||
+ ((progress_width == 0) || (progress_height == 0)))
+ {
+ draw_text_with_color (entry, cr, &text_color);
+ }
+ else
+ {
+ width = gdk_window_get_width (entry->text_area);
+ height = gdk_window_get_height (entry->text_area);
- cairo_rectangle (cr, progress_x, progress_y,
- progress_width, progress_height);
- cairo_clip (cr);
- cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
-
- draw_text_with_color (entry, cr, &text_color);
- cairo_restore (cr);
+ cairo_save (cr);
- cairo_rectangle (cr, progress_x, progress_y,
- progress_width, progress_height);
- cairo_clip (cr);
+ cairo_rectangle (cr, 0, 0, width, height);
+ cairo_clip (cr);
+ cairo_save (cr);
- draw_text_with_color (entry, cr, &bar_text_color);
- }
+ cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
+ cairo_rectangle (cr, 0, 0, width, height);
+
+ gdk_window_get_position (entry->text_area, &pos_x, &pos_y);
+ progress_x -= pos_x;
+ progress_y -= pos_y;
+
+ cairo_rectangle (cr, progress_x, progress_y,
+ progress_width, progress_height);
+ cairo_clip (cr);
+ cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
+
+ draw_text_with_color (entry, cr, &text_color);
+ cairo_restore (cr);
+
+ cairo_rectangle (cr, progress_x, progress_y,
+ progress_width, progress_height);
+ cairo_clip (cr);
- cairo_destroy (cr);
+ draw_text_with_color (entry, cr, &bar_text_color);
+
+ cairo_restore (cr);
}
}
static void
draw_insertion_cursor (GtkEntry *entry,
+ cairo_t *cr,
GdkRectangle *cursor_location,
gboolean is_primary,
PangoDirection direction,
else
text_dir = GTK_TEXT_DIR_RTL;
- gtk_draw_insertion_cursor (widget, entry->text_area, NULL,
+ gtk_draw_insertion_cursor (widget, cr,
cursor_location,
is_primary, text_dir, draw_arrow);
}
static void
gtk_entry_draw_cursor (GtkEntry *entry,
+ cairo_t *cr,
CursorType type)
{
+ GtkWidget *widget = GTK_WIDGET (entry);
GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
-
- if (GTK_WIDGET_DRAWABLE (entry))
- {
- GtkWidget *widget = GTK_WIDGET (entry);
- GdkRectangle cursor_location;
- gboolean split_cursor;
- PangoRectangle cursor_rect;
- GtkBorder inner_border;
- gint xoffset;
- gint text_area_height;
- gint cursor_index;
- gboolean block;
- gboolean block_at_line_end;
- PangoLayout *layout;
- const char *text;
-
- _gtk_entry_effective_inner_border (entry, &inner_border);
-
- xoffset = inner_border.left - entry->scroll_offset;
+ GdkRectangle cursor_location;
+ gboolean split_cursor;
+ PangoRectangle cursor_rect;
+ GtkBorder inner_border;
+ gint xoffset;
+ gint text_area_height;
+ gint cursor_index;
+ gboolean block;
+ gboolean block_at_line_end;
+ PangoLayout *layout;
+ const char *text;
- gdk_drawable_get_size (entry->text_area, NULL, &text_area_height);
+ _gtk_entry_effective_inner_border (entry, &inner_border);
- layout = gtk_entry_ensure_layout (entry, TRUE);
- text = pango_layout_get_text (layout);
- cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
- if (!entry->overwrite_mode)
- block = FALSE;
- else
- block = _gtk_text_util_get_block_cursor_location (layout,
- cursor_index, &cursor_rect, &block_at_line_end);
+ xoffset = inner_border.left - entry->scroll_offset;
- if (!block)
- {
- gint strong_x, weak_x;
- PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
- PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
- gint x1 = 0;
- gint x2 = 0;
+ text_area_height = gdk_window_get_height (entry->text_area);
- gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
+ layout = gtk_entry_ensure_layout (entry, TRUE);
+ text = pango_layout_get_text (layout);
+ cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
+ if (!entry->overwrite_mode)
+ block = FALSE;
+ else
+ block = _gtk_text_util_get_block_cursor_location (layout,
+ cursor_index, &cursor_rect, &block_at_line_end);
- g_object_get (gtk_widget_get_settings (widget),
- "gtk-split-cursor", &split_cursor,
- NULL);
+ if (!block)
+ {
+ gint strong_x, weak_x;
+ PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
+ PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
+ gint x1 = 0;
+ gint x2 = 0;
- dir1 = entry->resolved_dir;
-
- if (split_cursor)
- {
- x1 = strong_x;
+ gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
- if (weak_x != strong_x)
- {
- dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
- x2 = weak_x;
- }
- }
- else
- {
- if (keymap_direction == entry->resolved_dir)
- x1 = strong_x;
- else
- x1 = weak_x;
- }
+ g_object_get (gtk_widget_get_settings (widget),
+ "gtk-split-cursor", &split_cursor,
+ NULL);
- cursor_location.x = xoffset + x1;
- cursor_location.y = inner_border.top;
- cursor_location.width = 0;
- cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
+ dir1 = entry->resolved_dir;
+
+ if (split_cursor)
+ {
+ x1 = strong_x;
- draw_insertion_cursor (entry,
- &cursor_location, TRUE, dir1,
- dir2 != PANGO_DIRECTION_NEUTRAL);
-
- if (dir2 != PANGO_DIRECTION_NEUTRAL)
+ if (weak_x != strong_x)
{
- cursor_location.x = xoffset + x2;
- draw_insertion_cursor (entry,
- &cursor_location, FALSE, dir2,
- TRUE);
+ dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
+ x2 = weak_x;
}
}
- else /* overwrite_mode */
+ else
{
- GdkColor cursor_color;
- GdkRectangle rect;
- cairo_t *cr;
- gint x, y;
+ if (keymap_direction == entry->resolved_dir)
+ x1 = strong_x;
+ else
+ x1 = weak_x;
+ }
+
+ cursor_location.x = xoffset + x1;
+ cursor_location.y = inner_border.top;
+ cursor_location.width = 0;
+ cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
- get_layout_position (entry, &x, &y);
+ draw_insertion_cursor (entry, cr,
+ &cursor_location, TRUE, dir1,
+ dir2 != PANGO_DIRECTION_NEUTRAL);
+
+ if (dir2 != PANGO_DIRECTION_NEUTRAL)
+ {
+ cursor_location.x = xoffset + x2;
+ draw_insertion_cursor (entry, cr,
+ &cursor_location, FALSE, dir2,
+ TRUE);
+ }
+ }
+ else /* overwrite_mode */
+ {
+ GdkColor cursor_color;
+ GdkRectangle rect;
+ gint x, y;
- rect.x = PANGO_PIXELS (cursor_rect.x) + x;
- rect.y = PANGO_PIXELS (cursor_rect.y) + y;
- rect.width = PANGO_PIXELS (cursor_rect.width);
- rect.height = PANGO_PIXELS (cursor_rect.height);
+ cairo_save (cr);
- cr = gdk_cairo_create (entry->text_area);
+ get_layout_position (entry, &x, &y);
- _gtk_widget_get_cursor_color (widget, &cursor_color);
- gdk_cairo_set_source_color (cr, &cursor_color);
- gdk_cairo_rectangle (cr, &rect);
- cairo_fill (cr);
+ rect.x = PANGO_PIXELS (cursor_rect.x) + x;
+ rect.y = PANGO_PIXELS (cursor_rect.y) + y;
+ rect.width = PANGO_PIXELS (cursor_rect.width);
+ rect.height = PANGO_PIXELS (cursor_rect.height);
- if (!block_at_line_end)
- {
- gdk_cairo_rectangle (cr, &rect);
- cairo_clip (cr);
- cairo_move_to (cr, x, y);
- gdk_cairo_set_source_color (cr, &widget->style->base[widget->state]);
- pango_cairo_show_layout (cr, layout);
- }
+ _gtk_widget_get_cursor_color (widget, &cursor_color);
+ gdk_cairo_set_source_color (cr, &cursor_color);
+ gdk_cairo_rectangle (cr, &rect);
+ cairo_fill (cr);
- cairo_destroy (cr);
+ if (!block_at_line_end)
+ {
+ gdk_cairo_rectangle (cr, &rect);
+ cairo_clip (cr);
+ cairo_move_to (cr, x, y);
+ gdk_cairo_set_source_color (cr, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
+ pango_cairo_show_layout (cr, layout);
}
+
+ cairo_restore (cr);
}
}
static void
gtk_entry_queue_draw (GtkEntry *entry)
{
- if (GTK_WIDGET_DRAWABLE (entry))
- gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
+ if (gtk_widget_is_drawable (GTK_WIDGET (entry)))
+ gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (entry)),
+ NULL, FALSE);
}
void
}
}
+/**
+ * gtk_entry_reset_im_context:
+ * @entry: a #GtkEntry
+ *
+ * Reset the input method context of the entry if needed.
+ *
+ * This can be necessary in the case where modifying the buffer
+ * would confuse on-going input method behavior.
+ *
+ * Since: 2.22
+ */
+void
+gtk_entry_reset_im_context (GtkEntry *entry)
+{
+ g_return_if_fail (GTK_IS_ENTRY (entry));
+
+ _gtk_entry_reset_im_context (entry);
+}
+
+/**
+ * gtk_entry_im_context_filter_keypress:
+ * @entry: a #GtkEntry
+ * @event: the key event
+ *
+ * Allow the #GtkEntry input method to internally handle key press
+ * and release events. If this function returns %TRUE, then no further
+ * processing should be done for this key event. See
+ * gtk_im_context_filter_keypress().
+ *
+ * Note that you are expected to call this function from your handler
+ * when overriding key event handling. This is needed in the case when
+ * you need to insert your own key handling between the input method
+ * and the default key event handling of the #GtkEntry.
+ * See gtk_text_view_reset_im_context() for an example of use.
+ *
+ * Return value: %TRUE if the input method handled the key event.
+ *
+ * Since: 2.22
+ */
+gboolean
+gtk_entry_im_context_filter_keypress (GtkEntry *entry,
+ GdkEventKey *event)
+{
+ g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
+
+ return gtk_im_context_filter_keypress (entry->im_context, event);
+}
+
+
static gint
gtk_entry_find_position (GtkEntry *entry,
gint x)
PangoLayoutLine *line;
PangoRectangle logical_rect;
- if (!GTK_WIDGET_REALIZED (entry))
+ if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
return;
_gtk_entry_effective_inner_border (entry, &inner_border);
- gdk_drawable_get_size (entry->text_area, &text_area_width, NULL);
+ text_area_width = gdk_window_get_width (entry->text_area);
text_area_width -= inner_border.left + inner_border.right;
if (text_area_width < 0)
text_area_width = 0;
static void
gtk_entry_move_adjustments (GtkEntry *entry)
{
+ GtkAllocation allocation;
+ GtkAdjustment *adjustment;
PangoContext *context;
PangoFontMetrics *metrics;
gint x, layout_x, border_x, border_y;
gint char_width;
- GtkAdjustment *adjustment;
adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
if (!adjustment)
return;
+ gtk_widget_get_allocation (&(entry->widget), &allocation);
+
/* Cursor position, layout offset, border width, and widget allocation */
gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
get_layout_position (entry, &layout_x, NULL);
_gtk_entry_get_borders (entry, &border_x, &border_y);
- x += entry->widget.allocation.x + layout_x + border_x;
+ x += allocation.x + layout_x + border_x;
/* Approximate width of a char, so user can see what is ahead/behind */
context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
metrics = pango_context_get_metrics (context,
- entry->widget.style->font_desc,
+ gtk_widget_get_style (&(entry->widget))->font_desc,
pango_context_get_language (context));
char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
if (completion)
{
- if (GTK_WIDGET_MAPPED (completion->priv->popup_window))
+ if (gtk_widget_get_mapped (completion->priv->popup_window))
_gtk_entry_completion_popdown (completion);
if (!popup_completion && completion->priv->changed_id > 0)
gint start, end;
gint n_targets;
- if (!GTK_WIDGET_REALIZED (entry))
+ if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
return;
list = gtk_target_list_new (NULL, 0);
{
GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
EntryIconInfo *icon_info = priv->icons[icon_pos];
- GdkScreen *screen;
+ GtkIconInfo *info;
GtkIconTheme *icon_theme;
GtkSettings *settings;
+ GtkStateType state;
+ GtkWidget *widget;
+ GdkScreen *screen;
gint width, height;
- GtkIconInfo *info;
- gint state;
if (!icon_info || icon_info->pixbuf)
return;
+ widget = GTK_WIDGET (entry);
+
switch (icon_info->storage_type)
{
case GTK_IMAGE_EMPTY:
case GTK_IMAGE_PIXBUF:
break;
case GTK_IMAGE_STOCK:
- state = GTK_WIDGET_STATE (entry);
- GTK_WIDGET_STATE (entry) = GTK_STATE_NORMAL;
- icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
+ state = gtk_widget_get_state (widget);
+ gtk_widget_set_state (widget, GTK_STATE_NORMAL);
+ icon_info->pixbuf = gtk_widget_render_icon (widget,
icon_info->stock_id,
GTK_ICON_SIZE_MENU,
NULL);
if (!icon_info->pixbuf)
- icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
+ icon_info->pixbuf = gtk_widget_render_icon (widget,
GTK_STOCK_MISSING_IMAGE,
GTK_ICON_SIZE_MENU,
NULL);
- GTK_WIDGET_STATE (entry) = state;
+ gtk_widget_set_state (widget, state);
break;
case GTK_IMAGE_ICON_NAME:
- screen = gtk_widget_get_screen (GTK_WIDGET (entry));
+ screen = gtk_widget_get_screen (widget);
if (screen)
{
icon_theme = gtk_icon_theme_get_for_screen (screen);
if (icon_info->pixbuf == NULL)
{
- state = GTK_WIDGET_STATE (entry);
- GTK_WIDGET_STATE (entry) = GTK_STATE_NORMAL;
- icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
+ state = gtk_widget_get_state (widget);
+ gtk_widget_set_state (widget, GTK_STATE_NORMAL);
+ icon_info->pixbuf = gtk_widget_render_icon (widget,
GTK_STOCK_MISSING_IMAGE,
GTK_ICON_SIZE_MENU,
NULL);
- GTK_WIDGET_STATE (entry) = state;
+ gtk_widget_set_state (widget, state);
}
}
break;
case GTK_IMAGE_GICON:
- screen = gtk_widget_get_screen (GTK_WIDGET (entry));
+ screen = gtk_widget_get_screen (widget);
if (screen)
{
icon_theme = gtk_icon_theme_get_for_screen (screen);
if (icon_info->pixbuf == NULL)
{
- state = GTK_WIDGET_STATE (entry);
- GTK_WIDGET_STATE (entry) = GTK_STATE_NORMAL;
- icon_info->pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
+ state = gtk_widget_get_state (widget);
+ gtk_widget_set_state (widget, GTK_STATE_NORMAL);
+ icon_info->pixbuf = gtk_widget_render_icon (widget,
GTK_STOCK_MISSING_IMAGE,
GTK_ICON_SIZE_MENU,
NULL);
- GTK_WIDGET_STATE (entry) = state;
+ gtk_widget_set_state (widget, state);
}
}
break;
return g_object_new (GTK_TYPE_ENTRY, "buffer", buffer, NULL);
}
-/**
- * gtk_entry_new_with_max_length:
- * @max: the maximum length of the entry, or 0 for no maximum.
- * (other than the maximum length of entries.) The value passed in will
- * be clamped to the range 0-65536.
- *
- * Creates a new #GtkEntry widget with the given maximum length.
- *
- * Return value: a new #GtkEntry
- *
- * Deprecated: Use gtk_entry_set_max_length() instead.
- **/
-GtkWidget*
-gtk_entry_new_with_max_length (gint max)
-{
- GtkEntry *entry;
-
- max = CLAMP (max, 0, GTK_ENTRY_BUFFER_MAX_SIZE);
-
- entry = g_object_new (GTK_TYPE_ENTRY, NULL);
- gtk_entry_buffer_set_max_length (get_buffer (entry), max);
-
- return GTK_WIDGET (entry);
-}
-
-
static GtkEntryBuffer*
get_buffer (GtkEntry *entry)
{
*
* Since: 2.18
*
- * Returns: A #GtkEntryBuffer object.
+ * Returns: (transfer none): A #GtkEntryBuffer object.
*/
GtkEntryBuffer*
gtk_entry_get_buffer (GtkEntry *entry)
{
buffer_disconnect_signals (entry);
g_object_unref (priv->buffer);
-
- /* COMPAT: Deprecated. Not used. Setting these fields no longer necessary in GTK 3.x */
- entry->text = NULL;
- entry->text_length = 0;
- entry->text_max_length = 0;
}
priv->buffer = buffer;
if (priv->buffer)
- {
- buffer_connect_signals (entry);
-
- /* COMPAT: Deprecated. Not used. Setting these fields no longer necessary in GTK 3.x */
- entry->text = (char*)gtk_entry_buffer_get_text (priv->buffer);
- entry->text_length = gtk_entry_buffer_get_length (priv->buffer);
- entry->text_max_length = gtk_entry_buffer_get_max_length (priv->buffer);
- }
+ buffer_connect_signals (entry);
obj = G_OBJECT (entry);
g_object_freeze_notify (obj);
g_object_notify (obj, "invisible-char");
g_object_notify (obj, "invisible-char-set");
g_object_thaw_notify (obj);
+
+ gtk_editable_set_position (GTK_EDITABLE (entry), 0);
+ gtk_entry_recompute (entry);
}
+/**
+ * gtk_entry_get_text_area:
+ * @entry: a #GtkEntry
+ * @text_area: Return location for the text area.
+ *
+ * Gets the area where the entry's text is drawn. This function is
+ * useful when drawing something to the entry in a draw callback.
+ *
+ * If the entry is not realized, @text_area is filled with zeros.
+ *
+ * See also gtk_entry_get_icon_area().
+ *
+ * Since: 3.0
+ **/
+void
+gtk_entry_get_text_area (GtkEntry *entry,
+ GdkRectangle *text_area)
+{
+ g_return_if_fail (GTK_IS_ENTRY (entry));
+ g_return_if_fail (text_area != NULL);
+
+ if (entry->text_area)
+ {
+ GtkAllocation allocation;
+ gint x, y;
+
+ gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
+ gdk_window_get_position (entry->text_area, &x, &y);
+
+ text_area->x = x - allocation.x;
+ text_area->y = y - allocation.y;
+ text_area->width = gdk_window_get_width (entry->text_area);
+ text_area->height = gdk_window_get_height (entry->text_area);
+ }
+ else
+ {
+ text_area->x = 0;
+ text_area->y = 0;
+ text_area->width = 0;
+ text_area->height = 0;
+ }
+}
/**
* gtk_entry_set_text:
g_signal_handler_unblock (entry, completion->priv->changed_id);
}
-/**
- * gtk_entry_append_text:
- * @entry: a #GtkEntry
- * @text: the text to append
- *
- * Appends the given text to the contents of the widget.
- *
- * Deprecated: 2.0: Use gtk_editable_insert_text() instead.
- */
-void
-gtk_entry_append_text (GtkEntry *entry,
- const gchar *text)
-{
- GtkEntryPrivate *priv;
- gint tmp_pos;
-
- g_return_if_fail (GTK_IS_ENTRY (entry));
- g_return_if_fail (text != NULL);
- priv = GTK_ENTRY_GET_PRIVATE (entry);
-
- tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
- gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
-}
-
-/**
- * gtk_entry_prepend_text:
- * @entry: a #GtkEntry
- * @text: the text to prepend
- *
- * Prepends the given text to the contents of the widget.
- *
- * Deprecated: 2.0: Use gtk_editable_insert_text() instead.
- */
-void
-gtk_entry_prepend_text (GtkEntry *entry,
- const gchar *text)
-{
- gint tmp_pos;
-
- g_return_if_fail (GTK_IS_ENTRY (entry));
- g_return_if_fail (text != NULL);
-
- tmp_pos = 0;
- gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
-}
-
-/**
- * gtk_entry_set_position:
- * @entry: a #GtkEntry
- * @position: the position of the cursor. The cursor is displayed
- * before the character with the given (base 0) index in the widget.
- * The value must be less than or equal to the number of characters
- * in the widget. A value of -1 indicates that the position should
- * be set after the last character in the entry. Note that this
- * position is in characters, not in bytes.
- *
- * Sets the cursor position in an entry to the given value.
- *
- * Deprecated: 2.0: Use gtk_editable_set_position() instead.
- */
-void
-gtk_entry_set_position (GtkEntry *entry,
- gint position)
-{
- g_return_if_fail (GTK_IS_ENTRY (entry));
-
- gtk_editable_set_position (GTK_EDITABLE (entry), position);
-}
-
/**
* gtk_entry_set_visibility:
* @entry: a #GtkEntry
gtk_entry_recompute (entry);
}
-/**
- * gtk_entry_set_editable:
- * @entry: a #GtkEntry
- * @editable: %TRUE if the user is allowed to edit the text
- * in the widget
- *
- * Determines if the user can edit the text in the editable
- * widget or not.
- *
- * Deprecated: 2.0: Use gtk_editable_set_editable() instead.
- */
-void
-gtk_entry_set_editable (GtkEntry *entry,
- gboolean editable)
-{
- g_return_if_fail (GTK_IS_ENTRY (entry));
-
- gtk_editable_set_editable (GTK_EDITABLE (entry), editable);
-}
-
/**
* gtk_entry_set_overwrite_mode:
* @entry: a #GtkEntry
return gtk_entry_buffer_get_text (get_buffer (entry));
}
-/**
- * gtk_entry_select_region:
- * @entry: a #GtkEntry
- * @start: the starting position
- * @end: the end position
- *
- * Selects a region of text. The characters that are selected are
- * those characters at positions from @start_pos up to, but not
- * including @end_pos. If @end_pos is negative, then the the characters
- * selected will be those characters from @start_pos to the end of
- * the text.
- *
- * Deprecated: 2.0: Use gtk_editable_select_region() instead.
- */
-void
-gtk_entry_select_region (GtkEntry *entry,
- gint start,
- gint end)
-{
- gtk_editable_select_region (GTK_EDITABLE (entry), start, end);
-}
-
/**
* gtk_entry_set_max_length:
* @entry: a #GtkEntry
/**
* gtk_entry_set_inner_border:
* @entry: a #GtkEntry
- * @border: a #GtkBorder, or %NULL
+ * @border: (allow-none): a #GtkBorder, or %NULL
*
* Sets %entry's inner-border property to %border, or clears it if %NULL
* is passed. The inner-border is the area around the entry's text, but
* This function returns the entry's #GtkEntry:inner-border property. See
* gtk_entry_set_inner_border() for more information.
*
- * Return value: the entry's #GtkBorder, or %NULL if none was set.
+ * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
*
* Since: 2.10
**/
* gtk_entry_layout_index_to_text_index() and
* gtk_entry_text_index_to_layout_index() are needed to convert byte
* indices in the layout to byte indices in the entry contents.
- *
- * Return value: the #PangoLayout for this entry
+ *
+ * Return value: (transfer none): the #PangoLayout for this entry
**/
PangoLayout*
gtk_entry_get_layout (GtkEntry *entry)
/**
* gtk_entry_get_layout_offsets:
* @entry: a #GtkEntry
- * @x: location to store X offset of layout, or %NULL
- * @y: location to store Y offset of layout, or %NULL
+ * @x: (allow-none): location to store X offset of layout, or %NULL
+ * @y: (allow-none): location to store Y offset of layout, or %NULL
*
*
* Obtains the position of the #PangoLayout used to render text
* gtk_entry_set_icon_from_pixbuf:
* @entry: a #GtkEntry
* @icon_pos: Icon position
- * @pixbuf: A #GdkPixbuf, or %NULL
+ * @pixbuf: (allow-none): A #GdkPixbuf, or %NULL
*
* Sets the icon shown in the specified position using a pixbuf.
*
g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
}
- if (GTK_WIDGET_MAPPED (entry))
+ if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
gdk_window_show_unraised (icon_info->window);
}
gtk_entry_ensure_pixbuf (entry, icon_pos);
- if (GTK_WIDGET_VISIBLE (entry))
+ if (gtk_widget_get_visible (GTK_WIDGET (entry)))
gtk_widget_queue_resize (GTK_WIDGET (entry));
g_object_thaw_notify (G_OBJECT (entry));
* gtk_entry_set_icon_from_stock:
* @entry: A #GtkEntry
* @icon_pos: Icon position
- * @stock_id: The name of the stock item, or %NULL
+ * @stock_id: (allow-none): The name of the stock item, or %NULL
*
* Sets the icon shown in the entry at the specified position from
* a stock image.
g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
}
- if (GTK_WIDGET_MAPPED (entry))
+ if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
gdk_window_show_unraised (icon_info->window);
}
gtk_entry_ensure_pixbuf (entry, icon_pos);
- if (GTK_WIDGET_VISIBLE (entry))
+ if (gtk_widget_get_visible (GTK_WIDGET (entry)))
gtk_widget_queue_resize (GTK_WIDGET (entry));
g_object_thaw_notify (G_OBJECT (entry));
* gtk_entry_set_icon_from_icon_name:
* @entry: A #GtkEntry
* @icon_pos: The position at which to set the icon
- * @icon_name: An icon name, or %NULL
+ * @icon_name: (allow-none): An icon name, or %NULL
*
* Sets the icon shown in the entry at the specified position
* from the current icon theme.
g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
}
- if (GTK_WIDGET_MAPPED (entry))
+ if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
gdk_window_show_unraised (icon_info->window);
}
gtk_entry_ensure_pixbuf (entry, icon_pos);
- if (GTK_WIDGET_VISIBLE (entry))
+ if (gtk_widget_get_visible (GTK_WIDGET (entry)))
gtk_widget_queue_resize (GTK_WIDGET (entry));
g_object_thaw_notify (G_OBJECT (entry));
* gtk_entry_set_icon_from_gicon:
* @entry: A #GtkEntry
* @icon_pos: The position at which to set the icon
- * @icon: The icon to set, or %NULL
+ * @icon: (allow-none): The icon to set, or %NULL
*
* Sets the icon shown in the entry at the specified position
* from the current icon theme.
g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
}
- if (GTK_WIDGET_MAPPED (entry))
+ if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
gdk_window_show_unraised (icon_info->window);
}
gtk_entry_ensure_pixbuf (entry, icon_pos);
- if (GTK_WIDGET_VISIBLE (entry))
+ if (gtk_widget_get_visible (GTK_WIDGET (entry)))
gtk_widget_queue_resize (GTK_WIDGET (entry));
g_object_thaw_notify (G_OBJECT (entry));
{
icon_info->nonactivatable = !activatable;
- if (GTK_WIDGET_REALIZED (GTK_WIDGET (entry)))
+ if (gtk_widget_get_realized (GTK_WIDGET (entry)))
update_cursors (GTK_WIDGET (entry));
g_object_notify (G_OBJECT (entry),
* method will work regardless of whether the icon was set using a
* #GdkPixbuf, a #GIcon, a stock item, or an icon name.
*
- * Returns: A #GdkPixbuf, or %NULL if no icon is set for this position.
+ * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
+ * set for this position.
*
* Since: 2.16
*/
* no icon or if the icon was set by some other method (e.g., by
* stock, pixbuf, or icon name).
*
- * Returns: A #GIcon, or %NULL if no icon is set or if the icon
- * is not a #GIcon
+ * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
+ * or if the icon is not a #GIcon
*
* Since: 2.16
*/
icon_info->pressed = FALSE;
icon_info->prelight = FALSE;
- if (GTK_WIDGET_REALIZED (GTK_WIDGET (entry)))
+ if (gtk_widget_get_realized (GTK_WIDGET (entry)))
update_cursors (GTK_WIDGET (entry));
gtk_widget_queue_draw (GTK_WIDGET (entry));
{
GtkAllocation primary;
GtkAllocation secondary;
+ gint frame_x, frame_y;
g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
+ get_frame_size (entry, &frame_x, &frame_y, NULL, NULL);
+ x -= frame_x;
+ y -= frame_y;
+
get_icon_allocations (entry, &primary, &secondary);
if (primary.x <= x && x < primary.x + primary.width &&
* #GtkWidget::drag-begin signal to set a different icon. Note that you
* have to use g_signal_connect_after() to ensure that your signal handler
* gets executed after the default handler.
+ *
+ * Since: 2.16
*/
void
gtk_entry_set_icon_drag_source (GtkEntry *entry,
*
* Returns: index of the icon which is the source of the current
* DND operation, or -1.
+ *
+ * Since: 2.16
*/
gint
gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
return -1;
}
+/**
+ * gtk_entry_get_icon_area:
+ * @entry: A #GtkEntry
+ * @icon_pos: Icon position
+ * @icon_area: Return location for the icon's area
+ *
+ * Gets the area where entry's icon at @icon_pos is drawn.
+ * This function is useful when drawing something to the
+ * entry in a draw callback.
+ *
+ * If the entry is not realized or has no icon at the given position,
+ * @icon_area is filled with zeros.
+ *
+ * See also gtk_entry_get_text_area()
+ *
+ * Since: 3.0
+ */
+void
+gtk_entry_get_icon_area (GtkEntry *entry,
+ GtkEntryIconPosition icon_pos,
+ GdkRectangle *icon_area)
+{
+ GtkEntryPrivate *priv;
+ EntryIconInfo *icon_info;
+
+ g_return_if_fail (GTK_IS_ENTRY (entry));
+ g_return_if_fail (icon_area != NULL);
+
+ priv = GTK_ENTRY_GET_PRIVATE (entry);
+
+ icon_info = priv->icons[icon_pos];
+
+ if (icon_info)
+ {
+ GtkAllocation primary;
+ GtkAllocation secondary;
+
+ get_icon_allocations (entry, &primary, &secondary);
+
+ if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
+ *icon_area = primary;
+ else
+ *icon_area = secondary;
+ }
+ else
+ {
+ icon_area->x = 0;
+ icon_area->y = 0;
+ icon_area->width = 0;
+ icon_area->height = 0;
+ }
+}
+
static void
ensure_has_tooltip (GtkEntry *entry)
{
* gtk_entry_set_icon_tooltip_text:
* @entry: a #GtkEntry
* @icon_pos: the icon position
- * @tooltip: the contents of the tooltip for the icon, or %NULL
+ * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
*
* Sets @tooltip as the contents of the tooltip for the icon
* at the specified position.
* gtk_entry_set_icon_tooltip_markup:
* @entry: a #GtkEntry
* @icon_pos: the icon position
- * @tooltip: the contents of the tooltip for the icon, or %NULL
+ * @tooltip: (allow-none): the contents of the tooltip for the icon, or %NULL
*
* Sets @tooltip as the contents of the tooltip for the icon at
* the specified position. @tooltip is assumed to be marked up with
GtkBorder inner_border;
gint monitor_num, strong_x, height;
- g_return_if_fail (GTK_WIDGET_REALIZED (entry));
+ g_return_if_fail (gtk_widget_get_realized (widget));
gdk_window_get_origin (entry->text_area, x, y);
gtk_menu_set_monitor (menu, monitor_num);
gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
- gtk_widget_size_request (entry->popup_menu, &menu_req);
- gdk_drawable_get_size (entry->text_area, NULL, &height);
+ gtk_widget_get_preferred_size (entry->popup_menu,
+ &menu_req, NULL);
+ height = gdk_window_get_height (entry->text_area);
gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
_gtk_entry_effective_inner_border (entry, &inner_border);
PopupInfo *info = user_data;
GtkEntry *entry = info->entry;
- if (GTK_WIDGET_REALIZED (entry))
+ if (gtk_widget_get_realized (GTK_WIDGET (entry)))
{
DisplayMode mode;
gboolean clipboard_contains_text;
guint time)
{
GtkEntry *entry = GTK_ENTRY (widget);
+ GtkStyle *style;
GtkWidget *source_widget;
GdkDragAction suggested_action;
gint new_position, old_position;
gint sel1, sel2;
-
- x -= widget->style->xthickness;
- y -= widget->style->ythickness;
-
+
+ style = gtk_widget_get_style (widget);
+ x -= style->xthickness;
+ y -= style->ythickness;
+
old_position = entry->dnd_position;
new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
{
GtkEntry *entry = GTK_ENTRY (widget);
GtkEditable *editable = GTK_EDITABLE (widget);
+ GtkStyle *style;
gchar *str;
str = (gchar *) gtk_selection_data_get_text (selection_data);
- x -= widget->style->xthickness;
- y -= widget->style->ythickness;
+ style = gtk_widget_get_style (widget);
+ x -= style->xthickness;
+ y -= style->ythickness;
if (str && entry->editable)
{
static gboolean
cursor_blinks (GtkEntry *entry)
{
- if (GTK_WIDGET_HAS_FOCUS (entry) &&
+ if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
entry->editable &&
entry->selection_bound == entry->current_pos)
{
static void
show_cursor (GtkEntry *entry)
{
+ GtkWidget *widget;
+
if (!entry->cursor_visible)
{
entry->cursor_visible = TRUE;
- if (GTK_WIDGET_HAS_FOCUS (entry) && entry->selection_bound == entry->current_pos)
- gtk_widget_queue_draw (GTK_WIDGET (entry));
+ widget = GTK_WIDGET (entry);
+ if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
+ gtk_widget_queue_draw (widget);
}
}
static void
hide_cursor (GtkEntry *entry)
{
+ GtkWidget *widget;
+
if (entry->cursor_visible)
{
entry->cursor_visible = FALSE;
- if (GTK_WIDGET_HAS_FOCUS (entry) && entry->selection_bound == entry->current_pos)
- gtk_widget_queue_draw (GTK_WIDGET (entry));
+ widget = GTK_WIDGET (entry);
+ if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
+ gtk_widget_queue_draw (widget);
}
}
entry = GTK_ENTRY (data);
priv = GTK_ENTRY_GET_PRIVATE (entry);
- if (!GTK_WIDGET_HAS_FOCUS (entry))
+ if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
{
g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
"connect a handler to this signal, it must return\n"
gtk_entry_completion_timeout (gpointer data)
{
GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
+ GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (completion->priv->entry);
completion->priv->completion_timeout = 0;
g_object_get (completion, "popup-single-match", &popup_single, NULL);
if ((matches > (popup_single ? 0: 1)) || actions > 0)
{
- if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
+ if (gtk_widget_get_visible (completion->priv->popup_window))
_gtk_entry_completion_resize_popup (completion);
else
- _gtk_entry_completion_popup (completion);
+ _gtk_entry_completion_popup (completion, priv->completion_device);
}
else
_gtk_entry_completion_popdown (completion);
}
- else if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
+ else if (gtk_widget_get_visible (completion->priv->popup_window))
_gtk_entry_completion_popdown (completion);
return FALSE;
static inline gboolean
keyval_is_cursor_move (guint keyval)
{
- if (keyval == GDK_Up || keyval == GDK_KP_Up)
+ if (keyval == GDK_KEY_Up || keyval == GDK_KEY_KP_Up)
return TRUE;
- if (keyval == GDK_Down || keyval == GDK_KP_Down)
+ if (keyval == GDK_KEY_Down || keyval == GDK_KEY_KP_Down)
return TRUE;
- if (keyval == GDK_Page_Up)
+ if (keyval == GDK_KEY_Page_Up)
return TRUE;
- if (keyval == GDK_Page_Down)
+ if (keyval == GDK_KEY_Page_Down)
return TRUE;
return FALSE;
gint matches, actions = 0;
GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
- if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
+ if (!gtk_widget_get_mapped (completion->priv->popup_window))
return FALSE;
matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
{
GtkTreePath *path = NULL;
- if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
+ if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
{
if (completion->priv->current_selected < 0)
completion->priv->current_selected = matches + actions - 1;
else
completion->priv->current_selected--;
}
- else if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
+ else if (event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_KP_Down)
{
if (completion->priv->current_selected < matches + actions - 1)
completion->priv->current_selected++;
else
completion->priv->current_selected = -1;
}
- else if (event->keyval == GDK_Page_Up)
+ else if (event->keyval == GDK_KEY_Page_Up)
{
if (completion->priv->current_selected < 0)
completion->priv->current_selected = matches + actions - 1;
completion->priv->current_selected = matches - 1;
}
}
- else if (event->keyval == GDK_Page_Down)
+ else if (event->keyval == GDK_KEY_Page_Down)
{
if (completion->priv->current_selected < 0)
completion->priv->current_selected = 0;
{
GtkTreeIter iter;
+ GtkTreeIter child_iter;
GtkTreeModel *model = NULL;
GtkTreeSelection *sel;
gboolean entry_set;
sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
if (!gtk_tree_selection_get_selected (sel, &model, &iter))
return FALSE;
+
+ gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
+ model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
if (completion->priv->completion_prefix == NULL)
completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
g_signal_emit_by_name (completion, "cursor-on-match", model,
- &iter, &entry_set);
+ &child_iter, &entry_set);
}
}
else if (completion->priv->current_selected - matches >= 0)
return TRUE;
}
- else if (event->keyval == GDK_Escape ||
- event->keyval == GDK_Left ||
- event->keyval == GDK_KP_Left ||
- event->keyval == GDK_Right ||
- event->keyval == GDK_KP_Right)
+ else if (event->keyval == GDK_KEY_Escape ||
+ event->keyval == GDK_KEY_Left ||
+ event->keyval == GDK_KEY_KP_Left ||
+ event->keyval == GDK_KEY_Right ||
+ event->keyval == GDK_KEY_KP_Right)
{
gboolean retval = TRUE;
else if (completion->priv->inline_selection)
{
/* Escape rejects the tentative completion */
- if (event->keyval == GDK_Escape)
+ if (event->keyval == GDK_KEY_Escape)
{
if (completion->priv->completion_prefix)
gtk_entry_set_text (GTK_ENTRY (completion->priv->entry),
/* Move the cursor to the end for Right/Esc, to the
beginning for Left */
- if (event->keyval == GDK_Right ||
- event->keyval == GDK_KP_Right ||
- event->keyval == GDK_Escape)
+ if (event->keyval == GDK_KEY_Right ||
+ event->keyval == GDK_KEY_KP_Right ||
+ event->keyval == GDK_KEY_Escape)
gtk_editable_set_position (GTK_EDITABLE (widget), -1);
else
gtk_editable_set_position (GTK_EDITABLE (widget), 0);
return retval;
}
- else if (event->keyval == GDK_Tab ||
- event->keyval == GDK_KP_Tab ||
- event->keyval == GDK_ISO_Left_Tab)
+ else if (event->keyval == GDK_KEY_Tab ||
+ event->keyval == GDK_KEY_KP_Tab ||
+ event->keyval == GDK_KEY_ISO_Left_Tab)
{
- GtkDirectionType dir = event->keyval == GDK_ISO_Left_Tab ?
+ GtkDirectionType dir = event->keyval == GDK_KEY_ISO_Left_Tab ?
GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
_gtk_entry_reset_im_context (GTK_ENTRY (widget));
return TRUE;
}
- else if (event->keyval == GDK_ISO_Enter ||
- event->keyval == GDK_KP_Enter ||
- event->keyval == GDK_Return)
+ else if (event->keyval == GDK_KEY_ISO_Enter ||
+ event->keyval == GDK_KEY_KP_Enter ||
+ event->keyval == GDK_KEY_Return)
{
GtkTreeIter iter;
GtkTreeModel *model = NULL;
gtk_entry_completion_changed (GtkWidget *entry,
gpointer user_data)
{
+ GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
+ GdkDevice *device;
/* (re)install completion timeout */
if (completion->priv->completion_timeout)
if (completion->priv->minimum_key_length > 0 &&
strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
{
- if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
+ if (gtk_widget_get_visible (completion->priv->popup_window))
_gtk_entry_completion_popdown (completion);
return;
}
+ device = gtk_get_current_event_device ();
+
+ if (device && device->source == GDK_SOURCE_KEYBOARD)
+ device = gdk_device_get_associated_device (device);
+
+ if (device)
+ priv->completion_device = device;
+
completion->priv->completion_timeout =
gdk_threads_add_timeout (COMPLETION_TIMEOUT,
gtk_entry_completion_timeout,
/**
* gtk_entry_set_completion:
* @entry: A #GtkEntry
- * @completion: The #GtkEntryCompletion or %NULL
+ * @completion: (allow-none): The #GtkEntryCompletion or %NULL
*
* Sets @completion to be the auxiliary completion object to use with @entry.
* All further configuration of the completion mechanism is done on
old->priv->completion_timeout = 0;
}
- if (GTK_WIDGET_MAPPED (old->priv->popup_window))
+ if (gtk_widget_get_mapped (old->priv->popup_window))
_gtk_entry_completion_popdown (old);
disconnect_completion_signals (entry, old);
*
* Returns the auxiliary completion object currently in use by @entry.
*
- * Return value: The auxiliary completion object currently in use by @entry.
+ * Return value: (transfer none): The auxiliary completion object currently
+ * in use by @entry.
*
* Since: 2.4
*/
* Retrieves the horizontal cursor adjustment for the entry.
* See gtk_entry_set_cursor_hadjustment().
*
- * Return value: the horizontal cursor adjustment, or %NULL
+ * Return value: (transfer none): the horizontal cursor adjustment, or %NULL
* if none has been set.
- *
+ *
* Since: 2.12
*/
GtkAdjustment*
gtk_entry_set_progress_fraction (GtkEntry *entry,
gdouble fraction)
{
+ GtkWidget *widget;
GtkEntryPrivate *private;
gdouble old_fraction;
gint x, y, width, height;
g_return_if_fail (GTK_IS_ENTRY (entry));
+ widget = GTK_WIDGET (entry);
private = GTK_ENTRY_GET_PRIVATE (entry);
if (private->progress_pulse_mode)
else
old_fraction = private->progress_fraction;
- if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (entry)))
- get_progress_area (GTK_WIDGET(entry), &old_x, &old_y, &old_width, &old_height);
+ if (gtk_widget_is_drawable (widget))
+ get_progress_area (widget, &old_x, &old_y, &old_width, &old_height);
fraction = CLAMP (fraction, 0.0, 1.0);
private->progress_pulse_mode = FALSE;
private->progress_pulse_current = 0.0;
- if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (entry)))
+ if (gtk_widget_is_drawable (widget))
{
- get_progress_area (GTK_WIDGET(entry), &x, &y, &width, &height);
+ get_progress_area (widget, &x, &y, &width, &height);
if ((x != old_x) || (y != old_y) || (width != old_width) || (height != old_height))
- gtk_widget_queue_draw (GTK_WIDGET (entry));
+ gtk_widget_queue_draw (widget);
}
if (fraction != old_fraction)
if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
{
- if (gdk_keymap_get_caps_lock_state (keymap))
+ if (gdk_keymap_get_num_lock_state (keymap)
+ && gdk_keymap_get_caps_lock_state (keymap))
+ text = _("Caps Lock and Num Lock are on");
+ else if (gdk_keymap_get_num_lock_state (keymap))
+ text = _("Num Lock is on");
+ else if (gdk_keymap_get_caps_lock_state (keymap))
text = _("Caps Lock is on");
}
else
remove_capslock_feedback (entry);
}
-
-#define __GTK_ENTRY_C__
-#include "gtkaliasdef.c"