]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtktextutil.c
Verify GtkWidget invariants if G_ENABLE_DEBUG is defined
[~andy/gtk] / gtk / gtktextutil.c
index 3995bd174ba829572108f3eb0ad9805ccdd5172c..0ef71cf22cbdbdb7b48550a861e5b37c1887ac45 100644 (file)
@@ -35,7 +35,6 @@
 #include "gtktextbuffer.h"
 #include "gtkmenuitem.h"
 #include "gtkintl.h"
-#include "gtkalias.h"
 
 #define DRAG_ICON_MAX_WIDTH 250
 #define DRAG_ICON_MAX_HEIGHT 250
@@ -202,16 +201,19 @@ 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;
   gint          pixmap_height, pixmap_width;
   gint          layout_width, layout_height;
 
@@ -236,34 +238,32 @@ _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);
-
-  gdk_draw_rectangle (drawable,
-                      widget->style->base_gc [GTK_WIDGET_STATE (widget)],
-                      TRUE,
-                      0, 0,
-                      pixmap_width + 1,
-                      pixmap_height + 1);
-
-  gdk_draw_layout (drawable,
-                   widget->style->text_gc [GTK_WIDGET_STATE (widget)],
-                   1 + DRAG_ICON_LAYOUT_BORDER,
-                   1 + DRAG_ICON_LAYOUT_BORDER,
-                   layout);
-
-  gdk_draw_rectangle (drawable,
-                      widget->style->black_gc,
-                      FALSE,
-                      0, 0,
-                      pixmap_width + 1,
-                      pixmap_height + 1);
+  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);
+
+  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);
+  cairo_set_line_width (cr, 1.0);
+  cairo_stroke (cr);
+
+  cairo_destroy (cr);
   g_object_unref (layout);
 
-  return drawable;
+  cairo_surface_set_device_offset (surface, 2, 2);
+
+  return surface;
 }
 
 static void
@@ -280,26 +280,31 @@ 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;
   PangoContext      *ltr_context, *rtl_context;
   GtkTextIter        iter;
+  cairo_t           *cr;
 
    g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
    g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
    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);
 
@@ -321,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)
@@ -353,34 +359,35 @@ _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);
-
-   gdk_draw_rectangle (drawable,
-                       widget->style->base_gc [GTK_WIDGET_STATE (widget)],
-                       TRUE,
-                       0, 0,
-                       pixmap_width + 1,
-                       pixmap_height + 1);
-
-   gtk_text_layout_draw (layout, widget, drawable,
-                         widget->style->text_gc [GTK_WIDGET_STATE (widget)],
-                         - (1 + DRAG_ICON_LAYOUT_BORDER),
-                         - (1 + DRAG_ICON_LAYOUT_BORDER),
-                         0, 0,
-                         pixmap_width, pixmap_height, NULL);
-
-   gdk_draw_rectangle (drawable,
-                       widget->style->black_gc,
-                       FALSE,
-                       0, 0,
-                       pixmap_width + 1,
-                       pixmap_height + 1);
+   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)]);
+   cairo_paint (cr);
+
+   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);
+   cairo_set_line_width (cr, 1.0);
+   cairo_stroke (cr);
+
+   cairo_destroy (cr);
    g_object_unref (layout);
    g_object_unref (new_buffer);
 
-   return drawable;
+   cairo_surface_set_device_offset (surface, 2, 2);
+
+   return surface;
 }