1 /** \file   uiedit.c
2  * \brief   "Edit" submenu (copy / paste) for GTK3
3  *
4  * \author  groepaz <groepaz@gmx.net>
5  */
6 
7 /*
8  * This file is part of VICE, the Versatile Commodore Emulator.
9  * See README for copyright notice.
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24  *  02111-1307  USA.
25  *
26  */
27 
28 #include "vice.h"
29 
30 #include <gtk/gtk.h>
31 #include <string.h>
32 
33 #include "charset.h"
34 #include "clipboard.h"
35 #include "uiedit.h"
36 #include "lib.h"
37 #include "kbdbuf.h"
38 
paste_callback(GtkClipboard * clipboard,const gchar * text,gpointer data)39 static void paste_callback(GtkClipboard *clipboard, const gchar *text, gpointer data)
40 {
41     char *text_in_petscii;
42     if (text == NULL) {
43         return;
44     }
45     text_in_petscii = lib_stralloc(text);
46 
47     charset_petconvstring((unsigned char*)text_in_petscii, 0);
48     kbdbuf_feed(text_in_petscii);
49     lib_free(text_in_petscii);
50 }
51 
52 
53 /** \brief  Callback for the edit->copy menu item
54  *
55  * Copies the screen of the emulated machine into the host clipboard
56  *
57  * \param[in]   widget  widget (unused)
58  * \param[in]   data    extra data (unused)
59  *
60  * \return  TRUE so the key pressed doesn't go to the emulated machine
61  */
ui_copy_callback(GtkWidget * widget,gpointer user_data)62 gboolean ui_copy_callback(GtkWidget *widget, gpointer user_data)
63 {
64     char * text = clipboard_read_screen_output("\n");
65     if (text != NULL) {
66         gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
67                 text, strlen(text));
68     }
69     return TRUE;
70 }
71 
72 
73 /** \brief  Callback for the edit->paste menu item
74  *
75  * Copies the host clipboard into the emulated machine's screen
76  *
77  * \param[in]   widget  widget (unused)
78  * \param[in]   data    extra data (unused)
79  *
80  * \return  TRUE so the key pressed doesn't go to the emulated machine
81  */
ui_paste_callback(GtkWidget * widget,gpointer user_data)82 gboolean ui_paste_callback(GtkWidget *widget, gpointer user_data)
83 {
84     gtk_clipboard_request_text(gtk_clipboard_get(GDK_NONE), paste_callback, NULL);
85     return TRUE;
86 }
87