2015-12-11 15:44:46 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2020-01-30 14:34:53 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#elif defined (G_OS_WIN32)
|
|
|
|
#include <io.h>
|
|
|
|
#endif
|
|
|
|
|
2020-02-06 16:10:13 +00:00
|
|
|
static GdkTexture *
|
|
|
|
render_paintable_to_texture (GdkPaintable *paintable)
|
|
|
|
{
|
|
|
|
GtkSnapshot *snapshot;
|
|
|
|
GskRenderNode *node;
|
|
|
|
int width, height;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *cr;
|
|
|
|
GdkTexture *texture;
|
|
|
|
GBytes *bytes;
|
|
|
|
|
|
|
|
width = gdk_paintable_get_intrinsic_width (paintable);
|
|
|
|
if (width == 0)
|
|
|
|
width = 32;
|
|
|
|
|
|
|
|
height = gdk_paintable_get_intrinsic_height (paintable);
|
|
|
|
if (height == 0)
|
|
|
|
height = 32;
|
|
|
|
|
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
|
|
|
|
|
|
|
|
snapshot = gtk_snapshot_new ();
|
|
|
|
gdk_paintable_snapshot (paintable, snapshot, width, height);
|
|
|
|
node = gtk_snapshot_free_to_node (snapshot);
|
|
|
|
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
gsk_render_node_draw (node, cr);
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
|
|
|
|
bytes = g_bytes_new_with_free_func (cairo_image_surface_get_data (surface),
|
|
|
|
cairo_image_surface_get_height (surface)
|
|
|
|
* cairo_image_surface_get_stride (surface),
|
|
|
|
(GDestroyNotify) cairo_surface_destroy,
|
|
|
|
cairo_surface_reference (surface));
|
|
|
|
texture = gdk_memory_texture_new (cairo_image_surface_get_width (surface),
|
|
|
|
cairo_image_surface_get_height (surface),
|
|
|
|
GDK_MEMORY_DEFAULT,
|
|
|
|
bytes,
|
|
|
|
cairo_image_surface_get_stride (surface));
|
|
|
|
g_bytes_unref (bytes);
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2020-01-28 09:30:01 +00:00
|
|
|
static GdkTexture *
|
2020-02-18 01:01:52 +00:00
|
|
|
get_image_texture (GtkImage *image)
|
2015-12-11 15:44:46 +00:00
|
|
|
{
|
|
|
|
GtkIconTheme *icon_theme;
|
2017-11-15 00:43:13 +00:00
|
|
|
const char *icon_name;
|
2017-11-15 04:30:58 +00:00
|
|
|
int width = 48;
|
2020-02-06 16:10:13 +00:00
|
|
|
GdkPaintable *paintable = NULL;
|
2020-01-28 09:30:01 +00:00
|
|
|
GdkTexture *texture = NULL;
|
2020-02-04 16:19:22 +00:00
|
|
|
GtkIconPaintable *icon;
|
2015-12-11 15:44:46 +00:00
|
|
|
|
|
|
|
switch (gtk_image_get_storage_type (image))
|
|
|
|
{
|
2018-03-15 01:59:03 +00:00
|
|
|
case GTK_IMAGE_PAINTABLE:
|
|
|
|
paintable = gtk_image_get_paintable (image);
|
2020-02-06 16:10:13 +00:00
|
|
|
break;
|
2015-12-11 15:44:46 +00:00
|
|
|
case GTK_IMAGE_ICON_NAME:
|
2017-01-22 21:58:45 +00:00
|
|
|
icon_name = gtk_image_get_icon_name (image);
|
2017-10-31 01:59:06 +00:00
|
|
|
icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET (image)));
|
2020-02-01 23:27:14 +00:00
|
|
|
icon = gtk_icon_theme_lookup_icon (icon_theme,
|
|
|
|
icon_name,
|
2020-02-04 02:53:22 +00:00
|
|
|
NULL,
|
2020-02-01 23:27:14 +00:00
|
|
|
width, 1,
|
|
|
|
gtk_widget_get_direction (GTK_WIDGET (image)),
|
2020-02-04 03:26:19 +00:00
|
|
|
0);
|
2020-02-06 16:10:13 +00:00
|
|
|
paintable = GDK_PAINTABLE (icon);
|
|
|
|
break;
|
2020-03-06 17:05:43 +00:00
|
|
|
case GTK_IMAGE_GICON:
|
|
|
|
case GTK_IMAGE_EMPTY:
|
2015-12-11 15:44:46 +00:00
|
|
|
default:
|
|
|
|
g_warning ("Image storage type %d not handled",
|
|
|
|
gtk_image_get_storage_type (image));
|
|
|
|
}
|
2020-01-28 09:30:01 +00:00
|
|
|
|
2020-02-06 16:10:13 +00:00
|
|
|
if (paintable)
|
|
|
|
texture = render_paintable_to_texture (paintable);
|
|
|
|
|
|
|
|
g_object_unref (paintable);
|
|
|
|
|
2020-01-28 09:30:01 +00:00
|
|
|
return texture;
|
2015-12-11 15:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum {
|
|
|
|
TOP_LEFT,
|
|
|
|
CENTER,
|
|
|
|
BOTTOM_RIGHT
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-01-02 06:31:14 +00:00
|
|
|
got_texture (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer data)
|
2015-12-11 15:44:46 +00:00
|
|
|
{
|
2020-01-02 06:31:14 +00:00
|
|
|
GdkDrop *drop = GDK_DROP (source);
|
|
|
|
GtkWidget *image = data;
|
|
|
|
const GValue *value;
|
|
|
|
GError *error = NULL;
|
2015-12-11 15:44:46 +00:00
|
|
|
|
2020-01-02 06:31:14 +00:00
|
|
|
value = gdk_drop_read_value_finish (drop, result, &error);
|
|
|
|
if (value)
|
2015-12-11 15:44:46 +00:00
|
|
|
{
|
2020-01-02 06:31:14 +00:00
|
|
|
GdkTexture *texture = g_value_get_object (value);
|
|
|
|
gtk_image_set_from_paintable (GTK_IMAGE (image), GDK_PAINTABLE (texture));
|
|
|
|
gdk_drop_finish (drop, GDK_ACTION_COPY);
|
2017-11-16 21:50:37 +00:00
|
|
|
}
|
2020-01-02 06:31:14 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
g_error_free (error);
|
|
|
|
gdk_drop_finish (drop, 0);
|
|
|
|
}
|
2020-01-04 17:09:58 +00:00
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (image), "drop", NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
perform_drop (GdkDrop *drop,
|
|
|
|
GtkWidget *image)
|
|
|
|
{
|
2020-02-29 02:47:17 +00:00
|
|
|
if (gdk_content_formats_contain_gtype (gdk_drop_get_formats (drop), GDK_TYPE_TEXTURE))
|
2020-01-04 17:09:58 +00:00
|
|
|
gdk_drop_read_value_async (drop, GDK_TYPE_TEXTURE, G_PRIORITY_DEFAULT, NULL, got_texture, image);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gdk_drop_finish (drop, 0);
|
|
|
|
g_object_set_data (G_OBJECT (image), "drop", NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_copy (GtkWidget *button)
|
|
|
|
{
|
|
|
|
GtkWidget *popover = gtk_widget_get_ancestor (button, GTK_TYPE_POPOVER);
|
2020-02-24 12:21:46 +00:00
|
|
|
GtkWidget *image = gtk_widget_get_parent (popover);
|
2020-01-04 17:09:58 +00:00
|
|
|
GdkDrop *drop = GDK_DROP (g_object_get_data (G_OBJECT (image), "drop"));
|
|
|
|
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (popover));
|
|
|
|
perform_drop (drop, image);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_cancel (GtkWidget *button)
|
|
|
|
{
|
|
|
|
GtkWidget *popover = gtk_widget_get_ancestor (button, GTK_TYPE_POPOVER);
|
2020-02-24 12:21:46 +00:00
|
|
|
GtkWidget *image = gtk_widget_get_parent (popover);
|
2020-01-04 17:09:58 +00:00
|
|
|
GdkDrop *drop = GDK_DROP (g_object_get_data (G_OBJECT (image), "drop"));
|
|
|
|
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (popover));
|
|
|
|
gdk_drop_finish (drop, 0);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (image), "drop", NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ask_actions (GdkDrop *drop,
|
|
|
|
GtkWidget *image)
|
|
|
|
{
|
|
|
|
GtkWidget *popover, *box, *button;
|
|
|
|
|
|
|
|
popover = g_object_get_data (G_OBJECT (image), "popover");
|
|
|
|
if (!popover)
|
|
|
|
{
|
2020-02-24 12:21:46 +00:00
|
|
|
popover = gtk_popover_new ();
|
|
|
|
gtk_widget_set_parent (popover, image);
|
2020-01-04 17:09:58 +00:00
|
|
|
g_object_set_data (G_OBJECT (image), "popover", popover);
|
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
gtk_container_add (GTK_CONTAINER (popover), box);
|
|
|
|
button = gtk_button_new_with_label ("Copy");
|
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (do_copy), NULL);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), button);
|
|
|
|
button = gtk_button_new_with_label ("Move");
|
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (do_copy), NULL);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), button);
|
|
|
|
button = gtk_button_new_with_label ("Cancel");
|
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (do_cancel), NULL);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), button);
|
|
|
|
}
|
|
|
|
gtk_popover_popup (GTK_POPOVER (popover));
|
2020-01-02 06:31:14 +00:00
|
|
|
}
|
|
|
|
|
2020-01-08 22:07:30 +00:00
|
|
|
static gboolean
|
|
|
|
delayed_deny (gpointer data)
|
|
|
|
{
|
2020-02-29 02:47:17 +00:00
|
|
|
GtkDropTargetAsync *dest = data;
|
2020-01-08 22:07:30 +00:00
|
|
|
GtkWidget *image = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (dest));
|
|
|
|
GdkDrop *drop = GDK_DROP (g_object_get_data (G_OBJECT (image), "drop"));
|
|
|
|
|
|
|
|
if (drop)
|
|
|
|
{
|
|
|
|
g_print ("denying drop, late\n");
|
2020-02-29 02:47:17 +00:00
|
|
|
gtk_drop_target_async_reject_drop (dest, drop);
|
2020-01-08 22:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2020-02-29 02:47:17 +00:00
|
|
|
image_drag_accept (GtkDropTargetAsync *dest,
|
|
|
|
GdkDrop *drop,
|
|
|
|
gpointer data)
|
2020-01-08 22:07:30 +00:00
|
|
|
{
|
|
|
|
GtkWidget *image = data;
|
|
|
|
g_object_set_data_full (G_OBJECT (image), "drop", g_object_ref (drop), g_object_unref);
|
|
|
|
|
|
|
|
g_timeout_add (1000, delayed_deny, dest);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-01-02 06:31:14 +00:00
|
|
|
static gboolean
|
|
|
|
image_drag_drop (GtkDropTarget *dest,
|
2020-01-08 04:31:48 +00:00
|
|
|
GdkDrop *drop,
|
2020-02-29 02:47:17 +00:00
|
|
|
double x,
|
|
|
|
double y,
|
2020-01-02 06:31:14 +00:00
|
|
|
gpointer data)
|
|
|
|
{
|
2020-01-04 17:09:58 +00:00
|
|
|
GtkWidget *image = data;
|
|
|
|
GdkDragAction action = gdk_drop_get_actions (drop);
|
2020-01-01 02:10:15 +00:00
|
|
|
|
2020-01-04 17:09:58 +00:00
|
|
|
g_object_set_data_full (G_OBJECT (image), "drop", g_object_ref (drop), g_object_unref);
|
2020-01-02 06:31:14 +00:00
|
|
|
|
2020-01-04 17:09:58 +00:00
|
|
|
g_print ("drop, actions %d\n", action);
|
|
|
|
if (!gdk_drag_action_is_unique (action))
|
|
|
|
ask_actions (drop, image);
|
|
|
|
else
|
|
|
|
perform_drop (drop, image);
|
|
|
|
|
|
|
|
return TRUE;
|
2020-01-01 02:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_source_icon (GtkDragSource *source,
|
|
|
|
const char *icon_name,
|
|
|
|
int hotspot)
|
|
|
|
{
|
2020-02-01 23:27:14 +00:00
|
|
|
GtkWidget *widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (source));
|
2020-02-04 16:19:22 +00:00
|
|
|
GtkIconPaintable *icon;
|
2020-01-01 02:10:15 +00:00
|
|
|
int hot_x, hot_y;
|
|
|
|
int size = 48;
|
|
|
|
|
2020-02-06 16:10:13 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return;
|
|
|
|
|
2020-02-01 23:27:14 +00:00
|
|
|
icon = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_for_display (gtk_widget_get_display (widget)),
|
|
|
|
icon_name,
|
2020-02-04 02:53:22 +00:00
|
|
|
NULL,
|
2020-02-01 23:27:14 +00:00
|
|
|
size, 1,
|
2020-02-07 07:44:46 +00:00
|
|
|
gtk_widget_get_direction (widget),
|
2020-02-01 23:27:14 +00:00
|
|
|
0);
|
2020-01-01 02:10:15 +00:00
|
|
|
switch (hotspot)
|
2017-11-16 21:50:37 +00:00
|
|
|
{
|
2020-01-01 02:10:15 +00:00
|
|
|
default:
|
|
|
|
case TOP_LEFT:
|
|
|
|
hot_x = 0;
|
|
|
|
hot_y = 0;
|
|
|
|
break;
|
|
|
|
case CENTER:
|
|
|
|
hot_x = size / 2;
|
|
|
|
hot_y = size / 2;
|
|
|
|
break;
|
|
|
|
case BOTTOM_RIGHT:
|
|
|
|
hot_x = size;
|
|
|
|
hot_y = size;
|
|
|
|
break;
|
2015-12-11 15:44:46 +00:00
|
|
|
}
|
2020-01-28 09:30:01 +00:00
|
|
|
gtk_drag_source_set_icon (source, GDK_PAINTABLE (icon), hot_x, hot_y);
|
|
|
|
g_object_unref (icon);
|
2015-12-11 15:44:46 +00:00
|
|
|
}
|
|
|
|
|
2020-02-18 01:01:52 +00:00
|
|
|
static GdkContentProvider *
|
|
|
|
drag_prepare (GtkDragSource *source,
|
|
|
|
double x,
|
|
|
|
double y)
|
2015-12-11 15:44:46 +00:00
|
|
|
{
|
2020-02-18 01:01:52 +00:00
|
|
|
GtkImage *image = GTK_IMAGE (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (source)));
|
|
|
|
GdkTexture *texture;
|
|
|
|
GdkContentProvider *content;
|
2015-12-11 15:44:46 +00:00
|
|
|
|
2020-02-18 01:01:52 +00:00
|
|
|
content = gdk_content_provider_new_typed (G_TYPE_STRING, gtk_image_get_icon_name (GTK_IMAGE (image)));
|
2015-12-11 15:44:46 +00:00
|
|
|
|
2020-02-18 01:01:52 +00:00
|
|
|
texture = get_image_texture (image);
|
|
|
|
if (texture)
|
2020-01-01 02:10:15 +00:00
|
|
|
{
|
2020-02-18 01:01:52 +00:00
|
|
|
content = gdk_content_provider_new_union ((GdkContentProvider *[2]) {
|
|
|
|
gdk_content_provider_new_typed (GDK_TYPE_TEXTURE, texture),
|
|
|
|
content,
|
|
|
|
}, 2);
|
|
|
|
g_object_unref (texture);
|
2020-01-01 02:10:15 +00:00
|
|
|
}
|
2015-12-11 15:44:46 +00:00
|
|
|
|
2020-02-18 01:01:52 +00:00
|
|
|
return content;
|
2020-01-01 02:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drag_begin (GtkDragSource *source)
|
|
|
|
{
|
|
|
|
g_print ("drag begin\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drag_end (GtkDragSource *source)
|
|
|
|
{
|
|
|
|
g_print ("drag end\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2020-01-07 01:30:14 +00:00
|
|
|
drag_cancel (GtkDragSource *source,
|
2020-01-06 18:28:25 +00:00
|
|
|
GdkDrag *drag,
|
|
|
|
GdkDragCancelReason reason)
|
2020-01-01 02:10:15 +00:00
|
|
|
{
|
|
|
|
g_print ("drag failed: %d\n", reason);
|
|
|
|
return FALSE;
|
2015-12-11 15:44:46 +00:00
|
|
|
}
|
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
static GtkWidget *
|
2020-01-01 02:10:15 +00:00
|
|
|
make_image (const gchar *icon_name, int hotspot)
|
2016-04-21 18:21:14 +00:00
|
|
|
{
|
2017-08-01 22:49:42 +00:00
|
|
|
GtkWidget *image;
|
2020-01-01 02:10:15 +00:00
|
|
|
GtkDragSource *source;
|
2020-02-29 02:47:17 +00:00
|
|
|
GtkDropTargetAsync *dest;
|
2020-01-01 02:10:15 +00:00
|
|
|
GdkContentFormats *formats;
|
2020-01-07 05:46:37 +00:00
|
|
|
GdkContentFormatsBuilder *builder;
|
2016-04-21 18:21:14 +00:00
|
|
|
|
2017-11-15 00:43:13 +00:00
|
|
|
image = gtk_image_new_from_icon_name (icon_name);
|
2017-11-15 02:14:47 +00:00
|
|
|
gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
|
2016-04-21 18:21:14 +00:00
|
|
|
|
2020-01-07 05:46:37 +00:00
|
|
|
builder = gdk_content_formats_builder_new ();
|
|
|
|
gdk_content_formats_builder_add_gtype (builder, GDK_TYPE_TEXTURE);
|
|
|
|
gdk_content_formats_builder_add_gtype (builder, G_TYPE_STRING);
|
|
|
|
formats = gdk_content_formats_builder_free_to_formats (builder);
|
2016-04-21 18:21:14 +00:00
|
|
|
|
2020-01-06 19:46:14 +00:00
|
|
|
source = gtk_drag_source_new ();
|
|
|
|
gtk_drag_source_set_actions (source, GDK_ACTION_COPY|GDK_ACTION_MOVE|GDK_ACTION_ASK);
|
2020-01-01 02:10:15 +00:00
|
|
|
update_source_icon (source, icon_name, hotspot);
|
2016-04-21 18:21:14 +00:00
|
|
|
|
2020-02-18 01:01:52 +00:00
|
|
|
g_signal_connect (source, "prepare", G_CALLBACK (drag_prepare), NULL);
|
2020-01-01 02:10:15 +00:00
|
|
|
g_signal_connect (source, "drag-begin", G_CALLBACK (drag_begin), NULL);
|
|
|
|
g_signal_connect (source, "drag-end", G_CALLBACK (drag_end), NULL);
|
2020-01-07 01:30:14 +00:00
|
|
|
g_signal_connect (source, "drag-cancel", G_CALLBACK (drag_cancel), NULL);
|
2020-01-07 06:13:11 +00:00
|
|
|
gtk_widget_add_controller (image, GTK_EVENT_CONTROLLER (source));
|
2016-04-21 18:21:14 +00:00
|
|
|
|
2020-02-29 02:47:17 +00:00
|
|
|
dest = gtk_drop_target_async_new (formats, GDK_ACTION_COPY|GDK_ACTION_MOVE|GDK_ACTION_ASK);
|
|
|
|
g_signal_connect (dest, "accept", G_CALLBACK (image_drag_accept), image);
|
|
|
|
g_signal_connect (dest, "drop", G_CALLBACK (image_drag_drop), image);
|
2020-01-06 05:12:21 +00:00
|
|
|
gtk_widget_add_controller (image, GTK_EVENT_CONTROLLER (dest));
|
2020-01-02 06:31:14 +00:00
|
|
|
|
2017-08-01 22:49:42 +00:00
|
|
|
return image;
|
2016-04-21 18:21:14 +00:00
|
|
|
}
|
|
|
|
|
2015-12-11 15:44:46 +00:00
|
|
|
static void
|
2020-01-01 02:10:15 +00:00
|
|
|
spinner_drag_begin (GtkDragSource *source,
|
2020-01-06 18:28:25 +00:00
|
|
|
GdkDrag *drag,
|
|
|
|
GtkWidget *widget)
|
2015-12-13 21:01:05 +00:00
|
|
|
{
|
2020-01-01 02:10:15 +00:00
|
|
|
GdkPaintable *paintable;
|
2015-12-13 21:01:05 +00:00
|
|
|
|
2020-01-01 02:10:15 +00:00
|
|
|
paintable = gtk_widget_paintable_new (widget);
|
|
|
|
gtk_drag_source_set_icon (source, paintable, 0, 0);
|
|
|
|
g_object_unref (paintable);
|
2015-12-11 15:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
make_spinner (void)
|
|
|
|
{
|
2017-08-01 22:49:42 +00:00
|
|
|
GtkWidget *spinner;
|
2020-01-01 02:10:15 +00:00
|
|
|
GtkDragSource *source;
|
|
|
|
GdkContentProvider *content;
|
2015-12-11 15:44:46 +00:00
|
|
|
|
|
|
|
spinner = gtk_spinner_new ();
|
|
|
|
gtk_spinner_start (GTK_SPINNER (spinner));
|
|
|
|
|
2020-02-16 13:24:03 +00:00
|
|
|
content = gdk_content_provider_new_typed (G_TYPE_STRING, "ACTIVE");
|
2020-01-06 19:46:14 +00:00
|
|
|
source = gtk_drag_source_new ();
|
|
|
|
gtk_drag_source_set_content (source, content);
|
2020-01-01 02:10:15 +00:00
|
|
|
g_signal_connect (source, "drag-begin", G_CALLBACK (spinner_drag_begin), spinner);
|
2020-01-07 06:13:11 +00:00
|
|
|
gtk_widget_add_controller (spinner, GTK_EVENT_CONTROLLER (source));
|
2015-12-11 15:44:46 +00:00
|
|
|
|
2020-01-01 02:10:15 +00:00
|
|
|
g_object_unref (content);
|
2015-12-11 15:44:46 +00:00
|
|
|
|
2017-08-01 22:49:42 +00:00
|
|
|
return spinner;
|
2015-12-11 15:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *Argv[])
|
|
|
|
{
|
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *grid;
|
|
|
|
GtkWidget *entry;
|
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2015-12-11 15:44:46 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2015-12-11 15:44:46 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Drag And Drop");
|
|
|
|
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
|
|
|
|
|
|
|
|
grid = gtk_grid_new ();
|
|
|
|
g_object_set (grid,
|
2020-02-26 01:57:20 +00:00
|
|
|
"margin-start", 20,
|
|
|
|
"margin-end", 20,
|
|
|
|
"margin-top", 20,
|
|
|
|
"margin-bottom", 20,
|
2015-12-11 15:44:46 +00:00
|
|
|
"row-spacing", 20,
|
|
|
|
"column-spacing", 20,
|
|
|
|
NULL);
|
|
|
|
gtk_container_add (GTK_CONTAINER (window), grid);
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), make_image ("dialog-warning", TOP_LEFT), 0, 0, 1, 1);
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), make_image ("process-stop", BOTTOM_RIGHT), 1, 0, 1, 1);
|
|
|
|
|
|
|
|
entry = gtk_entry_new ();
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), entry, 0, 1, 2, 1);
|
|
|
|
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), make_spinner (), 0, 2, 1, 1);
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), make_image ("weather-clear", CENTER), 1, 2, 1, 1);
|
|
|
|
|
2020-01-01 02:10:15 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), make_image ("dialog-question", TOP_LEFT), 0, 3, 1, 1);
|
2016-04-21 18:21:14 +00:00
|
|
|
|
2020-01-01 02:10:15 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (grid), make_image ("dialog-information", CENTER), 1, 3, 1, 1);
|
2016-04-26 04:19:02 +00:00
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2020-02-10 03:24:47 +00:00
|
|
|
while (TRUE)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2015-12-11 15:44:46 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|