[gtk+/rendering-cleanup: 30/31] testview: Convert _gtk_text_util_create_rich_drag_icon() to use surfaces



commit d3527f0ce3760858301214ffb2aa1a46a86b3c2a
Author: Benjamin Otte <otte redhat com>
Date:   Sun Aug 15 21:24:55 2010 +0200

    testview: Convert _gtk_text_util_create_rich_drag_icon() to use surfaces

 gtk/gtktextutil.c |   16 ++++++++++------
 gtk/gtktextutil.h |    8 ++++----
 gtk/gtktextview.c |   22 +++++++++-------------
 3 files changed, 23 insertions(+), 23 deletions(-)
---
diff --git a/gtk/gtktextutil.c b/gtk/gtktextutil.c
index 08980fe..13cbbf6 100644
--- a/gtk/gtktextutil.c
+++ b/gtk/gtktextutil.c
@@ -276,13 +276,13 @@ gtk_text_view_set_attributes_from_style (GtkTextView        *text_view,
   values->font = pango_font_description_copy (style->font_desc);
 }
 
-GdkPixmap *
+cairo_surface_t *
 _gtk_text_util_create_rich_drag_icon (GtkWidget     *widget,
                                       GtkTextBuffer *buffer,
                                       GtkTextIter   *start,
                                       GtkTextIter   *end)
 {
-  GdkDrawable       *drawable = NULL;
+  cairo_surface_t   *surface;
   gint               pixmap_height, pixmap_width;
   gint               layout_width, layout_height;
   GtkTextBuffer     *new_buffer;
@@ -350,10 +350,12 @@ _gtk_text_util_create_rich_drag_icon (GtkWidget     *widget,
    pixmap_width  = layout_width + DRAG_ICON_LAYOUT_BORDER * 2;
    pixmap_height = layout_height + DRAG_ICON_LAYOUT_BORDER * 2;
 
-   drawable = gdk_pixmap_new (widget->window,
-                              pixmap_width  + 2, pixmap_height + 2, -1);
+   surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget),
+                                                CAIRO_CONTENT_COLOR,
+                                                pixmap_width  + 2,
+                                                pixmap_height + 2);
 
-   cr = gdk_cairo_create (drawable);
+   cr = cairo_create (surface);
 
    gdk_cairo_set_source_color (cr, &widget->style->base [gtk_widget_get_state (widget)]);
    cairo_paint (cr);
@@ -374,7 +376,9 @@ _gtk_text_util_create_rich_drag_icon (GtkWidget     *widget,
    g_object_unref (layout);
    g_object_unref (new_buffer);
 
-   return drawable;
+   cairo_surface_set_device_offset (surface, 2, 2);
+
+   return surface;
 }
 
 
diff --git a/gtk/gtktextutil.h b/gtk/gtktextutil.h
index 8aa7deb..358ead7 100644
--- a/gtk/gtktextutil.h
+++ b/gtk/gtktextutil.h
@@ -43,10 +43,10 @@ void _gtk_text_util_append_special_char_menuitems (GtkMenuShell              *me
 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,
-                                                 GtkTextIter   *end);
+cairo_surface_t * _gtk_text_util_create_rich_drag_icon (GtkWidget     *widget,
+                                                   GtkTextBuffer *buffer,
+                                                   GtkTextIter   *start,
+                                                   GtkTextIter   *end);
 
 gboolean _gtk_text_util_get_block_cursor_location (PangoLayout    *layout,
 						   gint            index_,
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 5baa390..7291633 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -6907,25 +6907,21 @@ drag_begin_cb (GtkWidget      *widget,
                GdkDragContext *context,
                gpointer        data)
 {
-  GtkTextView   *text_view = GTK_TEXT_VIEW (widget);
-  GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
-  GtkTextIter    start;
-  GtkTextIter    end;
-  GdkPixmap     *pixmap = NULL;
+  GtkTextView     *text_view = GTK_TEXT_VIEW (widget);
+  GtkTextBuffer   *buffer = gtk_text_view_get_buffer (text_view);
+  GtkTextIter      start;
+  GtkTextIter      end;
+  cairo_surface_t *surface = NULL;
 
   g_signal_handlers_disconnect_by_func (widget, drag_begin_cb, NULL);
 
   if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
-    pixmap = _gtk_text_util_create_rich_drag_icon (widget, buffer, &start, &end);
+    surface = _gtk_text_util_create_rich_drag_icon (widget, buffer, &start, &end);
 
-  if (pixmap)
+  if (surface)
     {
-      gtk_drag_set_icon_pixmap (context,
-                                gdk_drawable_get_colormap (pixmap),
-                                pixmap,
-                                NULL,
-                                -2, -2);
-      g_object_unref (pixmap);
+      gtk_drag_set_icon_surface (context, surface);
+      cairo_surface_destroy (surface);
     }
   else
     {



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