Hello,
I had a question regarding GdkContentProvider
, specifically the function gdk_content_provider_new_union
as I’m trying to implement drag-n-drop using GtkDragSource
and GtkDropTarget
. My question is, is it possible to wrap two (or more) different types in a GdkContentProvider
array and then have access to them in the drop site?
For example, in the following snippet, I set the drag content in prepare_drag_content()
function using two objects of different types:
static void
on_drop (GtkDropTarget *target,
GValue *value,
gdouble x,
gdouble y,
GtkWidget *button)
{
// Use @value to access the drag content set earlier
}
static GdkContentProvider *
prepare_drag_content (CustomWidget *self,
GtkWidget *button)
{
/**
* Setting content for drag-n-drop:
* How to access these two objects in `on_drop` callback above?
*/
GdkContentProvider *content[2] = {
gdk_content_provider_new_typed (CUSTOM_TYPE_WIDGET, self),
gdk_content_provider_new_typed (GTK_TYPE_WIDGET, button)
};
return gdk_content_provider_new_union (content, 2);
}
static void
add_drag_source (CustomWidget *self,
GtkWidget *button)
{
GtkDragSource *source = gtk_drag_source_new ();
gtk_drag_source_set_content (source, prepare_drag_content (self, button)); // set the content for dnd
gtk_widget_add_controller (GTK_WIDGET (button), GTK_EVENT_CONTROLLER (source));
}
Currently, I have created a custom type that wraps the two objects and then I’m unpacking it using g_value_get_object
on the drop site (i have set the drop site to accept this custom type only for now). The issue with this is having to create a new custom type just for this operation.
Additionally, I am not clear on how GdkContentProvider
gets converted to GValue
mid-event.