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 */
|
2019-02-28 19:31:36 +00:00
|
|
|
gdk_clipboard_set_text (clipboard, gtk_editable_get_text (GTK_EDITABLE (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 */
|
2019-02-28 19:31:36 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (entry), text);
|
2017-11-26 21:39:47 +00:00
|
|
|
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;
|
2020-02-04 16:19:22 +00:00
|
|
|
GtkIconPaintable *icon;
|
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)));
|
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
|
|
|
48, 1,
|
|
|
|
gtk_widget_get_direction (GTK_WIDGET (image)),
|
2020-02-04 03:26:19 +00:00
|
|
|
0);
|
2020-01-30 09:52:09 +00:00
|
|
|
if (icon == NULL)
|
2017-12-02 13:39:37 +00:00
|
|
|
return NULL;
|
2020-01-30 09:52:09 +00:00
|
|
|
return GDK_PAINTABLE (icon);
|
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
|
2020-01-01 01:30:32 +00:00
|
|
|
drag_begin (GtkDragSource *source,
|
2020-01-06 18:28:25 +00:00
|
|
|
GdkDrag *drag,
|
2020-01-01 01:30:32 +00:00
|
|
|
GtkWidget *widget)
|
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 (paintable)
|
2018-02-18 04:27:59 +00:00
|
|
|
{
|
2020-01-01 01:30:32 +00:00
|
|
|
gtk_drag_source_set_icon (source, 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
|
|
|
}
|
|
|
|
|
2020-01-07 19:48:09 +00:00
|
|
|
static GdkContentProvider *
|
2020-01-06 19:46:14 +00:00
|
|
|
prepare_drag (GtkDragSource *source,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
GtkWidget *image)
|
|
|
|
{
|
2020-02-16 15:22:37 +00:00
|
|
|
GdkPaintable *paintable = get_image_paintable (GTK_IMAGE (image));
|
|
|
|
|
|
|
|
if (!GDK_IS_TEXTURE (paintable))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return gdk_content_provider_new_typed (GDK_TYPE_TEXTURE, paintable);
|
2020-01-06 19:46:14 +00:00
|
|
|
}
|
|
|
|
|
2020-01-01 18:13:39 +00:00
|
|
|
static gboolean
|
|
|
|
drag_drop (GtkDropTarget *dest,
|
2020-02-29 02:47:17 +00:00
|
|
|
const GValue *value,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
GtkImage *image)
|
2020-01-01 18:13:39 +00:00
|
|
|
{
|
2020-02-29 02:47:17 +00:00
|
|
|
GdkTexture *texture = g_value_get_object (value);
|
|
|
|
gtk_image_set_from_paintable (GTK_IMAGE (image), GDK_PAINTABLE (texture));
|
2020-01-01 18:13:39 +00:00
|
|
|
|
2020-02-29 02:47:17 +00:00
|
|
|
return TRUE;
|
2005-05-25 15:22:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-12-27 03:03:52 +00:00
|
|
|
copy_image (GSimpleAction *action,
|
|
|
|
GVariant *value,
|
|
|
|
gpointer data)
|
2005-05-25 15:22:43 +00:00
|
|
|
{
|
2019-12-27 03:03:52 +00:00
|
|
|
GdkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (data));
|
|
|
|
GdkPaintable *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))
|
2020-01-01 18:13:39 +00:00
|
|
|
gdk_clipboard_set_texture (clipboard, GDK_TEXTURE (paintable));
|
2018-03-16 03:29:42 +00:00
|
|
|
|
|
|
|
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
|
2019-12-27 03:03:52 +00:00
|
|
|
paste_image (GSimpleAction *action,
|
|
|
|
GVariant *value,
|
|
|
|
gpointer data)
|
2005-05-25 15:22:43 +00:00
|
|
|
{
|
2019-12-27 03:03:52 +00:00
|
|
|
GdkClipboard *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
|
|
|
{
|
2019-12-27 03:03:52 +00:00
|
|
|
GtkWidget *popover;
|
|
|
|
GMenu *menu;
|
|
|
|
GMenuItem *item;
|
2005-05-25 15:22:43 +00:00
|
|
|
|
2019-12-27 03:03:52 +00:00
|
|
|
menu = g_menu_new ();
|
|
|
|
item = g_menu_item_new (_("_Copy"), "clipboard.copy");
|
|
|
|
g_menu_append_item (menu, item);
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2019-12-27 03:03:52 +00:00
|
|
|
item = g_menu_item_new (_("_Paste"), "clipboard.paste");
|
|
|
|
g_menu_append_item (menu, item);
|
2005-05-25 15:22:43 +00:00
|
|
|
|
2020-02-24 12:21:46 +00:00
|
|
|
popover = gtk_popover_menu_new_from_model (G_MENU_MODEL (menu));
|
|
|
|
gtk_widget_set_parent (popover, image);
|
2005-05-25 15:22:43 +00:00
|
|
|
|
2019-12-27 03:03:52 +00:00
|
|
|
gtk_popover_set_pointing_to (GTK_POPOVER (popover), &(GdkRectangle) { x, y, 1, 1});
|
|
|
|
gtk_popover_popup (GTK_POPOVER (popover));
|
|
|
|
|
|
|
|
g_object_unref (menu);
|
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;
|
2019-12-27 03:03:52 +00:00
|
|
|
GActionEntry entries[] = {
|
|
|
|
{ "copy", copy_image, NULL, NULL, NULL },
|
|
|
|
{ "paste", paste_image, NULL, NULL, NULL },
|
|
|
|
};
|
|
|
|
GActionGroup *actions;
|
2020-01-01 01:30:32 +00:00
|
|
|
GtkDragSource *source;
|
2020-01-01 18:13:39 +00:00
|
|
|
GtkDropTarget *dest;
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
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);
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (vbox, 8);
|
|
|
|
gtk_widget_set_margin_end (vbox, 8);
|
|
|
|
gtk_widget_set_margin_top (vbox, 8);
|
|
|
|
gtk_widget_set_margin_bottom (vbox, 8);
|
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);
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (hbox, 8);
|
|
|
|
gtk_widget_set_margin_end (hbox, 8);
|
|
|
|
gtk_widget_set_margin_top (hbox, 8);
|
|
|
|
gtk_widget_set_margin_bottom (hbox, 8);
|
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);
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (hbox, 8);
|
|
|
|
gtk_widget_set_margin_end (hbox, 8);
|
|
|
|
gtk_widget_set_margin_top (hbox, 8);
|
|
|
|
gtk_widget_set_margin_bottom (hbox, 8);
|
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);
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (hbox, 8);
|
|
|
|
gtk_widget_set_margin_end (hbox, 8);
|
|
|
|
gtk_widget_set_margin_top (hbox, 8);
|
|
|
|
gtk_widget_set_margin_bottom (hbox, 8);
|
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");
|
2020-01-01 01:30:32 +00:00
|
|
|
gtk_image_set_pixel_size (GTK_IMAGE (image), 48);
|
2017-08-02 12:59:26 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), image);
|
|
|
|
|
|
|
|
/* make image a drag source */
|
2020-01-06 19:46:14 +00:00
|
|
|
source = gtk_drag_source_new ();
|
|
|
|
g_signal_connect (source, "prepare", G_CALLBACK (prepare_drag), NULL);
|
2020-01-01 01:30:32 +00:00
|
|
|
g_signal_connect (source, "drag-begin", G_CALLBACK (drag_begin), image);
|
2020-01-07 06:06:39 +00:00
|
|
|
gtk_widget_add_controller (image, GTK_EVENT_CONTROLLER (source));
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2017-08-02 12:59:26 +00:00
|
|
|
/* accept drops on image */
|
2020-02-29 02:47:17 +00:00
|
|
|
dest = gtk_drop_target_new (GDK_TYPE_TEXTURE, GDK_ACTION_COPY);
|
|
|
|
g_signal_connect (dest, "drop", G_CALLBACK (drag_drop), image);
|
2020-01-06 05:12:21 +00:00
|
|
|
gtk_widget_add_controller (image, GTK_EVENT_CONTROLLER (dest));
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2017-08-02 12:59:26 +00:00
|
|
|
/* context menu on image */
|
2019-05-29 17:10:46 +00:00
|
|
|
gesture = gtk_gesture_click_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
|
|
|
|
2019-12-27 03:03:52 +00:00
|
|
|
actions = G_ACTION_GROUP (g_simple_action_group_new ());
|
|
|
|
g_action_map_add_action_entries (G_ACTION_MAP (actions), entries, G_N_ELEMENTS (entries), image);
|
|
|
|
|
|
|
|
gtk_widget_insert_action_group (image, "clipboard", actions);
|
|
|
|
|
|
|
|
g_object_unref (actions);
|
|
|
|
|
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");
|
2020-01-01 01:30:32 +00:00
|
|
|
gtk_image_set_pixel_size (GTK_IMAGE (image), 48);
|
2017-08-02 12:59:26 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), image);
|
|
|
|
|
|
|
|
/* make image a drag source */
|
2020-01-06 19:46:14 +00:00
|
|
|
source = gtk_drag_source_new ();
|
|
|
|
g_signal_connect (source, "prepare", G_CALLBACK (prepare_drag), NULL);
|
2020-01-01 01:30:32 +00:00
|
|
|
g_signal_connect (source, "drag-begin", G_CALLBACK (drag_begin), image);
|
2020-01-07 06:06:39 +00:00
|
|
|
gtk_widget_add_controller (image, GTK_EVENT_CONTROLLER (source));
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2017-08-02 12:59:26 +00:00
|
|
|
/* accept drops on image */
|
2020-02-29 02:47:17 +00:00
|
|
|
dest = gtk_drop_target_new (GDK_TYPE_TEXTURE, GDK_ACTION_COPY);
|
|
|
|
g_signal_connect (dest, "drop", G_CALLBACK (drag_drop), image);
|
2020-01-06 05:12:21 +00:00
|
|
|
gtk_widget_add_controller (image, GTK_EVENT_CONTROLLER (dest));
|
2008-08-11 19:12:58 +00:00
|
|
|
|
2017-08-02 12:59:26 +00:00
|
|
|
/* context menu on image */
|
2019-05-29 17:10:46 +00:00
|
|
|
gesture = gtk_gesture_click_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));
|
2019-12-27 03:03:52 +00:00
|
|
|
|
|
|
|
actions = G_ACTION_GROUP (g_simple_action_group_new ());
|
|
|
|
g_action_map_add_action_entries (G_ACTION_MAP (actions), entries, G_N_ELEMENTS (entries), image);
|
|
|
|
|
|
|
|
gtk_widget_insert_action_group (image, "clipboard", actions);
|
|
|
|
|
|
|
|
g_object_unref (actions);
|
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;
|
|
|
|
}
|