From 3d340d744933891f5bfeb14324689f62115ba210 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 15 Aug 2010 16:53:27 +0200 Subject: [PATCH] text: Make _gtk_text_util_create_drag_icon() return a surface And change its callers to handle it that way. --- gtk/gtkentry.c | 16 ++++++---------- gtk/gtklabel.c | 20 ++++++++------------ gtk/gtktextutil.c | 20 +++++++++++--------- gtk/gtktextutil.h | 6 +++--- 4 files changed, 28 insertions(+), 34 deletions(-) diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index 4b0d1cade4..db01e750f5 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -3967,27 +3967,23 @@ gtk_entry_motion_notify (GtkWidget *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; diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index 9a2c0a4c4e..a98d087f53 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -4845,7 +4845,7 @@ drag_begin_cb (GtkWidget *widget, { GtkLabel *label = GTK_LABEL (widget); GtkLabelPrivate *priv = label->priv; - GdkPixmap *pixmap = NULL; + cairo_surface_t *surface = NULL; g_signal_handlers_disconnect_by_func (widget, drag_begin_cb, NULL); @@ -4869,22 +4869,18 @@ drag_begin_cb (GtkWidget *widget, if (start > len) start = len; - pixmap = _gtk_text_util_create_drag_icon (widget, - priv->text + start, - end - start); + surface = _gtk_text_util_create_drag_icon (widget, + priv->text + start, + end - start); } - 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) + g_object_unref (surface); } static gboolean diff --git a/gtk/gtktextutil.c b/gtk/gtktextutil.c index af869b9e3b..723a5eed9e 100644 --- a/gtk/gtktextutil.c +++ b/gtk/gtktextutil.c @@ -201,16 +201,16 @@ limit_layout_lines (PangoLayout *layout) * * Creates a drag and drop icon from @text. * - * Returns: a #GdkPixmap to use as DND icon + * Returns: a #cairo_surface_t to use as DND icon */ -GdkPixmap * +cairo_surface_t * _gtk_text_util_create_drag_icon (GtkWidget *widget, gchar *text, gsize len) { GtkStyle *style; GtkStateType state; - GdkDrawable *drawable = NULL; + cairo_surface_t *surface; PangoContext *context; PangoLayout *layout; cairo_t *cr; @@ -238,13 +238,13 @@ _gtk_text_util_create_drag_icon (GtkWidget *widget, pixmap_width = layout_width / PANGO_SCALE + DRAG_ICON_LAYOUT_BORDER * 2; pixmap_height = layout_height / PANGO_SCALE + DRAG_ICON_LAYOUT_BORDER * 2; - drawable = gdk_pixmap_new (gtk_widget_get_window (widget), - pixmap_width + 2, - pixmap_height + 2, - -1); - cr = gdk_cairo_create (drawable); style = gtk_widget_get_style (widget); state = gtk_widget_get_state (widget); + surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget), + CAIRO_CONTENT_COLOR, + pixmap_width + 2, + pixmap_height + 2); + cr = cairo_create (surface); gdk_cairo_set_source_color (cr, &style->base [state]); cairo_paint (cr); @@ -261,7 +261,9 @@ _gtk_text_util_create_drag_icon (GtkWidget *widget, cairo_destroy (cr); g_object_unref (layout); - return drawable; + cairo_surface_set_device_offset (surface, 2, 2); + + return surface; } static void diff --git a/gtk/gtktextutil.h b/gtk/gtktextutil.h index 8b346520bf..8aa7deb471 100644 --- a/gtk/gtktextutil.h +++ b/gtk/gtktextutil.h @@ -40,9 +40,9 @@ void _gtk_text_util_append_special_char_menuitems (GtkMenuShell *me GtkTextUtilCharChosenFunc func, gpointer data); -GdkPixmap* _gtk_text_util_create_drag_icon (GtkWidget *widget, - gchar *text, - gsize len); +cairo_surface_t * _gtk_text_util_create_drag_icon (GtkWidget *widget, + gchar *text, + gsize len); GdkPixmap* _gtk_text_util_create_rich_drag_icon (GtkWidget *widget, GtkTextBuffer *buffer, GtkTextIter *start,