]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtktextutil.c
Verify GtkWidget invariants if G_ENABLE_DEBUG is defined
[~andy/gtk] / gtk / gtktextutil.c
index 61eade84f0355b9fd41b235ca2bb3fd1357b27cc..0ef71cf22cbdbdb7b48550a861e5b37c1887ac45 100644 (file)
@@ -201,14 +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)
 {
-  GdkDrawable  *drawable = NULL;
+  GtkStyle     *style;
+  GtkStateType  state;
+  cairo_surface_t *surface;
   PangoContext *context;
   PangoLayout  *layout;
   cairo_t      *cr;
@@ -236,20 +238,20 @@ _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 (widget->window,
-                             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, &widget->style->base [gtk_widget_get_state (widget)]);
+  gdk_cairo_set_source_color (cr, &style->base [state]);
   cairo_paint (cr);
 
-  gdk_draw_layout (drawable,
-                   widget->style->text_gc [gtk_widget_get_state (widget)],
-                   1 + DRAG_ICON_LAYOUT_BORDER,
-                   1 + DRAG_ICON_LAYOUT_BORDER,
-                   layout);
+  gdk_cairo_set_source_color (cr, &style->text [state]);
+  cairo_move_to (cr, 1 + DRAG_ICON_LAYOUT_BORDER, 1 + DRAG_ICON_LAYOUT_BORDER);
+  pango_cairo_show_layout (cr, layout);
 
   cairo_set_source_rgb (cr, 0, 0, 0);
   cairo_rectangle (cr, 0.5, 0.5, pixmap_width + 1, pixmap_height + 1);
@@ -259,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
@@ -276,15 +280,17 @@ 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;
+  GtkAllocation      allocation;
+  cairo_surface_t   *surface;
   gint               pixmap_height, pixmap_width;
   gint               layout_width, layout_height;
+  GtkStyle          *widget_style;
   GtkTextBuffer     *new_buffer;
   GtkTextLayout     *layout;
   GtkTextAttributes *style;
@@ -297,6 +303,8 @@ _gtk_text_util_create_rich_drag_icon (GtkWidget     *widget,
    g_return_val_if_fail (start != NULL, NULL);
    g_return_val_if_fail (end != NULL, NULL);
 
+   widget_style = gtk_widget_get_style (widget);
+
    new_buffer = gtk_text_buffer_new (gtk_text_buffer_get_tag_table (buffer));
    gtk_text_buffer_get_start_iter (new_buffer, &iter);
 
@@ -318,13 +326,14 @@ _gtk_text_util_create_rich_drag_icon (GtkWidget     *widget,
 
    style = gtk_text_attributes_new ();
 
-   layout_width = widget->allocation.width;
+   gtk_widget_get_allocation (widget, &allocation);
+   layout_width = allocation.width;
 
    if (GTK_IS_TEXT_VIEW (widget))
      {
        gtk_widget_ensure_style (widget);
        gtk_text_view_set_attributes_from_style (GTK_TEXT_VIEW (widget),
-                                                style, widget->style);
+                                                style, widget_style);
 
        layout_width = layout_width
          - gtk_text_view_get_border_window_size (GTK_TEXT_VIEW (widget), GTK_TEXT_WINDOW_LEFT)
@@ -350,20 +359,22 @@ _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)]);
+   gdk_cairo_set_source_color (cr, &widget_style->base [gtk_widget_get_state (widget)]);
    cairo_paint (cr);
 
-   gtk_text_layout_draw (layout, widget, drawable,
-                         widget->style->text_gc [gtk_widget_get_state (widget)],
-                         - (1 + DRAG_ICON_LAYOUT_BORDER),
-                         - (1 + DRAG_ICON_LAYOUT_BORDER),
-                         0, 0,
-                         pixmap_width, pixmap_height, NULL);
+   cairo_save (cr);
+
+   cairo_translate (cr, 1 + DRAG_ICON_LAYOUT_BORDER, 1 + DRAG_ICON_LAYOUT_BORDER);
+   gtk_text_layout_draw (layout, widget, cr, NULL);
+
+   cairo_restore (cr);
 
    cairo_set_source_rgb (cr, 0, 0, 0);
    cairo_rectangle (cr, 0.5, 0.5, pixmap_width + 1, pixmap_height + 1);
@@ -374,7 +385,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;
 }