2017-12-06 00:22:06 +00:00
|
|
|
/* Drag-and-Drop
|
|
|
|
*
|
|
|
|
* I can't believe its not glade!
|
2019-12-24 03:14:52 +00:00
|
|
|
*
|
|
|
|
* Try right-clicking in the window.
|
2017-12-06 00:22:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2017-12-07 04:10:56 +00:00
|
|
|
typedef struct _GtkDemoWidget GtkDemoWidget;
|
2017-12-06 00:22:06 +00:00
|
|
|
struct _GtkDemoWidget
|
|
|
|
{
|
2017-12-07 04:10:56 +00:00
|
|
|
GType type;
|
|
|
|
union {
|
|
|
|
char *text;
|
|
|
|
gboolean active;
|
|
|
|
};
|
2017-12-06 00:22:06 +00:00
|
|
|
};
|
|
|
|
|
2017-12-07 04:10:56 +00:00
|
|
|
static gpointer
|
|
|
|
copy_demo_widget (gpointer data)
|
2017-12-06 00:22:06 +00:00
|
|
|
{
|
2017-12-07 04:10:56 +00:00
|
|
|
GtkDemoWidget *demo = g_memdup (data, sizeof (GtkDemoWidget));
|
|
|
|
|
|
|
|
if (demo->type == GTK_TYPE_LABEL)
|
|
|
|
demo->text = g_strdup (demo->text);
|
|
|
|
|
|
|
|
return demo;
|
2017-12-06 00:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-12-07 04:10:56 +00:00
|
|
|
free_demo_widget (gpointer data)
|
2017-12-06 00:22:06 +00:00
|
|
|
{
|
2017-12-07 04:10:56 +00:00
|
|
|
GtkDemoWidget *demo = data;
|
|
|
|
|
|
|
|
if (demo->type == GTK_TYPE_LABEL)
|
|
|
|
g_free (demo->text);
|
2017-12-06 00:22:06 +00:00
|
|
|
|
2017-12-07 04:10:56 +00:00
|
|
|
g_free (demo);
|
2017-12-06 00:22:06 +00:00
|
|
|
}
|
|
|
|
|
2017-12-07 04:10:56 +00:00
|
|
|
#define GTK_TYPE_DEMO_WIDGET (gtk_demo_widget_get_type ())
|
2020-03-07 14:01:21 +00:00
|
|
|
static GType gtk_demo_widget_get_type (void);
|
2017-12-07 04:10:56 +00:00
|
|
|
G_DEFINE_BOXED_TYPE (GtkDemoWidget, gtk_demo_widget, copy_demo_widget, free_demo_widget)
|
|
|
|
|
|
|
|
static GtkDemoWidget *
|
|
|
|
serialize_widget (GtkWidget *widget)
|
2017-12-06 00:22:06 +00:00
|
|
|
{
|
2017-12-07 04:10:56 +00:00
|
|
|
GtkDemoWidget *demo;
|
|
|
|
|
|
|
|
demo = g_new0 (GtkDemoWidget, 1);
|
|
|
|
demo->type = G_OBJECT_TYPE (widget);
|
2017-12-06 00:22:06 +00:00
|
|
|
|
2017-12-07 04:10:56 +00:00
|
|
|
if (GTK_IS_LABEL (widget))
|
|
|
|
{
|
|
|
|
demo->text = g_strdup (gtk_label_get_text (GTK_LABEL (widget)));
|
|
|
|
}
|
|
|
|
else if (GTK_IS_SPINNER (widget))
|
|
|
|
{
|
2020-02-25 02:04:49 +00:00
|
|
|
g_object_get (widget, "spinning", &demo->active, NULL);
|
2017-12-07 04:10:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_print ("Type %s not supported\n", g_type_name (demo->type));
|
|
|
|
}
|
2017-12-06 00:22:06 +00:00
|
|
|
|
2017-12-07 04:10:56 +00:00
|
|
|
return demo;
|
2017-12-06 00:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
2017-12-07 04:10:56 +00:00
|
|
|
deserialize_widget (GtkDemoWidget *demo)
|
2017-12-06 00:22:06 +00:00
|
|
|
{
|
2017-12-07 04:10:56 +00:00
|
|
|
GtkWidget *widget = NULL;
|
|
|
|
|
|
|
|
if (demo->type == GTK_TYPE_LABEL)
|
|
|
|
{
|
|
|
|
widget = gtk_label_new (demo->text);
|
|
|
|
}
|
|
|
|
else if (demo->type == GTK_TYPE_SPINNER)
|
|
|
|
{
|
2020-02-25 02:04:49 +00:00
|
|
|
widget = g_object_new (demo->type, "spinning", demo->active, NULL);
|
2020-04-10 16:08:16 +00:00
|
|
|
gtk_widget_add_css_class (widget, "demo");
|
2017-12-07 04:10:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_print ("Type %s not supported\n", g_type_name (demo->type));
|
|
|
|
}
|
|
|
|
|
|
|
|
return widget;
|
2017-12-06 00:22:06 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 01:45:39 +00:00
|
|
|
static double pos_x, pos_y;
|
|
|
|
|
2017-12-06 00:22:06 +00:00
|
|
|
static void
|
2019-12-27 03:30:23 +00:00
|
|
|
new_label_cb (GtkWidget *button,
|
2017-12-06 01:45:39 +00:00
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkFixed *fixed = data;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
widget = gtk_label_new ("Label");
|
|
|
|
gtk_fixed_put (fixed, widget, pos_x, pos_y);
|
2019-12-27 03:30:23 +00:00
|
|
|
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (gtk_widget_get_ancestor (button, GTK_TYPE_POPOVER)));
|
2017-12-06 01:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-12-27 03:30:23 +00:00
|
|
|
new_spinner_cb (GtkWidget *button,
|
2017-12-06 01:45:39 +00:00
|
|
|
gpointer data)
|
2017-12-06 00:22:06 +00:00
|
|
|
{
|
2017-12-06 01:45:39 +00:00
|
|
|
GtkFixed *fixed = data;
|
2017-12-06 00:22:06 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
|
2017-12-06 01:45:39 +00:00
|
|
|
widget = gtk_spinner_new ();
|
2020-04-10 16:08:16 +00:00
|
|
|
gtk_widget_add_css_class (widget, "demo");
|
2017-12-06 01:45:39 +00:00
|
|
|
gtk_spinner_start (GTK_SPINNER (widget));
|
|
|
|
gtk_fixed_put (fixed, widget, pos_x, pos_y);
|
2019-12-27 03:30:23 +00:00
|
|
|
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (gtk_widget_get_ancestor (button, GTK_TYPE_POPOVER)));
|
2017-12-06 01:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-12-27 03:30:23 +00:00
|
|
|
copy_cb (GtkWidget *button, GtkWidget *child)
|
2017-12-06 01:45:39 +00:00
|
|
|
{
|
|
|
|
GdkClipboard *clipboard;
|
2017-12-07 04:10:56 +00:00
|
|
|
GtkDemoWidget *demo;
|
2017-12-06 01:45:39 +00:00
|
|
|
|
2017-12-07 04:10:56 +00:00
|
|
|
demo = serialize_widget (child);
|
2017-12-06 01:45:39 +00:00
|
|
|
|
|
|
|
clipboard = gdk_display_get_clipboard (gdk_display_get_default ());
|
2017-12-07 04:10:56 +00:00
|
|
|
gdk_clipboard_set (clipboard, GTK_TYPE_DEMO_WIDGET, demo);
|
2019-12-27 03:30:23 +00:00
|
|
|
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (gtk_widget_get_ancestor (button, GTK_TYPE_POPOVER)));
|
2017-12-06 01:45:39 +00:00
|
|
|
}
|
|
|
|
|
2017-12-07 04:36:35 +00:00
|
|
|
static void
|
2019-12-27 03:30:23 +00:00
|
|
|
delete_cb (GtkWidget *button, GtkWidget *child)
|
2017-12-07 04:36:35 +00:00
|
|
|
{
|
|
|
|
gtk_widget_destroy (child);
|
2019-12-27 03:30:23 +00:00
|
|
|
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (gtk_widget_get_ancestor (button, GTK_TYPE_POPOVER)));
|
2017-12-07 04:36:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-12-27 03:30:23 +00:00
|
|
|
cut_cb (GtkWidget *button, GtkWidget *child)
|
2017-12-07 04:36:35 +00:00
|
|
|
{
|
2019-12-27 03:30:23 +00:00
|
|
|
copy_cb (button, child);
|
|
|
|
delete_cb (button, child);
|
|
|
|
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (gtk_widget_get_ancestor (button, GTK_TYPE_POPOVER)));
|
2017-12-07 04:36:35 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 01:45:39 +00:00
|
|
|
static void
|
|
|
|
value_read (GObject *source,
|
|
|
|
GAsyncResult *res,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GdkClipboard *clipboard = GDK_CLIPBOARD (source);
|
|
|
|
GError *error = NULL;
|
|
|
|
const GValue *value;
|
2017-12-07 04:10:56 +00:00
|
|
|
GtkDemoWidget *demo;
|
|
|
|
GtkWidget *widget = NULL;
|
2017-12-06 01:45:39 +00:00
|
|
|
|
|
|
|
value = gdk_clipboard_read_value_finish (clipboard, res, &error);
|
|
|
|
|
|
|
|
if (value == NULL)
|
|
|
|
{
|
|
|
|
g_print ("error: %s\n", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-07 04:10:56 +00:00
|
|
|
if (!G_VALUE_HOLDS (value, GTK_TYPE_DEMO_WIDGET))
|
2017-12-06 01:45:39 +00:00
|
|
|
{
|
2017-12-07 04:10:56 +00:00
|
|
|
g_print ("can't handle clipboard contents\n");
|
2017-12-06 01:45:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-07 04:10:56 +00:00
|
|
|
demo = g_value_get_boxed (value);
|
|
|
|
widget = deserialize_widget (demo);
|
|
|
|
|
|
|
|
gtk_fixed_put (GTK_FIXED (data), widget, pos_x, pos_y);
|
2017-12-06 01:45:39 +00:00
|
|
|
}
|
2017-12-07 04:10:56 +00:00
|
|
|
|
2017-12-06 01:45:39 +00:00
|
|
|
static void
|
2019-12-27 03:30:23 +00:00
|
|
|
paste_cb (GtkWidget *button, GtkWidget *fixed)
|
2017-12-06 01:45:39 +00:00
|
|
|
{
|
|
|
|
GdkClipboard *clipboard;
|
|
|
|
|
|
|
|
clipboard = gdk_display_get_clipboard (gdk_display_get_default ());
|
2017-12-07 04:10:56 +00:00
|
|
|
if (gdk_content_formats_contain_gtype (gdk_clipboard_get_formats (clipboard), GTK_TYPE_DEMO_WIDGET))
|
|
|
|
{
|
|
|
|
g_print ("Paste %s\n", g_type_name (GTK_TYPE_DEMO_WIDGET));
|
2017-12-07 04:36:35 +00:00
|
|
|
gdk_clipboard_read_value_async (clipboard, GTK_TYPE_DEMO_WIDGET, 0, NULL, value_read, fixed);
|
2017-12-07 04:10:56 +00:00
|
|
|
}
|
2017-12-06 01:45:39 +00:00
|
|
|
else
|
|
|
|
g_print ("Don't know how to handle clipboard contents\n");
|
2019-12-27 03:30:23 +00:00
|
|
|
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (gtk_widget_get_ancestor (button, GTK_TYPE_POPOVER)));
|
2017-12-06 01:45:39 +00:00
|
|
|
}
|
|
|
|
|
2017-12-07 04:10:56 +00:00
|
|
|
static void
|
|
|
|
edit_label_done (GtkWidget *entry, gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *fixed = gtk_widget_get_parent (entry);
|
|
|
|
GtkWidget *label;
|
|
|
|
int x, y;
|
|
|
|
|
2019-03-26 16:50:30 +00:00
|
|
|
gtk_fixed_get_child_position (GTK_FIXED (fixed), entry, &x, &y);
|
2017-12-07 04:10:56 +00:00
|
|
|
|
|
|
|
label = GTK_WIDGET (g_object_get_data (G_OBJECT (entry), "label"));
|
2019-02-28 19:31:36 +00:00
|
|
|
gtk_label_set_text (GTK_LABEL (label), gtk_editable_get_text (GTK_EDITABLE (entry)));
|
2017-12-07 04:10:56 +00:00
|
|
|
|
|
|
|
gtk_widget_destroy (entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-12-27 03:30:23 +00:00
|
|
|
edit_cb (GtkWidget *button, GtkWidget *child)
|
2017-12-07 04:10:56 +00:00
|
|
|
{
|
|
|
|
GtkWidget *fixed = gtk_widget_get_parent (child);
|
|
|
|
int x, y;
|
|
|
|
|
2019-03-26 16:50:30 +00:00
|
|
|
gtk_fixed_get_child_position (GTK_FIXED (fixed), child, &x, &y);
|
2017-12-07 04:10:56 +00:00
|
|
|
|
|
|
|
if (GTK_IS_LABEL (child))
|
|
|
|
{
|
|
|
|
GtkWidget *entry = gtk_entry_new ();
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (entry), "label", child);
|
|
|
|
|
2019-02-28 19:31:36 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (entry), gtk_label_get_text (GTK_LABEL (child)));
|
2019-12-24 03:14:52 +00:00
|
|
|
gtk_editable_set_width_chars (GTK_EDITABLE (entry), 12);
|
2017-12-07 04:10:56 +00:00
|
|
|
g_signal_connect (entry, "activate", G_CALLBACK (edit_label_done), NULL);
|
|
|
|
gtk_fixed_put (GTK_FIXED (fixed), entry, x, y);
|
|
|
|
gtk_widget_grab_focus (entry);
|
|
|
|
}
|
|
|
|
else if (GTK_IS_SPINNER (child))
|
|
|
|
{
|
|
|
|
gboolean active;
|
|
|
|
|
2020-02-25 02:04:49 +00:00
|
|
|
g_object_get (child, "spinning", &active, NULL);
|
|
|
|
g_object_set (child, "spinning", !active, NULL);
|
2017-12-07 04:10:56 +00:00
|
|
|
}
|
2019-12-27 03:30:23 +00:00
|
|
|
|
|
|
|
if (button)
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (gtk_widget_get_ancestor (button, GTK_TYPE_POPOVER)));
|
2017-12-07 04:10:56 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 01:45:39 +00:00
|
|
|
static void
|
|
|
|
pressed_cb (GtkGesture *gesture,
|
|
|
|
int n_press,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2017-12-07 04:10:56 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
GtkWidget *child;
|
|
|
|
|
|
|
|
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
|
2019-04-07 21:36:40 +00:00
|
|
|
child = gtk_widget_pick (widget, x, y, GTK_PICK_DEFAULT);
|
2017-12-07 04:10:56 +00:00
|
|
|
|
2017-12-08 02:25:10 +00:00
|
|
|
if (gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture)) == GDK_BUTTON_SECONDARY)
|
2017-12-06 01:45:39 +00:00
|
|
|
{
|
|
|
|
GtkWidget *menu;
|
2019-12-27 03:30:23 +00:00
|
|
|
GtkWidget *box;
|
2017-12-06 01:45:39 +00:00
|
|
|
GtkWidget *item;
|
|
|
|
GdkClipboard *clipboard;
|
|
|
|
|
|
|
|
pos_x = x;
|
|
|
|
pos_y = y;
|
|
|
|
|
2020-02-24 12:21:46 +00:00
|
|
|
menu = gtk_popover_new ();
|
|
|
|
gtk_widget_set_parent (menu, widget);
|
2019-12-27 03:30:23 +00:00
|
|
|
gtk_popover_set_has_arrow (GTK_POPOVER (menu), FALSE);
|
|
|
|
gtk_popover_set_pointing_to (GTK_POPOVER (menu), &(GdkRectangle){ x, y, 1, 1});
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
gtk_container_add (GTK_CONTAINER (menu), box);
|
|
|
|
|
|
|
|
item = gtk_button_new_with_label ("New Label");
|
2020-04-17 04:20:09 +00:00
|
|
|
gtk_button_set_has_frame (GTK_BUTTON (item), FALSE);
|
2019-12-27 03:30:23 +00:00
|
|
|
g_signal_connect (item, "clicked", G_CALLBACK (new_label_cb), widget);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), item);
|
|
|
|
item = gtk_button_new_with_label ("New Spinner");
|
2020-04-17 04:20:09 +00:00
|
|
|
gtk_button_set_has_frame (GTK_BUTTON (item), FALSE);
|
2019-12-27 03:30:23 +00:00
|
|
|
g_signal_connect (item, "clicked", G_CALLBACK (new_spinner_cb), widget);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), item);
|
|
|
|
|
|
|
|
item = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), item);
|
|
|
|
|
|
|
|
item = gtk_button_new_with_label ("Edit");
|
2020-04-17 04:20:09 +00:00
|
|
|
gtk_button_set_has_frame (GTK_BUTTON (item), FALSE);
|
2017-12-07 04:10:56 +00:00
|
|
|
gtk_widget_set_sensitive (item, child != NULL && child != widget);
|
2019-12-27 03:30:23 +00:00
|
|
|
g_signal_connect (item, "clicked", G_CALLBACK (edit_cb), child);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), item);
|
2017-12-07 04:10:56 +00:00
|
|
|
|
2019-12-27 03:30:23 +00:00
|
|
|
item = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), item);
|
2017-12-07 04:10:56 +00:00
|
|
|
|
2019-12-27 03:30:23 +00:00
|
|
|
item = gtk_button_new_with_label ("Cut");
|
2020-04-17 04:20:09 +00:00
|
|
|
gtk_button_set_has_frame (GTK_BUTTON (item), FALSE);
|
2017-12-07 04:36:35 +00:00
|
|
|
gtk_widget_set_sensitive (item, child != NULL && child != widget);
|
2019-12-27 03:30:23 +00:00
|
|
|
g_signal_connect (item, "clicked", G_CALLBACK (cut_cb), child);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), item);
|
|
|
|
item = gtk_button_new_with_label ("Copy");
|
2020-04-17 04:20:09 +00:00
|
|
|
gtk_button_set_has_frame (GTK_BUTTON (item), FALSE);
|
2017-12-06 01:45:39 +00:00
|
|
|
gtk_widget_set_sensitive (item, child != NULL && child != widget);
|
2019-12-27 03:30:23 +00:00
|
|
|
g_signal_connect (item, "clicked", G_CALLBACK (copy_cb), child);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), item);
|
|
|
|
item = gtk_button_new_with_label ("Paste");
|
2020-04-17 04:20:09 +00:00
|
|
|
gtk_button_set_has_frame (GTK_BUTTON (item), FALSE);
|
2017-12-06 01:45:39 +00:00
|
|
|
clipboard = gdk_display_get_clipboard (gdk_display_get_default ());
|
2017-12-07 04:36:35 +00:00
|
|
|
gtk_widget_set_sensitive (item,
|
|
|
|
gdk_content_formats_contain_gtype (gdk_clipboard_get_formats (clipboard), GTK_TYPE_DEMO_WIDGET));
|
2019-12-27 03:30:23 +00:00
|
|
|
g_signal_connect (item, "clicked", G_CALLBACK (paste_cb), widget);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), item);
|
|
|
|
item = gtk_button_new_with_label ("Delete");
|
2020-04-17 04:20:09 +00:00
|
|
|
gtk_button_set_has_frame (GTK_BUTTON (item), FALSE);
|
2017-12-07 04:36:35 +00:00
|
|
|
gtk_widget_set_sensitive (item, child != NULL && child != widget);
|
2019-12-27 03:30:23 +00:00
|
|
|
g_signal_connect (item, "clicked", G_CALLBACK (delete_cb), child);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), item);
|
2017-12-06 01:45:39 +00:00
|
|
|
|
2019-12-27 03:30:23 +00:00
|
|
|
gtk_popover_popup (GTK_POPOVER (menu));
|
2017-12-06 01:45:39 +00:00
|
|
|
}
|
2017-12-06 00:22:06 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 02:25:10 +00:00
|
|
|
static void
|
|
|
|
released_cb (GtkGesture *gesture,
|
|
|
|
int n_press,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkWidget *child;
|
|
|
|
|
|
|
|
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
|
2019-04-07 17:19:09 +00:00
|
|
|
child = gtk_widget_pick (widget, x, y, 0);
|
2017-12-08 02:25:10 +00:00
|
|
|
|
|
|
|
if (gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture)) == GDK_BUTTON_PRIMARY)
|
|
|
|
{
|
|
|
|
if (child != NULL && child != widget)
|
2019-12-27 03:30:23 +00:00
|
|
|
edit_cb (NULL, child);
|
2017-12-08 02:25:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-06 00:22:06 +00:00
|
|
|
static GtkWidget *window = NULL;
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
do_dnd (GtkWidget *do_widget)
|
|
|
|
{
|
|
|
|
if (!window)
|
|
|
|
{
|
|
|
|
GtkWidget *vbox, *fixed;
|
|
|
|
GtkGesture *multipress;
|
|
|
|
GtkCssProvider *provider;
|
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2017-12-06 00:22:06 +00:00
|
|
|
gtk_window_set_display (GTK_WINDOW (window),
|
|
|
|
gtk_widget_get_display (do_widget));
|
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Drag-and-drop");
|
|
|
|
|
|
|
|
g_signal_connect (window, "destroy",
|
|
|
|
G_CALLBACK (gtk_widget_destroyed), &window);
|
|
|
|
|
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
gtk_container_add (GTK_CONTAINER (window), vbox);
|
|
|
|
|
|
|
|
fixed = gtk_fixed_new ();
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), fixed);
|
2017-12-06 00:22:06 +00:00
|
|
|
gtk_widget_set_hexpand (fixed, TRUE);
|
|
|
|
gtk_widget_set_vexpand (fixed, TRUE);
|
|
|
|
|
2019-05-29 17:10:46 +00:00
|
|
|
multipress = gtk_gesture_click_new ();
|
2017-12-06 00:22:06 +00:00
|
|
|
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (multipress), 0);
|
|
|
|
g_signal_connect (multipress, "pressed", G_CALLBACK (pressed_cb), NULL);
|
2017-12-08 02:25:10 +00:00
|
|
|
g_signal_connect (multipress, "released", G_CALLBACK (released_cb), NULL);
|
2018-03-09 05:14:59 +00:00
|
|
|
gtk_widget_add_controller (fixed, GTK_EVENT_CONTROLLER (multipress));
|
2017-12-06 00:22:06 +00:00
|
|
|
|
|
|
|
provider = gtk_css_provider_new ();
|
|
|
|
gtk_css_provider_load_from_resource (provider, "/dnd/dnd.css");
|
|
|
|
gtk_style_context_add_provider_for_display (gdk_display_get_default (),
|
|
|
|
GTK_STYLE_PROVIDER (provider),
|
|
|
|
800);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gtk_widget_get_visible (window))
|
|
|
|
gtk_widget_show (window);
|
|
|
|
else
|
|
|
|
gtk_widget_destroy (window);
|
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|