Index: gtk/gtktextutil.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktextutil.c,v
retrieving revision 1.15
diff -u -r1.15 gtktextutil.c
--- gtk/gtktextutil.c	13 Sep 2005 19:57:42 -0000	1.15
+++ gtk/gtktextutil.c	3 Feb 2006 21:40:36 -0000
@@ -27,11 +27,19 @@
 #include <config.h>
 #include "gtktextutil.h"
 #include "gtkintl.h"
+#include "gtktextview.h"
+
+#define GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
+
+#include "gtktextdisplay.h"
+#include "gtktextbuffer.h"
+#include "gtktextbufferserialize.h"
 #include "gtkmenuitem.h"
 #include "gtkalias.h"
 
 #define DRAG_ICON_MAX_WIDTH 250
-#define DRAG_ICON_LAYOUT_BORDER 2
+#define DRAG_ICON_MAX_HEIGHT 250
+#define DRAG_ICON_LAYOUT_BORDER 5
 #define DRAG_ICON_MAX_LINES 7
 #define ELLIPSIS_CHARACTER "\xe2\x80\xa6"
 
@@ -169,14 +177,20 @@
     }
 }
 
-/**
- * _gtk_text_util_create_drag_icon
- * @widget: #GtkWidget to extract the pango context
- * @text: a #gchar to render the icon
- * @len: length of @text, or -1 for NUL-terminated text
- *
- * Creates a drag and drop icon from @text.
- **/
+static void
+gtk_text_view_set_attributes_from_style (GtkTextView        *text_view,
+                                         GtkTextAttributes  *values,
+                                         GtkStyle           *style)
+{
+  values->appearance.bg_color = style->base[GTK_STATE_NORMAL];
+  values->appearance.fg_color = style->text[GTK_STATE_NORMAL];
+
+  if (values->font)
+    pango_font_description_free (values->font);
+
+  values->font = pango_font_description_copy (style->font_desc);
+}
+
 GdkPixmap*
 _gtk_text_util_create_drag_icon (GtkWidget *widget, 
                                  gchar     *text,
@@ -188,53 +202,103 @@
   gint          pixmap_height, pixmap_width;
   gint          layout_width, layout_height;
 
+  GtkTextBuffer *buffer;
+  GtkTextIter iter;
+
   g_return_val_if_fail (widget != NULL, NULL);
   g_return_val_if_fail (text != NULL, NULL);
 
-  context = gtk_widget_get_pango_context (widget);
-  layout  = pango_layout_new (context);
+  buffer = gtk_text_buffer_new (NULL);
+  gtk_text_buffer_get_start_iter (buffer, &iter);
+
+  if (_gtk_text_buffer_deserialize_rich_text (buffer, &iter,
+					      text, len,
+					      TRUE, NULL, NULL))
+    {
+      GtkTextLayout *layout;
+      GtkTextAttributes *style;
+      PangoContext *ltr_context, *rtl_context;
+      GtkTextView *text_view;
+      
+      layout = gtk_text_layout_new ();
+
+      ltr_context = gtk_widget_create_pango_context (widget);
+      pango_context_set_base_dir (ltr_context, PANGO_DIRECTION_LTR);
+      rtl_context = gtk_widget_create_pango_context (widget);
+      pango_context_set_base_dir (rtl_context, PANGO_DIRECTION_RTL);
+
+      gtk_text_layout_set_contexts (layout, ltr_context, rtl_context);
+
+      g_object_unref (ltr_context);
+      g_object_unref (rtl_context);
 
-  pango_layout_set_text (layout, text, len);
-  pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR);
-  pango_layout_get_size (layout, &layout_width, &layout_height);
-
-  layout_width = MIN (layout_width, DRAG_ICON_MAX_WIDTH * PANGO_SCALE);
-  pango_layout_set_width (layout, layout_width);
-
-  limit_layout_lines (layout);
-
-  /* get again layout extents, they may have changed */
-  pango_layout_get_size (layout, &layout_width, &layout_height);
-
-  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_text_attributes_new ();
 
-  g_object_unref (layout);
+      layout_width = widget->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);
+
+	  layout_width = layout_width
+	    - gtk_text_view_get_border_window_size (GTK_TEXT_VIEW (widget), GTK_TEXT_WINDOW_LEFT)
+	    - gtk_text_view_get_border_window_size (GTK_TEXT_VIEW (widget), GTK_TEXT_WINDOW_RIGHT);
+	}
+
+      style->direction = gtk_widget_get_direction (widget);
+      style->wrap_mode = PANGO_WRAP_WORD_CHAR;
+
+      gtk_text_layout_set_default_style (layout, style);
+      gtk_text_attributes_unref (style);
+
+      gtk_text_layout_set_buffer (layout, buffer);
+      gtk_text_layout_set_screen_width (layout, layout_width);
+
+      gtk_text_layout_validate (layout, DRAG_ICON_MAX_HEIGHT);
+      gtk_text_layout_get_size (layout, &layout_width, &layout_height);
+
+      g_print ("layout size %d %d\n", layout_width, layout_height);
+
+      layout_width = MIN (layout_width, DRAG_ICON_MAX_WIDTH);
+      layout_height = MIN (layout_height, DRAG_ICON_MAX_HEIGHT);
+
+      pixmap_width  = layout_width + DRAG_ICON_LAYOUT_BORDER * 2;
+      pixmap_height = layout_height + DRAG_ICON_LAYOUT_BORDER * 2;
+
+      g_print ("pixmap size %d %d\n", pixmap_width, pixmap_height);
+      
+      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);
+      
+      g_object_unref (layout);
+    }
+  else
+    g_print ("deserialized rich text FAILED\n");
+  
+
+  g_object_unref (buffer);
 
   return drawable;
 }
+
Index: gtk/gtktextview.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktextview.c,v
retrieving revision 1.304
diff -u -r1.304 gtktextview.c
--- gtk/gtktextview.c	21 Jan 2006 04:03:28 -0000	1.304
+++ gtk/gtktextview.c	3 Feb 2006 21:41:08 -0000
@@ -6011,13 +6017,22 @@
   GtkTextView *text_view;
   gchar *text;
   GdkPixmap *pixmap = NULL;
+  GtkTextIter start, end;
+  gsize len;
 
   g_signal_handlers_disconnect_by_func (widget, drag_begin_cb, NULL);
 
   text_view = GTK_TEXT_VIEW (widget);
 
-  text   = _gtk_text_view_get_selected_text (text_view);
-  pixmap = _gtk_text_util_create_drag_icon (widget, text, -1);
+  text = _gtk_text_view_get_selected_text (text_view);
+  if (gtk_text_buffer_get_selection_bounds (get_buffer (text_view), &start, &end))
+    {
+      /* Extract the selected text */
+      text = gtk_rich_text_serialize (get_buffer (text_view), 
+				      gdk_atom_intern ("application/x-gtk-text-buffer-rich-text", FALSE),
+				      &start, &end, &len);
+      pixmap = _gtk_text_util_create_drag_icon (widget, text, len);
+    }
 
   if (pixmap)
     gtk_drag_set_icon_pixmap (context,
