2004-07-29 15:40:35 +00:00
|
|
|
/* Clipboard
|
|
|
|
*
|
2017-12-02 13:39:37 +00:00
|
|
|
* GdkClipboard is used for clipboard handling. This demo shows how to
|
2008-08-11 19:12:58 +00:00
|
|
|
* copy and paste text to and from the clipboard.
|
2005-05-25 15:22:43 +00:00
|
|
|
*
|
2008-08-11 19:12:58 +00:00
|
|
|
* It also shows how to transfer images via the clipboard or via
|
2005-05-25 15:22:43 +00:00
|
|
|
* drag-and-drop, and how to make clipboard contents persist after
|
|
|
|
* the application exits. Clipboard persistence requires a clipboard
|
|
|
|
* manager to run.
|
2004-07-29 15:40:35 +00:00
|
|
|
*/
|
|
|
|
|
2013-06-21 17:46:54 +00:00
|
|
|
#include <glib/gi18n.h>
|
2004-07-29 15:40:35 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2017-11-26 21:39:47 +00:00
|
|
|
static GtkWidget *window = NULL;
|
|
|
|
|
2004-07-29 15:40:35 +00:00
|
|
|
void
|
|
|
|
copy_button_clicked (GtkWidget *button,
|
2005-05-25 15:22:43 +00:00
|
|
|
gpointer user_data)
|
2004-07-29 15:40:35 +00:00
|
|
|
{
|
|
|
|
GtkWidget *entry;
|
2017-11-26 21:39:47 +00:00
|
|
|
GdkClipboard *clipboard;
|
2004-07-29 15:40:35 +00:00
|
|
|
|
|
|
|
entry = GTK_WIDGET (user_data);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2004-07-29 15:40:35 +00:00
|
|
|
/* Get the clipboard object */
|
2017-11-26 21:39:47 +00:00
|
|
|
clipboard = gtk_widget_get_clipboard (entry);
|
2004-07-29 15:40:35 +00:00
|
|
|
|
|
|
|
/* Set clipboard text */
|
2017-11-26 21:39:47 +00:00
|
|
|
gdk_clipboard_set_text (clipboard, gtk_entry_get_text (GTK_ENTRY (entry)));
|
2004-07-29 15:40:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-11-26 21:39:47 +00:00
|
|
|
paste_received (GObject *source_object,
|
|
|
|
GAsyncResult *result,
|
2005-05-25 15:22:43 +00:00
|
|
|
gpointer user_data)
|
2004-07-29 15:40:35 +00:00
|
|
|
{
|
2017-11-26 21:39:47 +00:00
|
|
|
GdkClipboard *clipboard;
|
2004-07-29 15:40:35 +00:00
|
|
|
GtkWidget *entry;
|
2017-11-26 21:39:47 +00:00
|
|
|
char *text;
|
|
|
|
GError *error = NULL;
|
2004-07-29 15:40:35 +00:00
|
|
|
|
2017-11-26 21:39:47 +00:00
|
|
|
clipboard = GDK_CLIPBOARD (source_object);
|
2004-07-29 15:40:35 +00:00
|
|
|
entry = GTK_WIDGET (user_data);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2017-11-26 21:39:47 +00:00
|
|
|
/* Get the resulting text of the read operation */
|
|
|
|
text = gdk_clipboard_read_text_finish (clipboard, result, &error);
|
|
|
|
|
|
|
|
if (text)
|
|
|
|
{
|
|
|
|
/* Set the entry text */
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (entry), text);
|
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
/* Show an error about why pasting failed.
|
|
|
|
* Usually you probably want to ignore such failures,
|
|
|
|
* but for demonstration purposes, we show the error.
|
|
|
|
*/
|
|
|
|
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
GTK_BUTTONS_CLOSE,
|
|
|
|
"Could not paste text: %s",
|
|
|
|
error->message);
|
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (gtk_widget_destroy), NULL);
|
|
|
|
gtk_widget_show (dialog);
|
|
|
|
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
2004-07-29 15:40:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
paste_button_clicked (GtkWidget *button,
|
2017-11-26 21:39:47 +00:00
|
|
|
gpointer user_data)
|
2004-07-29 15:40:35 +00:00
|
|
|
{
|
|
|
|
GtkWidget *entry;
|
2017-11-26 21:39:47 +00:00
|
|
|
GdkClipboard *clipboard;
|
2004-07-29 15:40:35 +00:00
|
|
|
|
|
|
|
entry = GTK_WIDGET (user_data);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2004-07-29 15:40:35 +00:00
|
|
|
/* Get the clipboard object */
|
2017-11-26 21:39:47 +00:00
|
|
|
clipboard = gtk_widget_get_clipboard (entry);
|
2004-07-29 15:40:35 +00:00
|
|
|
|
|
|
|
/* Request the contents of the clipboard, contents_received will be
|
|
|
|
called when we do get the contents.
|
|
|
|
*/
|
2017-11-26 21:39:47 +00:00
|
|
|
gdk_clipboard_read_text_async (clipboard, NULL, paste_received, entry);
|
2005-05-25 15:22:43 +00:00
|
|
|
}
|
|
|
|
|
2018-03-16 03:29:42 +00:00
|
|
|
static GdkPaintable *
|
|
|
|
get_image_paintable (GtkImage *image)
|
2005-05-25 15:22:43 +00:00
|
|
|
{
|
2013-06-26 13:50:05 +00:00
|
|
|
const gchar *icon_name;
|
2013-06-21 17:46:54 +00:00
|
|
|
GtkIconTheme *icon_theme;
|
2017-12-02 13:39:37 +00:00
|
|
|
GtkIconInfo *icon_info;
|
2005-05-25 15:22:43 +00:00
|
|
|
|
|
|
|
switch (gtk_image_get_storage_type (image))
|
|
|
|
{
|
2018-03-16 03:29:42 +00:00
|
|
|
case GTK_IMAGE_PAINTABLE:
|
|
|
|
return g_object_ref (gtk_image_get_paintable (image));
|
2013-06-21 17:46:54 +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)));
|
2017-12-02 13:39:37 +00:00
|
|
|
icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, 48, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
|
|
|
|
if (icon_info == NULL)
|
|
|
|
return NULL;
|
2018-03-16 03:29:42 +00:00
|
|
|
return GDK_PAINTABLE (gtk_icon_info_load_texture (icon_info));
|
2005-05-25 15:22:43 +00:00
|
|
|
default:
|
2008-08-11 19:12:58 +00:00
|
|
|
g_warning ("Image storage type %d not handled",
|
2005-05-25 15:22:43 +00:00
|
|
|
gtk_image_get_storage_type (image));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drag_begin (GtkWidget *widget,
|
2018-06-29 17:34:14 +00:00
|
|
|
GdkDrag *drag,
|
2005-05-25 15:22:43 +00:00
|
|
|
gpointer data)
|
|
|
|
{
|
2018-03-16 03:29:42 +00:00
|
|
|
GdkPaintable *paintable;
|
2005-05-25 15:22:43 +00:00
|
|
|
|
2018-03-16 03:29:42 +00:00
|
|
|
paintable = get_image_paintable (GTK_IMAGE (widget));
|
|
|
|
if (paintable)
|
2018-02-18 04:27:59 +00:00
|
|
|
{
|
2018-06-29 17:34:14 +00:00
|
|
|
gtk_drag_set_icon_paintable (drag, paintable, -2, -2);
|
2018-03-16 03:29:42 +00:00
|
|
|
g_object_unref (paintable);
|
2018-02-18 04:27:59 +00:00
|
|
|
}
|
2005-05-25 15:22:43 +00:00
|
|
|
}
|
|
|
|
|
2008-08-11 19:12:58 +00:00
|
|
|
void
|
2015-06-28 13:23:28 +00:00
|
|
|
drag_data_get (GtkWidget *widget,
|
2018-06-29 17:34:14 +00:00
|
|
|
GdkDrag *drag,
|
2015-06-28 13:23:28 +00:00
|
|
|
GtkSelectionData *selection_data,
|
|
|
|
guint info,
|
|
|
|
gpointer data)
|
2005-05-25 15:22:43 +00:00
|
|
|
{
|
2018-03-16 03:29:42 +00:00
|
|
|
GdkPaintable *paintable;
|
2005-05-25 15:22:43 +00:00
|
|
|
|
2018-03-16 03:29:42 +00:00
|
|
|
paintable = get_image_paintable (GTK_IMAGE (widget));
|
|
|
|
if (GDK_IS_TEXTURE (paintable))
|
|
|
|
gtk_selection_data_set_texture (selection_data, GDK_TEXTURE (paintable));
|
2005-05-25 15:22:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drag_data_received (GtkWidget *widget,
|
2018-05-16 02:50:24 +00:00
|
|
|
GdkDrop *drop,
|
2005-05-25 15:22:43 +00:00
|
|
|
GtkSelectionData *selection_data,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2010-12-15 23:57:13 +00:00
|
|
|
if (gtk_selection_data_get_length (selection_data) > 0)
|
2005-05-25 15:22:43 +00:00
|
|
|
{
|
2017-12-02 13:39:37 +00:00
|
|
|
GdkTexture *texture;
|
2017-10-23 03:40:20 +00:00
|
|
|
|
2017-12-02 13:39:37 +00:00
|
|
|
texture = gtk_selection_data_get_texture (selection_data);
|
2018-03-16 03:29:42 +00:00
|
|
|
gtk_image_set_from_paintable (GTK_IMAGE (data), GDK_PAINTABLE (texture));
|
2017-12-02 13:39:37 +00:00
|
|
|
g_object_unref (texture);
|
2005-05-25 15:22:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
copy_image (GtkMenuItem *item,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2017-12-02 13:39:37 +00:00
|
|
|
GdkClipboard *clipboard;
|
2018-03-16 03:29:42 +00:00
|
|
|
GdkPaintable *paintable;
|
2005-05-25 15:22:43 +00:00
|
|
|
|
2017-12-02 13:39:37 +00:00
|
|
|
clipboard = gtk_widget_get_clipboard (GTK_WIDGET (data));
|
2018-03-16 03:29:42 +00:00
|
|
|
paintable = get_image_paintable (GTK_IMAGE (data));
|
2005-05-25 15:22:43 +00:00
|
|
|
|
2018-03-16 03:29:42 +00:00
|
|
|
if (GDK_IS_TEXTURE (paintable))
|
|
|
|
gdk_clipboard_set_texture (clipboard, GDK_TEXTURE (paintable));
|
|
|
|
|
|
|
|
if (paintable)
|
|
|
|
g_object_unref (paintable);
|
2005-05-25 15:22:43 +00:00
|
|
|
}
|
|
|
|
|
2017-12-02 13:39:37 +00:00
|
|
|
static void
|
|
|
|
paste_image_received (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GdkTexture *texture;
|
|
|
|
|
|
|
|
texture = gdk_clipboard_read_texture_finish (GDK_CLIPBOARD (source), result, NULL);
|
|
|
|
if (texture == NULL)
|
|
|
|
return;
|
|
|
|
|
2018-03-16 03:29:42 +00:00
|
|
|
gtk_image_set_from_paintable (GTK_IMAGE (data), GDK_PAINTABLE (texture));
|
2017-12-02 13:39:37 +00:00
|
|
|
g_object_unref (texture);
|
|
|
|
}
|
|
|
|
|
2005-05-25 15:22:43 +00:00
|
|
|
static void
|
|
|
|
paste_image (GtkMenuItem *item,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2017-12-02 13:39:37 +00:00
|
|
|
GdkClipboard *clipboard;
|
2005-05-25 15:22:43 +00:00
|
|
|
|
2017-12-02 13:39:37 +00:00
|
|
|
clipboard = gtk_widget_get_clipboard (GTK_WIDGET (data));
|
|
|
|
gdk_clipboard_read_texture_async (clipboard,
|
|
|
|
NULL,
|
|
|
|
paste_image_received,
|
|
|
|
data);
|
2005-05-25 15:22:43 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 23:38:00 +00:00
|
|
|
static void
|
|
|
|
pressed_cb (GtkGesture *gesture,
|
|
|
|
int n_press,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
GtkWidget *image)
|
2005-05-25 15:22:43 +00:00
|
|
|
{
|
|
|
|
GtkWidget *menu;
|
|
|
|
GtkWidget *item;
|
|
|
|
|
|
|
|
menu = gtk_menu_new ();
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2013-06-21 17:46:54 +00:00
|
|
|
item = gtk_menu_item_new_with_mnemonic (_("_Copy"));
|
2018-01-10 23:38:00 +00:00
|
|
|
g_signal_connect (item, "activate", G_CALLBACK (copy_image), image);
|
2005-05-25 15:22:43 +00:00
|
|
|
gtk_widget_show (item);
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
|
|
|
|
2013-06-21 17:46:54 +00:00
|
|
|
item = gtk_menu_item_new_with_mnemonic (_("_Paste"));
|
2018-01-10 23:38:00 +00:00
|
|
|
g_signal_connect (item, "activate", G_CALLBACK (paste_image), image);
|
2005-05-25 15:22:43 +00:00
|
|
|
gtk_widget_show (item);
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
|
|
|
|
2018-01-10 23:38:00 +00:00
|
|
|
gtk_menu_popup_at_pointer (GTK_MENU (menu), NULL);
|
2004-07-29 15:40:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
do_clipboard (GtkWidget *do_widget)
|
|
|
|
{
|
|
|
|
if (!window)
|
|
|
|
{
|
|
|
|
GtkWidget *vbox, *hbox;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *entry, *button;
|
2017-08-02 12:59:26 +00:00
|
|
|
GtkWidget *image;
|
2018-01-10 23:38:00 +00:00
|
|
|
GtkGesture *gesture;
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2004-07-29 15:40:35 +00:00
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
2017-10-31 06:41:15 +00:00
|
|
|
gtk_window_set_display (GTK_WINDOW (window),
|
|
|
|
gtk_widget_get_display (do_widget));
|
2015-06-20 01:59:15 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Clipboard");
|
2009-08-31 05:08:31 +00:00
|
|
|
|
2005-05-25 15:22:43 +00:00
|
|
|
g_signal_connect (window, "destroy",
|
|
|
|
G_CALLBACK (gtk_widget_destroyed), &window);
|
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2016-10-26 19:03:04 +00:00
|
|
|
g_object_set (vbox, "margin", 8, NULL);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2004-07-29 15:40:35 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (window), vbox);
|
|
|
|
|
|
|
|
label = gtk_label_new ("\"Copy\" will copy the text\nin the entry to the clipboard");
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), label);
|
2004-07-29 15:40:35 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
|
2016-10-26 19:03:04 +00:00
|
|
|
g_object_set (hbox, "margin", 8, NULL);
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), hbox);
|
2004-07-29 15:40:35 +00:00
|
|
|
|
|
|
|
/* Create the first entry */
|
|
|
|
entry = gtk_entry_new ();
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), entry);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2004-07-29 15:40:35 +00:00
|
|
|
/* Create the button */
|
2013-06-21 17:46:54 +00:00
|
|
|
button = gtk_button_new_with_mnemonic (_("_Copy"));
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), button);
|
2004-07-29 15:40:35 +00:00
|
|
|
g_signal_connect (button, "clicked",
|
2005-05-25 15:22:43 +00:00
|
|
|
G_CALLBACK (copy_button_clicked), entry);
|
2004-07-29 15:40:35 +00:00
|
|
|
|
|
|
|
label = gtk_label_new ("\"Paste\" will paste the text from the clipboard to the entry");
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), label);
|
2004-07-29 15:40:35 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
|
2016-10-26 19:03:04 +00:00
|
|
|
g_object_set (hbox, "margin", 8, NULL);
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), hbox);
|
2004-07-29 15:40:35 +00:00
|
|
|
|
|
|
|
/* Create the second entry */
|
|
|
|
entry = gtk_entry_new ();
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), entry);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2004-07-29 15:40:35 +00:00
|
|
|
/* Create the button */
|
2013-06-21 17:46:54 +00:00
|
|
|
button = gtk_button_new_with_mnemonic (_("_Paste"));
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), button);
|
2004-07-29 15:40:35 +00:00
|
|
|
g_signal_connect (button, "clicked",
|
2005-05-25 15:22:43 +00:00
|
|
|
G_CALLBACK (paste_button_clicked), entry);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2005-05-25 15:22:43 +00:00
|
|
|
label = gtk_label_new ("Images can be transferred via the clipboard, too");
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), label);
|
2005-05-25 15:22:43 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
|
2016-10-26 19:03:04 +00:00
|
|
|
g_object_set (hbox, "margin", 8, NULL);
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), hbox);
|
2005-05-25 15:22:43 +00:00
|
|
|
|
|
|
|
/* Create the first image */
|
2017-11-15 00:43:13 +00:00
|
|
|
image = gtk_image_new_from_icon_name ("dialog-warning");
|
2017-08-02 12:59:26 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), image);
|
|
|
|
|
|
|
|
/* make image a drag source */
|
2017-11-14 21:32:23 +00:00
|
|
|
gtk_drag_source_set (image, GDK_BUTTON1_MASK, NULL, GDK_ACTION_COPY);
|
2017-08-02 12:59:26 +00:00
|
|
|
gtk_drag_source_add_image_targets (image);
|
|
|
|
g_signal_connect (image, "drag-begin",
|
2005-05-25 15:22:43 +00:00
|
|
|
G_CALLBACK (drag_begin), image);
|
2017-08-02 12:59:26 +00:00
|
|
|
g_signal_connect (image, "drag-data-get",
|
2005-05-25 15:22:43 +00:00
|
|
|
G_CALLBACK (drag_data_get), image);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2017-08-02 12:59:26 +00:00
|
|
|
/* accept drops on image */
|
|
|
|
gtk_drag_dest_set (image, GTK_DEST_DEFAULT_ALL,
|
2017-11-14 21:32:23 +00:00
|
|
|
NULL, GDK_ACTION_COPY);
|
2017-08-02 12:59:26 +00:00
|
|
|
gtk_drag_dest_add_image_targets (image);
|
|
|
|
g_signal_connect (image, "drag-data-received",
|
2005-05-25 15:22:43 +00:00
|
|
|
G_CALLBACK (drag_data_received), image);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2017-08-02 12:59:26 +00:00
|
|
|
/* context menu on image */
|
2018-03-09 05:14:59 +00:00
|
|
|
gesture = gtk_gesture_multi_press_new ();
|
2018-01-10 23:38:00 +00:00
|
|
|
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_SECONDARY);
|
|
|
|
g_signal_connect (gesture, "pressed", G_CALLBACK (pressed_cb), image);
|
2018-03-09 05:14:59 +00:00
|
|
|
gtk_widget_add_controller (image, GTK_EVENT_CONTROLLER (gesture));
|
2005-05-25 15:22:43 +00:00
|
|
|
|
|
|
|
/* Create the second image */
|
2017-11-15 00:43:13 +00:00
|
|
|
image = gtk_image_new_from_icon_name ("process-stop");
|
2017-08-02 12:59:26 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), image);
|
|
|
|
|
|
|
|
/* make image a drag source */
|
2017-11-14 21:32:23 +00:00
|
|
|
gtk_drag_source_set (image, GDK_BUTTON1_MASK, NULL, GDK_ACTION_COPY);
|
2017-08-02 12:59:26 +00:00
|
|
|
gtk_drag_source_add_image_targets (image);
|
|
|
|
g_signal_connect (image, "drag-begin",
|
2005-05-25 15:22:43 +00:00
|
|
|
G_CALLBACK (drag_begin), image);
|
2017-08-02 12:59:26 +00:00
|
|
|
g_signal_connect (image, "drag-data-get",
|
2005-05-25 15:22:43 +00:00
|
|
|
G_CALLBACK (drag_data_get), image);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2017-08-02 12:59:26 +00:00
|
|
|
/* accept drops on image */
|
|
|
|
gtk_drag_dest_set (image, GTK_DEST_DEFAULT_ALL,
|
2017-11-14 21:32:23 +00:00
|
|
|
NULL, GDK_ACTION_COPY);
|
2017-08-02 12:59:26 +00:00
|
|
|
gtk_drag_dest_add_image_targets (image);
|
|
|
|
g_signal_connect (image, "drag-data-received",
|
2005-05-25 15:22:43 +00:00
|
|
|
G_CALLBACK (drag_data_received), image);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2017-08-02 12:59:26 +00:00
|
|
|
/* context menu on image */
|
2018-03-09 05:14:59 +00:00
|
|
|
gesture = gtk_gesture_multi_press_new ();
|
2018-01-10 23:38:00 +00:00
|
|
|
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_SECONDARY);
|
|
|
|
g_signal_connect (gesture, "pressed", G_CALLBACK (pressed_cb), image);
|
2018-03-09 05:14:59 +00:00
|
|
|
gtk_widget_add_controller (image, GTK_EVENT_CONTROLLER (gesture));
|
2004-07-29 15:40:35 +00:00
|
|
|
}
|
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
if (!gtk_widget_get_visible (window))
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2004-07-29 15:40:35 +00:00
|
|
|
else
|
2015-06-28 13:23:28 +00:00
|
|
|
gtk_widget_destroy (window);
|
2004-07-29 15:40:35 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|