text: Make _gtk_text_util_create_drag_icon() return a surface

And change its callers to handle it that way.
This commit is contained in:
Benjamin Otte 2010-08-15 16:53:27 +02:00
parent 3dfb47bc3c
commit 3d340d7449
4 changed files with 28 additions and 34 deletions

View File

@ -3967,27 +3967,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;

View File

@ -4845,7 +4845,7 @@ drag_begin_cb (GtkWidget *widget,
{
GtkLabel *label = GTK_LABEL (widget);
GtkLabelPrivate *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

View File

@ -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

View File

@ -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,