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 
39 
40 /** \brief  Event handler for the 'paste' event
41  *
42  * Pastes \a text into the emulated machine via the machine's keyboard buffer.
43  *
44  * \param[in]   clipboard   clipboard (unused)
45  * \param[in]   text        text to paste into the emulated machine
46  * \param[in]   data        extra event data (unused)
47  */
paste_callback(GtkClipboard * clipboard,const gchar * text,gpointer data)48 static void paste_callback(GtkClipboard *clipboard, const gchar *text, gpointer data)
49 {
50     char *text_in_petscii;
51     if (text == NULL) {
52         return;
53     }
54     text_in_petscii = lib_strdup(text);
55 
56     charset_petconvstring((unsigned char*)text_in_petscii, 0);
57     kbdbuf_feed(text_in_petscii);
58     lib_free(text_in_petscii);
59 }
60 
61 
62 /** \brief  Callback for the edit->copy menu item
63  *
64  * Copies the screen of the emulated machine into the host clipboard
65  *
66  * \param[in]   widget      widget (unused)
67  * \param[in]   user_data   extra data (unused)
68  *
69  * \return  TRUE so the key pressed doesn't go to the emulated machine
70  */
ui_copy_callback(GtkWidget * widget,gpointer user_data)71 gboolean ui_copy_callback(GtkWidget *widget, gpointer user_data)
72 {
73     char * text = clipboard_read_screen_output("\n");
74     if (text != NULL) {
75         gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
76                 text, (gint)strlen(text));
77     }
78     return TRUE;
79 }
80 
81 
82 /** \brief  Callback for the edit->paste menu item
83  *
84  * Copies the host clipboard into the emulated machine's screen
85  *
86  * \param[in]   widget      widget (unused)
87  * \param[in]   user_data   extra data (unused)
88  *
89  * \return  TRUE so the key pressed doesn't go to the emulated machine
90  */
ui_paste_callback(GtkWidget * widget,gpointer user_data)91 gboolean ui_paste_callback(GtkWidget *widget, gpointer user_data)
92 {
93     gtk_clipboard_request_text(gtk_clipboard_get(GDK_NONE), paste_callback, NULL);
94     return TRUE;
95 }
96