#include "gtkiconfactory.h"
#include "gtkicontheme.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"
#define MIN_ENTRY_WIDTH 150
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;
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 (entry);
gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
+ gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
entry->editable = TRUE;
entry->visible = TRUE;
}
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
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 (gtk_widget_get_window (widget),
&attributes,
attributes_mask);
gdk_window_set_user_data (icon_info->window, widget);
- gdk_window_set_background (icon_info->window,
- >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
gtk_widget_queue_resize (widget);
}
EntryIconInfo *icon_info = NULL;
gint i;
- if (gtk_widget_get_realized (widget) && !gtk_widget_get_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_get_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;
- GtkStateType state;
- GtkStyle *style;
EntryIconInfo *icon_info;
GdkWindow *window;
GdkWindowAttr attributes;
gint attributes_mask;
+ gint frame_x, frame_y;
int i;
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;
-
- window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
- gtk_widget_set_window (widget, window);
- gdk_window_set_user_data (window, entry);
+ attributes_mask = GDK_WA_X | GDK_WA_Y;
get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
-
+
+ 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 (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);
gtk_widget_style_attach (widget);
- style = gtk_widget_get_style (widget);
- state = gtk_widget_get_state (widget);
- gdk_window_set_background (window, &style->base[state]);
- gdk_window_set_background (entry->text_area, &style->base[state]);
-
gdk_window_show (entry->text_area);
gtk_im_context_set_client_window (entry->im_context, entry->text_area);
}
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,
- gtk_widget_get_style (widget)->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
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);
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,
gint frame_height;
gint xborder, yborder;
- 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_get_realized (widget))
- gdk_drawable_get_size (gtk_widget_get_window (widget), NULL, &frame_height);
+ get_frame_size (entry, NULL, NULL, NULL, &frame_height);
else
frame_height = requisition.height;
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)
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 (gtk_widget_get_window (widget),
- x, y, width, height);
-
place_windows (entry);
gtk_entry_recompute (entry);
static void
draw_icon (GtkWidget *widget,
+ cairo_t *cr,
GtkEntryIconPosition icon_pos)
{
GtkEntry *entry = GTK_ENTRY (widget);
EntryIconInfo *icon_info = priv->icons[icon_pos];
GdkPixbuf *pixbuf;
gint x, y, width, height;
- cairo_t *cr;
if (!icon_info)
return;
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.
*/
pixbuf = temp_pixbuf;
}
- cr = gdk_cairo_create (icon_info->window);
gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
cairo_paint (cr);
- cairo_destroy (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);
- gdk_drawable_get_size (window, &width, &height);
+ get_frame_size (GTK_ENTRY (widget), &frame_x, &frame_y, &width, &height);
+ gtk_widget_get_allocation (widget, &allocation);
+
+ 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;
}
style = gtk_widget_get_style (widget);
- gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
- if (state_hint)
- state = gtk_widget_has_focus (widget) ?
- GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
- else
- state = GTK_STATE_NORMAL;
+ state = gtk_widget_has_focus (widget) ?
+ GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
- gtk_paint_shadow (style, 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)
{
width += 2 * priv->focus_width;
height += 2 * priv->focus_width;
- gtk_paint_focus (style, window,
+ gtk_paint_focus (style, cr,
gtk_widget_get_state (widget),
- &event->area, widget, "entry",
+ widget, "entry",
0, 0, width, height);
}
-}
-
-static void
-gtk_entry_get_progress_border (GtkWidget *widget,
- GtkBorder *progress_border)
-{
- GtkBorder *tmp_border;
- GtkStyle *style;
- gtk_widget_style_get (widget, "progress-border", &tmp_border, NULL);
- if (tmp_border)
- {
- *progress_border = *tmp_border;
- gtk_border_free (tmp_border);
- }
- else
- {
- style = gtk_widget_get_style (widget);
-
- progress_border->left = style->xthickness;
- progress_border->right = style->xthickness;
- progress_border->top = style->ythickness;
- progress_border->bottom = 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 (gtk_widget_get_window (widget), 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 != gtk_widget_get_window (widget))
- {
- 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_get_sensitive (widget))
state = GTK_STATE_INSENSITIVE;
- gtk_paint_box (gtk_widget_get_style (widget), 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);
GtkStyle *style;
- gboolean state_hint;
GtkStateType state;
GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+ int i;
style = gtk_widget_get_style (widget);
- gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
-
- if (state_hint)
- state = gtk_widget_has_focus (widget) ?
- GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
- else
- state = gtk_widget_get_state(widget);
+ state = gtk_widget_has_focus (widget) ?
+ GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
- if (gtk_widget_get_window (widget) == event->window)
+ if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
{
- gtk_entry_draw_frame (widget, event);
- }
- else if (entry->text_area == event->window)
- {
- gint width, height;
+ /* Draw entry_bg, shadow, progress and focus */
+ gtk_entry_draw_frame (widget, cr);
- gdk_drawable_get_size (entry->text_area, &width, &height);
+ /* Draw text and cursor */
+ cairo_save (cr);
- gtk_paint_flat_box (style, entry->text_area,
- state, GTK_SHADOW_NONE,
- &event->area, widget, "entry_bg",
- 0, 0, width, height);
-
- 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;
+ 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;
-
- gdk_drawable_get_size (icon_info->window, &width, &height);
+ cairo_save (cr);
- gtk_paint_flat_box (style, icon_info->window,
- gtk_widget_get_state (widget), GTK_SHADOW_NONE,
- NULL, widget, "entry_bg",
- 0, 0, width, height);
+ gtk_cairo_transform_to_window (cr, widget, icon_info->window);
- gtk_entry_draw_progress (widget, event);
- draw_icon (widget, i);
+ draw_icon (widget, cr, i);
- break;
+ cairo_restore (cr);
}
}
}
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_get_realized (widget))
{
- GtkStateType state;
- GtkStyle *style;
-
- style = gtk_widget_get_style (widget);
- state = gtk_widget_get_state (widget);
-
- gdk_window_set_background (gtk_widget_get_window (widget),
- &style->base[state]);
- gdk_window_set_background (entry->text_area,
- &style->base[state]);
- 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,
- &style->base[state]);
- }
-
if (gtk_widget_is_sensitive (widget))
cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
else
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_get_realized (widget))
- {
- GtkStyle *style;
-
- style = gtk_widget_get_style (widget);
-
- gdk_window_set_background (gtk_widget_get_window (widget),
- &style->base[gtk_widget_get_state (widget)]);
- gdk_window_set_background (entry->text_area,
- &style->base[gtk_widget_get_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,
- &style->base[gtk_widget_get_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));
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");
}
}
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_is_drawable (widget))
- {
- 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;
-
- 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];
+ 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];
- get_progress_area (widget,
- &progress_x, &progress_y,
- &progress_width, &progress_height);
+ get_progress_area (widget,
+ &progress_x, &progress_y,
+ &progress_width, &progress_height);
- cr = gdk_cairo_create (entry->text_area);
+ 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);
- /* 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);
+ /* 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, 0, 0, width, height);
- cairo_clip (cr);
- cairo_save (cr);
+ cairo_save (cr);
- cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
- cairo_rectangle (cr, 0, 0, width, height);
+ cairo_rectangle (cr, 0, 0, width, height);
+ cairo_clip (cr);
+ cairo_save (cr);
- gdk_window_get_position (entry->text_area, &pos_x, &pos_y);
- progress_x -= pos_x;
- progress_y -= pos_y;
+ cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
+ cairo_rectangle (cr, 0, 0, width, height);
- 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);
+ 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_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);
- draw_text_with_color (entry, cr, &bar_text_color);
- }
+ 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_is_drawable (widget))
- {
- 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;
+ }
- get_layout_position (entry, &x, &y);
+ 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;
- 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);
+ 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;
- cr = gdk_cairo_create (entry->text_area);
+ cairo_save (cr);
- _gtk_widget_get_cursor_color (widget, &cursor_color);
- gdk_cairo_set_source_color (cr, &cursor_color);
- gdk_cairo_rectangle (cr, &rect);
- cairo_fill (cr);
+ get_layout_position (entry, &x, &y);
- 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);
- }
+ 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);
+
+ _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);
}
}
gtk_entry_queue_draw (GtkEntry *entry)
{
if (gtk_widget_is_drawable (GTK_WIDGET (entry)))
- gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
+ gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (entry)),
+ NULL, FALSE);
}
void
_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;
*
* 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);
}
/**
- * gtk_entry_get_text_window:
+ * gtk_entry_get_text_area:
* @entry: a #GtkEntry
+ * @text_area: Return location for the text area.
*
- * Returns the #GdkWindow which contains the text. This function is
- * useful when drawing something to the entry in an expose-event
- * callback because it enables the callback to distinguish between
- * the text window and entry's icon windows.
+ * Gets the area where the entry's text is drawn. This function is
+ * useful when drawing something to the entry in a draw callback.
*
- * See also gtk_entry_get_icon_window().
+ * If the entry is not realized, @text_area is filled with zeros.
*
- * Return value: the entry's text window.
+ * See also gtk_entry_get_icon_area().
*
- * Since: 2.20
+ * Since: 3.0
**/
-GdkWindow *
-gtk_entry_get_text_window (GtkEntry *entry)
+void
+gtk_entry_get_text_area (GtkEntry *entry,
+ GdkRectangle *text_area)
{
- g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
+ g_return_if_fail (GTK_IS_ENTRY (entry));
+ g_return_if_fail (text_area != NULL);
- return entry->text_area;
-}
+ 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:
* 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
*/
{
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 &&
}
/**
- * gtk_entry_get_icon_window:
+ * gtk_entry_get_icon_area:
* @entry: A #GtkEntry
* @icon_pos: Icon position
+ * @icon_area: Return location for the icon's area
*
- * Returns the #GdkWindow which contains the entry's icon at
- * @icon_pos. This function is useful when drawing something to the
- * entry in an expose-event callback because it enables the callback
- * to distinguish between the text window and entry's icon windows.
+ * 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.
*
- * See also gtk_entry_get_text_window().
+ * If the entry is not realized or has no icon at the given position,
+ * @icon_area is filled with zeros.
*
- * Return value: the entry's icon window at @icon_pos.
+ * See also gtk_entry_get_text_area()
*
- * Since: 2.20
+ * Since: 3.0
*/
-GdkWindow *
-gtk_entry_get_icon_window (GtkEntry *entry,
- GtkEntryIconPosition icon_pos)
+void
+gtk_entry_get_icon_area (GtkEntry *entry,
+ GtkEntryIconPosition icon_pos,
+ GdkRectangle *icon_area)
{
GtkEntryPrivate *priv;
EntryIconInfo *icon_info;
- g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
+ 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)
- return icon_info->window;
+ {
+ GtkAllocation primary;
+ GtkAllocation secondary;
+
+ get_icon_allocations (entry, &primary, &secondary);
- return NULL;
+ 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
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);
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;
{
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;
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;
*
* 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
*/