Commit b90e8cfc authored by Colin Walters's avatar Colin Walters

gtkdnd: Add API that takes GIcon

This will be useful for me to port gnome-panel to gnome-menus 4, which
uses GAppInfo, which in turn returns icon references as GIcon.

https://bugzilla.gnome.org/show_bug.cgi?id=649295
parent e36c9dff
......@@ -5992,12 +5992,14 @@ gtk_drag_set_icon_pixbuf
gtk_drag_set_icon_stock
gtk_drag_set_icon_surface
gtk_drag_set_icon_name
gtk_drag_set_icon_gicon
gtk_drag_set_icon_default
gtk_drag_check_threshold
gtk_drag_source_set
gtk_drag_source_set_icon_pixbuf
gtk_drag_source_set_icon_stock
gtk_drag_source_set_icon_name
gtk_drag_source_set_icon_gicon
gtk_drag_source_unset
gtk_drag_source_set_target_list
gtk_drag_source_get_target_list
......
......@@ -749,6 +749,7 @@ gtk_drag_get_source_widget
gtk_drag_highlight
gtk_drag_result_get_type G_GNUC_CONST
gtk_drag_set_icon_default
gtk_drag_set_icon_gicon
gtk_drag_set_icon_name
gtk_drag_set_icon_pixbuf
gtk_drag_set_icon_stock
......@@ -759,6 +760,7 @@ gtk_drag_source_add_text_targets
gtk_drag_source_add_uri_targets
gtk_drag_source_get_target_list
gtk_drag_source_set
gtk_drag_source_set_icon_gicon
gtk_drag_source_set_icon_name
gtk_drag_source_set_icon_pixbuf
gtk_drag_source_set_icon_stock
......
......@@ -101,6 +101,7 @@ struct _GtkDragSourceSite
GtkImagePixbufData pixbuf;
GtkImageStockData stock;
GtkImageIconNameData name;
GtkImageGIconData gicon;
} icon_data;
/* Stored button press information to detect drag beginning */
......@@ -2477,6 +2478,11 @@ gtk_drag_begin_internal (GtkWidget *widget,
site->icon_data.name.icon_name,
-2, -2);
break;
case GTK_IMAGE_GICON:
gtk_drag_set_icon_gicon (context,
site->icon_data.gicon.icon,
-2, -2);
break;
case GTK_IMAGE_EMPTY:
default:
g_assert_not_reached();
......@@ -2830,6 +2836,9 @@ gtk_drag_source_unset_icon (GtkDragSourceSite *site)
case GTK_IMAGE_ICON_NAME:
g_free (site->icon_data.name.icon_name);
break;
case GTK_IMAGE_GICON:
_gtk_image_gicon_data_clear (&(site->icon_data.gicon));
break;
default:
g_assert_not_reached();
break;
......@@ -2919,6 +2928,34 @@ gtk_drag_source_set_icon_name (GtkWidget *widget,
site->icon_data.name.icon_name = g_strdup (icon_name);
}
/**
* gtk_drag_source_set_icon_gicon: (method)
* @widget: a #GtkWidget
* @icon: A #GIcon
*
* Sets the icon that will be used for drags from a particular source
* to @icon. See the docs for #GtkIconTheme for more details.
*
* Since: 3.2
**/
void
gtk_drag_source_set_icon_gicon (GtkWidget *widget,
GIcon *icon)
{
GtkDragSourceSite *site;
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (icon != NULL);
site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
g_return_if_fail (site != NULL);
gtk_drag_source_unset_icon (site);
site->icon_type = GTK_IMAGE_GICON;
site->icon_data.gicon.icon = g_object_ref (icon);
}
static void
gtk_drag_get_icon (GtkDragSourceInfo *info,
GtkWidget **icon_window,
......@@ -3375,15 +3412,46 @@ gtk_drag_set_icon_name (GdkDragContext *context,
const gchar *icon_name,
gint hot_x,
gint hot_y)
{
GIcon *icon;
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
g_return_if_fail (icon_name != NULL);
icon = g_themed_icon_new (icon_name);
gtk_drag_set_icon_gicon (context, icon, hot_x, hot_y);
g_object_unref (icon);
}
/**
* gtk_drag_set_icon_gicon:
* @context: the context for a drag. (This must be called
* with a context for the source side of a drag)
* @icon: a #GIcon
* @hot_x: the X offset of the hotspot within the icon
* @hot_y: the Y offset of the hotspot within the icon
*
* Sets the icon for a given drag from the given @icon. See the
* documentation for gtk_drag_set_icon_name() for more details about
* using icons in drag and drop.
*
* Since: 3.2
**/
void
gtk_drag_set_icon_gicon (GdkDragContext *context,
GIcon *icon,
gint hot_x,
gint hot_y)
{
GdkScreen *screen;
GtkSettings *settings;
GtkIconTheme *icon_theme;
GtkIconInfo *icon_info;
GdkPixbuf *pixbuf;
gint width, height, icon_size;
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
g_return_if_fail (icon_name != NULL);
g_return_if_fail (icon != NULL);
screen = gdk_window_get_screen (gdk_drag_context_get_source_window (context));
g_return_if_fail (screen != NULL);
......@@ -3398,12 +3466,22 @@ gtk_drag_set_icon_name (GdkDragContext *context,
icon_theme = gtk_icon_theme_get_for_screen (screen);
pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name,
icon_size, 0, NULL);
icon_info = gtk_icon_theme_lookup_by_gicon (icon_theme, icon, icon_size, 0);
if (icon_info != NULL)
{
pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
}
else
pixbuf = NULL;
if (pixbuf)
set_icon_stock_pixbuf (context, NULL, pixbuf, hot_x, hot_y, FALSE);
else
g_warning ("Cannot load drag icon from icon name %s", icon_name);
{
char *str = g_icon_to_string (icon);
g_warning ("Cannot load drag icon from GIcon '%s'", str);
g_free (str);
}
}
/**
......
......@@ -155,6 +155,8 @@ void gtk_drag_source_set_icon_stock (GtkWidget *widget,
const gchar *stock_id);
void gtk_drag_source_set_icon_name (GtkWidget *widget,
const gchar *icon_name);
void gtk_drag_source_set_icon_gicon (GtkWidget *widget,
GIcon *icon);
/* There probably should be functions for setting the targets
* as a GtkTargetList
......@@ -186,6 +188,10 @@ void gtk_drag_set_icon_name (GdkDragContext *context,
const gchar *icon_name,
gint hot_x,
gint hot_y);
void gtk_drag_set_icon_gicon (GdkDragContext *context,
GIcon *icon,
gint hot_x,
gint hot_y);
void gtk_drag_set_icon_default (GdkDragContext *context);
......
......@@ -2040,6 +2040,20 @@ gtk_image_update_size (GtkImage *image,
gtk_widget_queue_resize (widget);
}
void
_gtk_image_gicon_data_clear (GtkImageGIconData *data)
{
if (data->pixbuf)
{
g_object_unref (data->pixbuf);
data->pixbuf = NULL;
}
if (data->icon)
{
g_object_unref (data->icon);
data->icon = NULL;
}
}
/**
* gtk_image_set_pixel_size:
......
......@@ -75,6 +75,7 @@ struct _GtkImageGIconData
GdkPixbuf *pixbuf;
};
void _gtk_image_gicon_data_clear (GtkImageGIconData *data);
G_END_DECLS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment