Commit 5e7ea614539be0015edcd1bbb1651db2f436e86c
1 parent
762f4b2d
Exists in
master
and in
1 other branch
Copying the new clipboard methods used on linux to windows.
Showing
3 changed files
with
187 additions
and
31 deletions
Show diff stats
src/selection/windows/copy.c
... | ... | @@ -18,7 +18,7 @@ |
18 | 18 | * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin |
19 | 19 | * St, Fifth Floor, Boston, MA 02110-1301 USA |
20 | 20 | * |
21 | - * Este programa está nomeado como - e possui - linhas de código. | |
21 | + * Este programa está nomeado como - possui - linhas de código. | |
22 | 22 | * |
23 | 23 | * Contatos: |
24 | 24 | * |
... | ... | @@ -31,6 +31,7 @@ |
31 | 31 | #include <lib3270/selection.h> |
32 | 32 | |
33 | 33 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
34 | + | |
34 | 35 | static void clipboard_clear(G_GNUC_UNUSED GtkClipboard *clipboard, G_GNUC_UNUSED GObject *obj) |
35 | 36 | { |
36 | 37 | v3270 * terminal = GTK_V3270(obj); |
... | ... | @@ -56,18 +57,8 @@ static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionDa |
56 | 57 | { |
57 | 58 | case CLIPBOARD_TYPE_TEXT: // Get clipboard contents as text |
58 | 59 | { |
59 | - gchar *text; | |
60 | - | |
61 | - if(terminal->selection.format == V3270_SELECT_TABLE) | |
62 | - { | |
63 | - text = v3270_get_copy_as_table(terminal,"\t"); | |
64 | - } | |
65 | - else | |
66 | - { | |
67 | - text = v3270_get_copy_as_text(terminal); | |
68 | - } | |
60 | + g_autofree gchar *text = v3270_get_copy_as_text(terminal); | |
69 | 61 | gtk_selection_data_set_text(selection,text,-1); |
70 | - g_free(text); | |
71 | 62 | } |
72 | 63 | break; |
73 | 64 | |
... | ... | @@ -85,6 +76,33 @@ static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionDa |
85 | 76 | } |
86 | 77 | break; |
87 | 78 | |
79 | + case CLIPBOARD_TYPE_HTML: | |
80 | + { | |
81 | + g_autofree gchar *text = v3270_get_copy_as_html(terminal); | |
82 | + //debug("Selection:\n%s",text); | |
83 | + gtk_selection_data_set( | |
84 | + selection, | |
85 | + gdk_atom_intern_static_string("text/html"), | |
86 | + 8, | |
87 | + (guchar *) text, | |
88 | + strlen(text) | |
89 | + ); | |
90 | + } | |
91 | + break; | |
92 | + | |
93 | + case CLIPBOARD_TYPE_V3270_UNPROTECTED: | |
94 | + { | |
95 | + g_autofree gchar *data = v3270_get_copy_as_data_block(terminal); | |
96 | + gtk_selection_data_set( | |
97 | + selection, | |
98 | + GTK_V3270_GET_CLASS(obj)->clipboard_formatted, | |
99 | + 8, | |
100 | + (guchar *) data, | |
101 | + ((struct SelectionHeader *) data)->length | |
102 | + ); | |
103 | + } | |
104 | + break; | |
105 | + | |
88 | 106 | default: |
89 | 107 | g_warning("Unexpected clipboard type %d\n",target); |
90 | 108 | } |
... | ... | @@ -109,7 +127,9 @@ void v3270_update_system_clipboard(GtkWidget *widget) |
109 | 127 | // Reference: https://cpp.hotexamples.com/examples/-/-/g_list_insert_sorted/cpp-g_list_insert_sorted-function-examples.html |
110 | 128 | // |
111 | 129 | static const GtkTargetEntry internal_targets[] = { |
112 | - { "text/csv", 0, CLIPBOARD_TYPE_CSV } | |
130 | + { "text/csv", 0, CLIPBOARD_TYPE_CSV }, | |
131 | + { "text/html", 0, CLIPBOARD_TYPE_HTML }, | |
132 | + { "application/x-v3270-unprotected", 0, CLIPBOARD_TYPE_V3270_UNPROTECTED }, | |
113 | 133 | }; |
114 | 134 | |
115 | 135 | GtkTargetList * list = gtk_target_list_new(internal_targets, G_N_ELEMENTS(internal_targets)); |
... | ... | @@ -147,3 +167,4 @@ void v3270_update_system_clipboard(GtkWidget *widget) |
147 | 167 | g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, TRUE); |
148 | 168 | |
149 | 169 | } |
170 | + | ... | ... |
src/selection/windows/paste.c
... | ... | @@ -18,7 +18,7 @@ |
18 | 18 | * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin |
19 | 19 | * St, Fifth Floor, Boston, MA 02110-1301 USA |
20 | 20 | * |
21 | - * Este programa está nomeado como - e possui - linhas de código. | |
21 | + * Este programa está nomeado como selection.c e possui - linhas de código. | |
22 | 22 | * |
23 | 23 | * Contatos: |
24 | 24 | * |
... | ... | @@ -27,40 +27,171 @@ |
27 | 27 | * |
28 | 28 | */ |
29 | 29 | |
30 | - #include <windows.h> | |
31 | 30 | #include <clipboard.h> |
32 | 31 | |
33 | 32 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
34 | 33 | |
35 | -LIB3270_EXPORT void v3270_paste_text(GtkWidget *widget) | |
34 | +static void text_received(G_GNUC_UNUSED GtkClipboard *clipboard, const gchar *text, GtkWidget *widget) | |
36 | 35 | { |
37 | - g_return_if_fail(GTK_IS_V3270(widget)); | |
36 | + v3270_input_text(widget,text,"UTF-8"); | |
37 | +} | |
38 | + | |
39 | +static gboolean has_target(const GdkAtom atom, const GdkAtom *atoms, const gint n_atoms) | |
40 | +{ | |
41 | + gint ix; | |
42 | + | |
43 | + for(ix = 0; ix < n_atoms; ix++) | |
44 | + { | |
45 | + if(atom == atoms[ix]) | |
46 | + return TRUE; | |
47 | + } | |
48 | + | |
49 | + return FALSE; | |
50 | +} | |
51 | + | |
52 | +static void formatted_received(GtkClipboard *clipboard, GtkSelectionData *selection_data, GtkWidget *widget) | |
53 | +{ | |
54 | + const struct SelectionHeader *selection = (const struct SelectionHeader *) gtk_selection_data_get_data(selection_data); | |
55 | + | |
56 | + v3270 * terminal = GTK_V3270(widget); | |
57 | + | |
58 | + debug( | |
59 | + "Received formatted data with %u bytes: Build=%u rows=%u cols=%u", | |
60 | + selection->length, | |
61 | + selection->build, | |
62 | + selection->rows, | |
63 | + selection->cols | |
64 | + ); | |
65 | + | |
66 | + if(selection->cols != lib3270_get_width(terminal->host) || selection->rows != lib3270_get_height(terminal->host)) | |
67 | + { | |
68 | + GtkWidget * dialog = | |
69 | + gtk_message_dialog_new( | |
70 | + GTK_WINDOW(gtk_widget_get_toplevel(widget)), | |
71 | + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, | |
72 | + GTK_MESSAGE_INFO, | |
73 | + GTK_BUTTONS_NONE, | |
74 | + _("Not the same terminal type") | |
75 | + ); | |
76 | + | |
77 | + | |
78 | + gtk_window_set_title(GTK_WINDOW(dialog),_("Can't paste")); | |
79 | + | |
80 | + gtk_dialog_add_buttons( | |
81 | + GTK_DIALOG (dialog), | |
82 | + _("_Cancel"), GTK_RESPONSE_CANCEL, | |
83 | + _("_Paste as text"), GTK_RESPONSE_APPLY, | |
84 | + NULL | |
85 | + ); | |
86 | + | |
87 | + gtk_dialog_set_default_response(GTK_DIALOG (dialog),GTK_RESPONSE_APPLY); | |
88 | + | |
89 | + gint response = gtk_dialog_run(GTK_DIALOG(dialog)); | |
90 | + | |
91 | + gtk_widget_destroy(dialog); | |
92 | + | |
93 | + if(response == GTK_RESPONSE_APPLY) | |
94 | + { | |
95 | + gtk_clipboard_request_text( | |
96 | + clipboard, | |
97 | + (GtkClipboardTextReceivedFunc) text_received, | |
98 | + (gpointer) widget | |
99 | + ); | |
100 | + } | |
38 | 101 | |
39 | - if (!OpenClipboard(NULL)) | |
40 | 102 | return; |
41 | 103 | |
42 | - if (IsClipboardFormatAvailable(CF_TEXT)) | |
104 | + } | |
105 | + | |
106 | + if(!v3270_set_from_data_block(terminal, selection)) | |
43 | 107 | { |
44 | - // Got text formatted clipboard. | |
45 | - HGLOBAL hglb; | |
108 | + GtkWidget * dialog = | |
109 | + gtk_message_dialog_new( | |
110 | + GTK_WINDOW(gtk_widget_get_toplevel(widget)), | |
111 | + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, | |
112 | + GTK_MESSAGE_INFO, | |
113 | + GTK_BUTTONS_NONE, | |
114 | + _("Unable to paste formatted data") | |
115 | + ); | |
116 | + | |
117 | + | |
118 | + gtk_window_set_title(GTK_WINDOW(dialog),_("Can't paste")); | |
119 | + | |
120 | + gtk_dialog_add_buttons( | |
121 | + GTK_DIALOG (dialog), | |
122 | + _("_Cancel"), GTK_RESPONSE_CANCEL, | |
123 | + _("_Paste as text"), GTK_RESPONSE_APPLY, | |
124 | + NULL | |
125 | + ); | |
46 | 126 | |
47 | - hglb = GetClipboardData(CF_TEXT); | |
48 | - if (hglb != NULL) | |
127 | + gtk_dialog_set_default_response(GTK_DIALOG (dialog),GTK_RESPONSE_APPLY); | |
128 | + | |
129 | + gint response = gtk_dialog_run(GTK_DIALOG(dialog)); | |
130 | + | |
131 | + gtk_widget_destroy(dialog); | |
132 | + | |
133 | + if(response == GTK_RESPONSE_APPLY) | |
49 | 134 | { |
50 | - LPTSTR lptstr = GlobalLock(hglb); | |
51 | - if (lptstr != NULL) | |
52 | - { | |
53 | - v3270_input_text(widget,lptstr,"CP1252"); | |
54 | - GlobalUnlock(hglb); | |
55 | - } | |
135 | + gtk_clipboard_request_text( | |
136 | + clipboard, | |
137 | + (GtkClipboardTextReceivedFunc) text_received, | |
138 | + (gpointer) widget | |
139 | + ); | |
56 | 140 | } |
141 | + | |
142 | + return; | |
143 | + | |
144 | + | |
57 | 145 | } |
58 | 146 | |
59 | - CloseClipboard(); | |
147 | + | |
148 | +} | |
149 | + | |
150 | +static void targets_received(GtkClipboard *clipboard, GdkAtom *atoms, gint n_atoms, GtkWidget *widget) | |
151 | +{ | |
152 | + if(has_target(GTK_V3270_GET_CLASS(widget)->clipboard_formatted,atoms,n_atoms)) | |
153 | + { | |
154 | + debug("Clipboard as TN3270 \"%s\" data",gdk_atom_name(GTK_V3270_GET_CLASS(widget)->clipboard_formatted)); | |
155 | + | |
156 | + gtk_clipboard_request_contents( | |
157 | + clipboard, | |
158 | + GTK_V3270_GET_CLASS(widget)->clipboard_formatted, | |
159 | + (GtkClipboardReceivedFunc) formatted_received, | |
160 | + (gpointer) widget | |
161 | + ); | |
162 | + | |
163 | + return; | |
164 | + } | |
165 | + | |
166 | + // No special format available, request it as text. | |
167 | + gtk_clipboard_request_text( | |
168 | + clipboard, | |
169 | + (GtkClipboardTextReceivedFunc) text_received, | |
170 | + (gpointer) widget | |
171 | + ); | |
60 | 172 | |
61 | 173 | } |
62 | 174 | |
63 | 175 | LIB3270_EXPORT void v3270_paste(GtkWidget *widget) |
64 | 176 | { |
65 | - v3270_paste(widget); | |
177 | + g_return_if_fail(GTK_IS_V3270(widget)); | |
178 | + | |
179 | + GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,GTK_V3270(widget)->selection.target); | |
180 | + | |
181 | + gtk_clipboard_request_targets(clipboard, (GtkClipboardTargetsReceivedFunc) targets_received, (gpointer) widget); | |
182 | + | |
183 | +} | |
184 | + | |
185 | +LIB3270_EXPORT void v3270_paste_text(GtkWidget *widget) | |
186 | +{ | |
187 | + g_return_if_fail(GTK_IS_V3270(widget)); | |
188 | + GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,GTK_V3270(widget)->selection.target); | |
189 | + | |
190 | + gtk_clipboard_request_text( | |
191 | + clipboard, | |
192 | + (GtkClipboardTextReceivedFunc) text_received, | |
193 | + (gpointer) widget | |
194 | + ); | |
195 | + | |
66 | 196 | } |
197 | + | ... | ... |
src/testprogram/testprogram.c
... | ... | @@ -92,6 +92,10 @@ static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { |
92 | 92 | |
93 | 93 | gtk_notebook_append_page(GTK_NOTEBOOK(notebook),terminal,gtk_label_new("Terminal")); |
94 | 94 | |
95 | +#ifdef _WIN32 | |
96 | + v3270_set_font_family(terminal,"Droid Sans Mono"); | |
97 | +#endif // _WIN32 | |
98 | + | |
95 | 99 | } |
96 | 100 | |
97 | 101 | // Create trace window | ... | ... |