[gtk+/rendering-cleanup: 50/140] text: Make _gtk_text_util_create_drag_icon() return a surface



commit 53a3399d80e5b80f0c1cb89ada7e60810bf404fe
Author: Benjamin Otte <otte redhat com>
Date:   Sun Aug 15 16:53:27 2010 +0200

    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 1cccba9..a7eef39 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -4000,27 +4000,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 4ac3420..c4d01ea 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -4845,7 +4845,7 @@ drag_begin_cb (GtkWidget      *widget,
 {
   GtkLabel *label = GTK_LABEL (widget);
   GtkLabelPriv *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 af869b9..723a5ee 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 8b34652..8aa7deb 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,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]