[gtk/wip/otte/widgetfactory-dnd: 4/7] widget-factory: Add images that support dnd
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/widgetfactory-dnd: 4/7] widget-factory: Add images that support dnd
- Date: Tue, 27 Jul 2021 02:27:34 +0000 (UTC)
commit bb87cffaac5140819f50f1f6e8e77e0cdef540b7
Author: Benjamin Otte <otte redhat com>
Date: Mon Jul 26 02:35:09 2021 +0200
widget-factory: Add images that support dnd
Just use the bottom left notebook for a GtkPicture with custom drag
source and drop target.
demos/widget-factory/widget-factory.c | 33 +++++++++++++++++++++
demos/widget-factory/widget-factory.ui | 54 +++++++++++++++++++++++++++++-----
2 files changed, 79 insertions(+), 8 deletions(-)
---
diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c
index 5b10ecdd74..7d49469fe1 100644
--- a/demos/widget-factory/widget-factory.c
+++ b/demos/widget-factory/widget-factory.c
@@ -696,6 +696,37 @@ on_range_to_changed (GtkSpinButton *to)
gtk_spin_button_set_value (from, v2);
}
+static GdkContentProvider *
+on_picture_drag_prepare (GtkDragSource *source,
+ double x,
+ double y,
+ gpointer unused)
+{
+ GtkWidget *picture;
+
+ picture = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (source));
+
+ return gdk_content_provider_new_typed (GDK_TYPE_TEXTURE, gtk_picture_get_paintable (GTK_PICTURE
(picture)));
+}
+
+static gboolean
+on_picture_drop (GtkDropTarget *dest,
+ const GValue *value,
+ double x,
+ double y,
+ gpointer unused)
+{
+ GtkWidget *picture;
+ GdkPaintable *paintable;
+
+ picture = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (dest));
+ paintable = g_value_get_object (value);
+
+ gtk_picture_set_paintable (GTK_PICTURE (picture), paintable);
+
+ return TRUE;
+}
+
static void
info_bar_response (GtkWidget *infobar, int response_id)
{
@@ -2040,6 +2071,8 @@ activate (GApplication *app)
"on_page_combo_changed", (GCallback)on_page_combo_changed,
"on_range_from_changed", (GCallback)on_range_from_changed,
"on_range_to_changed", (GCallback)on_range_to_changed,
+ "on_picture_drag_prepare", (GCallback)on_picture_drag_prepare,
+ "on_picture_drop", (GCallback)on_picture_drop,
"tab_close_cb", (GCallback)tab_close_cb,
"increase_icon_size", (GCallback)increase_icon_size,
"decrease_icon_size", (GCallback)decrease_icon_size,
diff --git a/demos/widget-factory/widget-factory.ui b/demos/widget-factory/widget-factory.ui
index c37ade2945..684d5011a1 100644
--- a/demos/widget-factory/widget-factory.ui
+++ b/demos/widget-factory/widget-factory.ui
@@ -1251,8 +1251,21 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
<child>
<object class="GtkNotebookPage">
<property name="child">
- <object class="GtkBox" id="box6">
- <property name="orientation">vertical</property>
+ <object class="GtkPicture">
+ <property
name="file">resource:///org/gtk/WidgetFactory4/sunset.jpg</property>
+ <child>
+ <object class="GtkDragSource">
+ <property name="actions">copy</property>
+ <signal name="prepare" handler="on_picture_drag_prepare"
swapped="no"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkDropTarget">
+ <property name="actions">copy</property>
+ <property name="formats">GdkTexture</property>
+ <signal name="drop" handler="on_picture_drop" swapped="no"/>
+ </object>
+ </child>
</object>
</property>
<property name="tab">
@@ -1265,8 +1278,21 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
<child>
<object class="GtkNotebookPage">
<property name="child">
- <object class="GtkBox" id="box7">
- <property name="orientation">vertical</property>
+ <object class="GtkPicture">
+ <property
name="file">resource:///org/gtk/WidgetFactory4/sunset.jpg</property>
+ <child>
+ <object class="GtkDragSource">
+ <property name="actions">copy</property>
+ <signal name="prepare" handler="on_picture_drag_prepare"
swapped="no"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkDropTarget">
+ <property name="actions">copy</property>
+ <property name="formats">GdkTexture</property>
+ <signal name="drop" handler="on_picture_drop" swapped="no"/>
+ </object>
+ </child>
</object>
</property>
<property name="tab">
@@ -1278,10 +1304,22 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
</child>
<child>
<object class="GtkNotebookPage">
- <property name="position">2</property>
<property name="child">
- <object class="GtkBox" id="box8">
- <property name="orientation">vertical</property>
+ <object class="GtkPicture">
+ <property
name="file">resource:///org/gtk/WidgetFactory4/sunset.jpg</property>
+ <child>
+ <object class="GtkDragSource">
+ <property name="actions">copy</property>
+ <signal name="prepare" handler="on_picture_drag_prepare"
swapped="no"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkDropTarget">
+ <property name="actions">copy</property>
+ <property name="formats">GdkTexture</property>
+ <signal name="drop" handler="on_picture_drop" swapped="no"/>
+ </object>
+ </child>
</object>
</property>
<property name="tab">
@@ -1299,7 +1337,7 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
<child>
<object class="GtkNotebookPage">
<property name="child">
- <object class="GtkBox" id="box9">
+ <object class="GtkBox" id="box8">
<property name="orientation">vertical</property>
</object>
</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]