mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-27 06:00:22 +00:00
testview: Convert _gtk_text_util_create_rich_drag_icon() to use surfaces
This commit is contained in:
parent
331999d84d
commit
4138e86ad4
@ -280,14 +280,14 @@ 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)
|
||||
{
|
||||
GtkAllocation allocation;
|
||||
GdkDrawable *drawable = NULL;
|
||||
cairo_surface_t *surface;
|
||||
gint pixmap_height, pixmap_width;
|
||||
gint layout_width, layout_height;
|
||||
GtkStyle *widget_style;
|
||||
@ -303,7 +303,7 @@ _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);
|
||||
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);
|
||||
@ -359,12 +359,14 @@ _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 (gtk_widget_get_window (widget),
|
||||
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);
|
||||
|
||||
cairo_save (cr);
|
||||
@ -383,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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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_,
|
||||
|
@ -6905,25 +6905,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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user