Commit 65993c406917236583a6ac3de17affdd12e2c9f6
1 parent
f67e6894
Exists in
master
and in
1 other branch
Working with clipboard system.
Showing
10 changed files
with
754 additions
and
572 deletions
Show diff stats
Makefile.in
@@ -33,6 +33,8 @@ SOURCES= \ | @@ -33,6 +33,8 @@ SOURCES= \ | ||
33 | $(wildcard src/terminal/@OSNAME@/*.rc) \ | 33 | $(wildcard src/terminal/@OSNAME@/*.rc) \ |
34 | $(wildcard src/terminal/@OSNAME@/*.c) \ | 34 | $(wildcard src/terminal/@OSNAME@/*.c) \ |
35 | $(wildcard src/filetransfer/*.c) \ | 35 | $(wildcard src/filetransfer/*.c) \ |
36 | + $(wildcard src/clipboard/*.c) \ | ||
37 | + $(wildcard src/clipboard/@OSNAME@/*.c) \ | ||
36 | $(wildcard src/trace/*.c) \ | 38 | $(wildcard src/trace/*.c) \ |
37 | $(wildcard src/dialogs/*.c) \ | 39 | $(wildcard src/dialogs/*.c) \ |
38 | $(wildcard src/dialogs/@OSNAME@/*.c) \ | 40 | $(wildcard src/dialogs/@OSNAME@/*.c) \ |
@@ -0,0 +1,43 @@ | @@ -0,0 +1,43 @@ | ||
1 | +/* | ||
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | ||
5 | + * | ||
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
7 | + * | ||
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
10 | + * Free Software Foundation. | ||
11 | + * | ||
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
15 | + * obter mais detalhes. | ||
16 | + * | ||
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | ||
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | + * | ||
21 | + * Este programa está nomeado como selection.c e possui - linhas de código. | ||
22 | + * | ||
23 | + * Contatos: | ||
24 | + * | ||
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
27 | + * | ||
28 | + */ | ||
29 | + | ||
30 | + #include <clipboard.h> | ||
31 | + | ||
32 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
33 | + | ||
34 | +static void text_received(G_GNUC_UNUSED GtkClipboard *clipboard, const gchar *text, GtkWidget *widget) | ||
35 | +{ | ||
36 | + v3270_paste_string(widget,text,"UTF-8"); | ||
37 | +} | ||
38 | + | ||
39 | +LIB3270_EXPORT void v3270_paste(GtkWidget *widget) | ||
40 | +{ | ||
41 | + gtk_clipboard_request_text(gtk_widget_get_clipboard(widget,GDK_SELECTION_CLIPBOARD),(GtkClipboardTextReceivedFunc) text_received,(gpointer) widget); | ||
42 | +} | ||
43 | + |
@@ -0,0 +1,211 @@ | @@ -0,0 +1,211 @@ | ||
1 | +/* | ||
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | ||
5 | + * | ||
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
7 | + * | ||
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
10 | + * Free Software Foundation. | ||
11 | + * | ||
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
15 | + * obter mais detalhes. | ||
16 | + * | ||
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | ||
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | + * | ||
21 | + * Este programa está nomeado como selection.c e possui - linhas de código. | ||
22 | + * | ||
23 | + * Contatos: | ||
24 | + * | ||
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
27 | + * | ||
28 | + */ | ||
29 | + | ||
30 | + #include <clipboard.h> | ||
31 | + | ||
32 | +/*--[ Globals ]--------------------------------------------------------------------------------------*/ | ||
33 | + | ||
34 | + static const GtkTargetEntry targets[] = | ||
35 | + { | ||
36 | + { "COMPOUND_TEXT", 0, CLIPBOARD_TYPE_TEXT }, | ||
37 | + { "UTF8_STRING", 0, CLIPBOARD_TYPE_TEXT }, | ||
38 | + }; | ||
39 | + | ||
40 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
41 | + | ||
42 | +static void clipboard_clear(G_GNUC_UNUSED GtkClipboard *clipboard, G_GNUC_UNUSED GObject *obj) | ||
43 | +{ | ||
44 | +} | ||
45 | + | ||
46 | +static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionData *selection, guint target, GObject *obj) | ||
47 | +{ | ||
48 | + v3270 * widget = GTK_V3270(obj); | ||
49 | + | ||
50 | + switch(target) | ||
51 | + { | ||
52 | + case CLIPBOARD_TYPE_TEXT: /* Get clipboard contents as text */ | ||
53 | + if(!widget->selection.text) | ||
54 | + { | ||
55 | + lib3270_ring_bell(widget->host); | ||
56 | + } | ||
57 | + else | ||
58 | + { | ||
59 | + gchar * text = g_convert(widget->selection.text, -1, "UTF-8", lib3270_get_display_charset(widget->host), NULL, NULL, NULL); | ||
60 | + gtk_selection_data_set_text(selection,text,-1); | ||
61 | + g_free(text); | ||
62 | + } | ||
63 | + break; | ||
64 | + | ||
65 | + default: | ||
66 | + g_warning("Unexpected clipboard type %d\n",target); | ||
67 | + } | ||
68 | +} | ||
69 | + | ||
70 | +/** | ||
71 | + * Clear clipboard contents. | ||
72 | + * | ||
73 | + * @param terminal Pointer to the terminal Widget. | ||
74 | + * | ||
75 | + */ | ||
76 | +void v3270_clear_clipboard(v3270 *terminal) | ||
77 | +{ | ||
78 | + terminal->selection.text = lib3270_free(terminal->selection.text); | ||
79 | +} | ||
80 | + | ||
81 | +/** | ||
82 | + * Get lib3270 selection as a g_malloc buffer. | ||
83 | + * | ||
84 | + * @param widget Widget containing the desired section. | ||
85 | + * | ||
86 | + * @return NULL if error, otherwise the selected buffer contents (release with g_free). | ||
87 | + * | ||
88 | + */ | ||
89 | +LIB3270_EXPORT gchar * v3270_get_selected(GtkWidget *widget, gboolean cut) | ||
90 | +{ | ||
91 | + const char *text; | ||
92 | + | ||
93 | + g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | ||
94 | + | ||
95 | + text = v3270_update_selected_text(widget,cut); | ||
96 | + | ||
97 | + if(text) | ||
98 | + return g_convert(text, -1, "UTF-8", lib3270_get_display_charset(GTK_V3270(widget)->host), NULL, NULL, NULL); | ||
99 | + | ||
100 | + return NULL; | ||
101 | +} | ||
102 | + | ||
103 | +LIB3270_EXPORT gchar * v3270_get_copy(GtkWidget *widget) | ||
104 | +{ | ||
105 | + const char *text; | ||
106 | + g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | ||
107 | + | ||
108 | + text = GTK_V3270(widget)->selection.text; | ||
109 | + | ||
110 | + if(!text) | ||
111 | + text = v3270_update_selected_text(widget,FALSE); | ||
112 | + | ||
113 | + if(text) | ||
114 | + return g_convert(text, -1, "UTF-8", lib3270_get_display_charset(GTK_V3270(widget)->host), NULL, NULL, NULL); | ||
115 | + | ||
116 | + return NULL; | ||
117 | +} | ||
118 | + | ||
119 | +LIB3270_EXPORT void v3270_set_copy(GtkWidget *widget, const gchar *text) | ||
120 | +{ | ||
121 | + v3270 * terminal; | ||
122 | + gchar * isotext; | ||
123 | + | ||
124 | + g_return_if_fail(GTK_IS_V3270(widget)); | ||
125 | + | ||
126 | + terminal = GTK_V3270(widget); | ||
127 | + v3270_clear_clipboard(terminal); | ||
128 | + | ||
129 | + if(!text) | ||
130 | + { | ||
131 | + /* No string, signal clipboard clear and return */ | ||
132 | + g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, FALSE); | ||
133 | + return; | ||
134 | + } | ||
135 | + | ||
136 | + /* Received text, replace the selection buffer */ | ||
137 | + terminal->selection.format = V3270_SELECT_TEXT; | ||
138 | + isotext = g_convert(text, -1, lib3270_get_display_charset(terminal->host), "UTF-8", NULL, NULL, NULL); | ||
139 | + | ||
140 | + if(!isotext) | ||
141 | + { | ||
142 | + /* No string, signal clipboard clear and return */ | ||
143 | + g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, FALSE); | ||
144 | + return; | ||
145 | + } | ||
146 | + | ||
147 | + terminal->selection.text = lib3270_strdup(isotext); | ||
148 | + | ||
149 | + g_free(isotext); | ||
150 | + | ||
151 | + g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, TRUE); | ||
152 | +} | ||
153 | + | ||
154 | +void v3270_update_system_clipboard(GtkWidget *widget) | ||
155 | +{ | ||
156 | + if(GTK_V3270(widget)->selection.text) | ||
157 | + { | ||
158 | + GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,GDK_SELECTION_CLIPBOARD); | ||
159 | + | ||
160 | + if(gtk_clipboard_set_with_owner( | ||
161 | + clipboard, | ||
162 | + targets, | ||
163 | + G_N_ELEMENTS(targets), | ||
164 | + (GtkClipboardGetFunc) clipboard_get, | ||
165 | + (GtkClipboardClearFunc) clipboard_clear, | ||
166 | + G_OBJECT(widget) | ||
167 | + )) | ||
168 | + { | ||
169 | + gtk_clipboard_set_can_store(clipboard,targets,1); | ||
170 | + } | ||
171 | + | ||
172 | + g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, TRUE); | ||
173 | + } | ||
174 | +} | ||
175 | + | ||
176 | +LIB3270_EXPORT void v3270_copy(GtkWidget *widget, V3270_SELECT_FORMAT mode, gboolean cut) | ||
177 | +{ | ||
178 | + g_return_if_fail(GTK_IS_V3270(widget)); | ||
179 | + GTK_V3270(widget)->selection.format = mode; | ||
180 | + v3270_update_selected_text(widget,cut); | ||
181 | + v3270_update_system_clipboard(widget); | ||
182 | +} | ||
183 | + | ||
184 | +LIB3270_EXPORT void v3270_unselect(GtkWidget *widget) | ||
185 | +{ | ||
186 | + v3270_disable_updates(widget); | ||
187 | + lib3270_unselect(v3270_get_session(widget)); | ||
188 | + v3270_enable_updates(widget); | ||
189 | +} | ||
190 | + | ||
191 | +gboolean v3270_get_selection_bounds(GtkWidget *widget, gint *start, gint *end) | ||
192 | +{ | ||
193 | + g_return_val_if_fail(GTK_IS_V3270(widget),FALSE); | ||
194 | + return lib3270_get_selection_bounds(GTK_V3270(widget)->host,start,end) == 0 ? FALSE : TRUE; | ||
195 | +} | ||
196 | + | ||
197 | +LIB3270_EXPORT void v3270_select_region(GtkWidget *widget, gint start, gint end) | ||
198 | +{ | ||
199 | + g_return_if_fail(GTK_IS_V3270(widget)); | ||
200 | + lib3270_select_region(GTK_V3270(widget)->host,start,end); | ||
201 | +} | ||
202 | + | ||
203 | +LIB3270_EXPORT void v3270_select_all(GtkWidget *widget) | ||
204 | +{ | ||
205 | + g_return_if_fail(GTK_IS_V3270(widget)); | ||
206 | + v3270_disable_updates(widget); | ||
207 | + lib3270_select_all(v3270_get_session(widget)); | ||
208 | + v3270_enable_updates(widget); | ||
209 | +} | ||
210 | + | ||
211 | + |
@@ -0,0 +1,286 @@ | @@ -0,0 +1,286 @@ | ||
1 | +/* | ||
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | ||
5 | + * | ||
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
7 | + * | ||
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
10 | + * Free Software Foundation. | ||
11 | + * | ||
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
15 | + * obter mais detalhes. | ||
16 | + * | ||
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | ||
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | + * | ||
21 | + * Este programa está nomeado como - e possui - linhas de código. | ||
22 | + * | ||
23 | + * Contatos: | ||
24 | + * | ||
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
27 | + * | ||
28 | + */ | ||
29 | + | ||
30 | + #include <clipboard.h> | ||
31 | + | ||
32 | + | ||
33 | +LIB3270_EXPORT void v3270_copy_append(GtkWidget *widget) | ||
34 | +{ | ||
35 | + v3270 * terminal; | ||
36 | + char * str; | ||
37 | + | ||
38 | + g_return_if_fail(GTK_IS_V3270(widget)); | ||
39 | + | ||
40 | + terminal = GTK_V3270(widget); | ||
41 | + | ||
42 | + if(!terminal->selection.text) | ||
43 | + { | ||
44 | + // Clipboard is empty, do a single copy | ||
45 | + v3270_copy(widget, V3270_SELECT_TEXT, FALSE); | ||
46 | + return; | ||
47 | + } | ||
48 | + | ||
49 | + str = lib3270_get_selected(terminal->host); | ||
50 | + | ||
51 | + if(str) | ||
52 | + { | ||
53 | + size_t len = strlen(terminal->selection.text)+strlen(str)+2; | ||
54 | + | ||
55 | + terminal->selection.text = lib3270_realloc(terminal->selection.text,len); | ||
56 | + | ||
57 | + strncat(terminal->selection.text,"\n",len); | ||
58 | + strncat(terminal->selection.text,str,len); | ||
59 | + | ||
60 | + lib3270_free(str); | ||
61 | + } | ||
62 | + | ||
63 | + v3270_update_system_clipboard(widget); | ||
64 | + | ||
65 | +} | ||
66 | + | ||
67 | +const char * v3270_update_selected_text(GtkWidget *widget, gboolean cut) | ||
68 | +{ | ||
69 | + char * text; | ||
70 | + v3270 * terminal = GTK_V3270(widget); | ||
71 | + | ||
72 | + v3270_clear_clipboard(terminal); | ||
73 | + | ||
74 | + if(cut) | ||
75 | + text = lib3270_cut_selected(terminal->host); | ||
76 | + else | ||
77 | + text = lib3270_get_selected(terminal->host); | ||
78 | + | ||
79 | + if(!text) | ||
80 | + { | ||
81 | + g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, FALSE); | ||
82 | + lib3270_ring_bell(terminal->host); | ||
83 | + return NULL; | ||
84 | + } | ||
85 | + | ||
86 | + if(terminal->selection.format == V3270_SELECT_TABLE) | ||
87 | + { | ||
88 | + // Convert text to table | ||
89 | + gchar **ln = g_strsplit(text,"\n",-1); | ||
90 | + int width = lib3270_get_width(terminal->host); | ||
91 | + gboolean cols[width]; | ||
92 | + int l; | ||
93 | + GString * buffer; | ||
94 | + | ||
95 | + memset(cols,0,sizeof(gboolean)*width); | ||
96 | + | ||
97 | + // Find column delimiters | ||
98 | + for(l=0;ln[l];l++) | ||
99 | + { | ||
100 | + int c; | ||
101 | + gchar * ptr = ln[l]; | ||
102 | + | ||
103 | + for(c=0;c<width && *ptr;c++) | ||
104 | + { | ||
105 | + if(!g_ascii_isspace(*ptr)) | ||
106 | + cols[c] = TRUE; | ||
107 | + | ||
108 | + ptr++; | ||
109 | + } | ||
110 | + | ||
111 | + } | ||
112 | + | ||
113 | + // Read screen contents | ||
114 | + buffer = g_string_sized_new(strlen(text)); | ||
115 | + for(l=0;ln[l];l++) | ||
116 | + { | ||
117 | + int col = 0; | ||
118 | + gchar * src = ln[l]; | ||
119 | + | ||
120 | + while(col < width && *src) | ||
121 | + { | ||
122 | + if(col) | ||
123 | + g_string_append_c(buffer,'\t'); | ||
124 | + | ||
125 | + // Find column start | ||
126 | + while(!cols[col] && col < width && *src) | ||
127 | + { | ||
128 | + col++; | ||
129 | + src++; | ||
130 | + } | ||
131 | + | ||
132 | + if(col < width && *src) | ||
133 | + { | ||
134 | + gchar tmp[width+1]; | ||
135 | + gchar * dst = tmp; | ||
136 | + | ||
137 | + // Copy column content | ||
138 | + while(cols[col] && col < width && *src) | ||
139 | + { | ||
140 | + *dst = *src; | ||
141 | + col++; | ||
142 | + dst++; | ||
143 | + src++; | ||
144 | + } | ||
145 | + *dst = 0; | ||
146 | + g_string_append(buffer,g_strstrip(tmp)); | ||
147 | + } | ||
148 | + | ||
149 | + } | ||
150 | + g_string_append_c(buffer,'\n'); | ||
151 | + | ||
152 | + } | ||
153 | + | ||
154 | + g_strfreev(ln); | ||
155 | + g_free(text); | ||
156 | + | ||
157 | + text = g_string_free(buffer,FALSE); | ||
158 | + } | ||
159 | + | ||
160 | + return terminal->selection.text = text; | ||
161 | + | ||
162 | +} | ||
163 | + | ||
164 | +LIB3270_EXPORT void v3270_paste_string(GtkWidget *widget, const gchar *text, const gchar *encoding) | ||
165 | +{ | ||
166 | + gchar * buffer = NULL; | ||
167 | + H3270 * session = v3270_get_session(widget); | ||
168 | + const gchar * charset = lib3270_get_display_charset(session); | ||
169 | + gboolean next; | ||
170 | + | ||
171 | + if(!text) | ||
172 | + return; | ||
173 | + else if(g_ascii_strcasecmp(encoding,charset)) | ||
174 | + buffer = g_convert(text, -1, charset, encoding, NULL, NULL, NULL); | ||
175 | + else | ||
176 | + buffer = g_strdup(text); | ||
177 | + | ||
178 | + if(!buffer) | ||
179 | + { | ||
180 | + /* Conversion failed, update special chars and try again */ | ||
181 | + size_t f; | ||
182 | + | ||
183 | + static const struct _xlat | ||
184 | + { | ||
185 | + const gchar *from; | ||
186 | + const gchar *to; | ||
187 | + } xlat[] = | ||
188 | + { | ||
189 | + { "–", "-" }, | ||
190 | + { "→", "->" }, | ||
191 | + { "←", "<-" }, | ||
192 | + { "©", "(c)" }, | ||
193 | + { "↔", "<->" }, | ||
194 | + { "™", "(TM)" }, | ||
195 | + { "®", "(R)" }, | ||
196 | + { "“", "\"" }, | ||
197 | + { "”", "\"" }, | ||
198 | + { "…", "..." }, | ||
199 | + { "•", "*" }, | ||
200 | + { "․", "." }, | ||
201 | + { "·", "*" }, | ||
202 | + | ||
203 | + }; | ||
204 | + | ||
205 | + gchar *string = g_strdup(text); | ||
206 | + | ||
207 | + // FIXME (perry#1#): Is there any better way for a "sed" here? | ||
208 | + for(f=0;f<G_N_ELEMENTS(xlat);f++) | ||
209 | + { | ||
210 | + gchar *ptr = g_strstr_len(string,-1,xlat[f].from); | ||
211 | + | ||
212 | + if(ptr) | ||
213 | + { | ||
214 | + gchar *old = string; | ||
215 | + gchar **tmp = g_strsplit(old,xlat[f].from,-1); | ||
216 | + string = g_strjoinv(xlat[f].to,tmp); | ||
217 | + g_strfreev(tmp); | ||
218 | + g_free(old); | ||
219 | + } | ||
220 | + } | ||
221 | + | ||
222 | + buffer = g_convert(string, -1, charset, encoding, NULL, NULL, NULL); | ||
223 | + | ||
224 | + if(!buffer) | ||
225 | + { | ||
226 | + // Still failing, convert line by line | ||
227 | + gchar **ln = g_strsplit(string,"\n",-1); | ||
228 | + | ||
229 | + for(f=0;ln[f];f++) | ||
230 | + { | ||
231 | + GError *error = NULL; | ||
232 | + gchar *str = g_convert(ln[f], -1, charset, encoding, NULL, NULL, &error); | ||
233 | + | ||
234 | + if(!str) | ||
235 | + { | ||
236 | + GtkWidget *dialog = gtk_message_dialog_new( GTK_WINDOW( gtk_widget_get_toplevel(widget)), | ||
237 | + GTK_DIALOG_DESTROY_WITH_PARENT, | ||
238 | + GTK_MESSAGE_ERROR, | ||
239 | + GTK_BUTTONS_OK, | ||
240 | + _( "Can't convert line %lu from %s to %s" ),(unsigned long) (f+1), encoding, charset); | ||
241 | + | ||
242 | + gtk_window_set_title(GTK_WINDOW(dialog), _( "Charset error" ) ); | ||
243 | + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s\n%s",error->message, ln[f]); | ||
244 | + | ||
245 | + gtk_dialog_run(GTK_DIALOG (dialog)); | ||
246 | + gtk_widget_destroy(dialog); | ||
247 | + | ||
248 | + break; | ||
249 | + } | ||
250 | + else | ||
251 | + { | ||
252 | + g_free(str); | ||
253 | + } | ||
254 | + | ||
255 | + } | ||
256 | + g_strfreev(ln); | ||
257 | + | ||
258 | + } | ||
259 | + | ||
260 | + g_free(string); | ||
261 | + } | ||
262 | + | ||
263 | + if(buffer) | ||
264 | + { | ||
265 | + /* Remove TABS */ | ||
266 | + gchar *ptr; | ||
267 | + | ||
268 | + for(ptr = buffer;*ptr;ptr++) | ||
269 | + { | ||
270 | + if(*ptr == '\t') | ||
271 | + *ptr = ' '; | ||
272 | + } | ||
273 | + } | ||
274 | + else | ||
275 | + { | ||
276 | + g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_PASTENEXT], 0, FALSE); | ||
277 | + return; | ||
278 | + } | ||
279 | + | ||
280 | + next = lib3270_paste(session,(unsigned char *) buffer) ? TRUE : FALSE; | ||
281 | + | ||
282 | + g_free(buffer); | ||
283 | + | ||
284 | + g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_PASTENEXT], 0, next); | ||
285 | + | ||
286 | +} |
@@ -0,0 +1,58 @@ | @@ -0,0 +1,58 @@ | ||
1 | +/* | ||
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | ||
5 | + * | ||
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
7 | + * | ||
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
10 | + * Free Software Foundation. | ||
11 | + * | ||
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
15 | + * obter mais detalhes. | ||
16 | + * | ||
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | ||
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | + * | ||
21 | + * Este programa está nomeado como selection.c e possui - linhas de código. | ||
22 | + * | ||
23 | + * Contatos: | ||
24 | + * | ||
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
27 | + * | ||
28 | + */ | ||
29 | + | ||
30 | + #include <windows.h> | ||
31 | + #include <clipboard.h> | ||
32 | + | ||
33 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
34 | + | ||
35 | +LIB3270_EXPORT void v3270_paste(GtkWidget *widget) | ||
36 | +{ | ||
37 | + HGLOBAL hglb; | ||
38 | + | ||
39 | + if (!IsClipboardFormatAvailable(CF_TEXT)) | ||
40 | + return; | ||
41 | + | ||
42 | + if (!OpenClipboard(NULL)) | ||
43 | + return; | ||
44 | + | ||
45 | + hglb = GetClipboardData(CF_TEXT); | ||
46 | + if (hglb != NULL) | ||
47 | + { | ||
48 | + LPTSTR lptstr = GlobalLock(hglb); | ||
49 | + if (lptstr != NULL) | ||
50 | + { | ||
51 | + v3270_paste_string(widget,lptstr,"CP1252"); | ||
52 | + GlobalUnlock(hglb); | ||
53 | + } | ||
54 | + } | ||
55 | + | ||
56 | + CloseClipboard(); | ||
57 | + | ||
58 | +} |
@@ -0,0 +1,54 @@ | @@ -0,0 +1,54 @@ | ||
1 | +/* | ||
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | ||
5 | + * | ||
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
7 | + * | ||
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
10 | + * Free Software Foundation. | ||
11 | + * | ||
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
15 | + * obter mais detalhes. | ||
16 | + * | ||
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | ||
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | + * | ||
21 | + * Este programa está nomeado como clipboard.h e possui - linhas de código. | ||
22 | + * | ||
23 | + * Contatos: | ||
24 | + * | ||
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
27 | + * | ||
28 | + */ | ||
29 | + | ||
30 | +#ifndef V3270_CLIPBOARD_H_INCLUDED | ||
31 | + | ||
32 | + #define V3270_CLIPBOARD_H_INCLUDED | ||
33 | + | ||
34 | + #include <gtk/gtk.h> | ||
35 | + #include <lib3270.h> | ||
36 | + #include <v3270.h> | ||
37 | + #include <terminal.h> | ||
38 | + #include <internals.h> | ||
39 | + #include <lib3270/selection.h> | ||
40 | + #include <lib3270/log.h> | ||
41 | + #include <lib3270/actions.h> | ||
42 | + | ||
43 | + enum | ||
44 | + { | ||
45 | + CLIPBOARD_TYPE_TEXT, | ||
46 | + }; | ||
47 | + | ||
48 | + G_GNUC_INTERNAL void v3270_update_system_clipboard(GtkWidget *widget); | ||
49 | + G_GNUC_INTERNAL const char * v3270_update_selected_text(GtkWidget *widget, gboolean cut); | ||
50 | + | ||
51 | + | ||
52 | + | ||
53 | +#endif // V3270_CLIPBOARD_H_INCLUDED | ||
54 | + |
src/include/terminal.h
@@ -101,7 +101,6 @@ G_BEGIN_DECLS | @@ -101,7 +101,6 @@ G_BEGIN_DECLS | ||
101 | int selecting : 1; /**< Selecting region */ | 101 | int selecting : 1; /**< Selecting region */ |
102 | int moving : 1; /**< Moving selected region */ | 102 | int moving : 1; /**< Moving selected region */ |
103 | int resizing : 1; /**< Resizing selected region */ | 103 | int resizing : 1; /**< Resizing selected region */ |
104 | - int table : 1; /**< Copy mode is table */ | ||
105 | int scaled_fonts : 1; /**< Use scaled fonts */ | 104 | int scaled_fonts : 1; /**< Use scaled fonts */ |
106 | int drawing : 1; /**< Draw widget? */ | 105 | int drawing : 1; /**< Draw widget? */ |
107 | 106 | ||
@@ -118,8 +117,9 @@ G_BEGIN_DECLS | @@ -118,8 +117,9 @@ G_BEGIN_DECLS | ||
118 | 117 | ||
119 | struct | 118 | struct |
120 | { | 119 | { |
121 | - char * text; /**< Clipboard contents (lib3270 charset) */ | ||
122 | - int baddr; /**< Selection addr */ | 120 | + V3270_SELECT_FORMAT format; /**< Copy format */ |
121 | + char * text; /**< Clipboard contents (lib3270 charset) */ | ||
122 | + int baddr; /**< Selection addr */ | ||
123 | } selection; | 123 | } selection; |
124 | 124 | ||
125 | LIB3270_POINTER pointer_id; | 125 | LIB3270_POINTER pointer_id; |
@@ -0,0 +1,81 @@ | @@ -0,0 +1,81 @@ | ||
1 | +/* | ||
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | ||
5 | + * | ||
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
7 | + * | ||
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
10 | + * Free Software Foundation. | ||
11 | + * | ||
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
15 | + * obter mais detalhes. | ||
16 | + * | ||
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | ||
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | + * | ||
21 | + * Este programa está nomeado como - e possui - linhas de código. | ||
22 | + * | ||
23 | + * Contatos: | ||
24 | + * | ||
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
27 | + * | ||
28 | + */ | ||
29 | + | ||
30 | + #include <internals.h> | ||
31 | + #include <terminal.h> | ||
32 | + #include <lib3270/selection.h> | ||
33 | + | ||
34 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
35 | + | ||
36 | +/** | ||
37 | + * Get text at informed area. | ||
38 | + * | ||
39 | + * @param widget Widget. | ||
40 | + * @param offset Offset of the desired text. | ||
41 | + * @param len Number of characters to get. | ||
42 | + * | ||
43 | + */ | ||
44 | +LIB3270_EXPORT gchar * v3270_get_text(GtkWidget *widget, int offset, int len) | ||
45 | +{ | ||
46 | + v3270 * terminal; | ||
47 | + gchar * text; | ||
48 | + char * str; | ||
49 | + | ||
50 | + g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | ||
51 | + | ||
52 | + terminal = GTK_V3270(widget); | ||
53 | + | ||
54 | + str = lib3270_get_string_at_address(terminal->host, offset, len, '\n'); | ||
55 | + | ||
56 | + if(!str) | ||
57 | + return NULL; | ||
58 | + | ||
59 | + text = g_convert(str, -1, "UTF-8", lib3270_get_display_charset(terminal->host), NULL, NULL, NULL); | ||
60 | + | ||
61 | + lib3270_free(str); | ||
62 | + return text; | ||
63 | +} | ||
64 | + | ||
65 | +gchar * v3270_get_region(GtkWidget *widget, gint start_pos, gint end_pos, gboolean all) | ||
66 | +{ | ||
67 | + char * str; | ||
68 | + gchar * utftext; | ||
69 | + | ||
70 | + g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | ||
71 | + | ||
72 | + str = lib3270_get_region(GTK_V3270(widget)->host,start_pos,end_pos,all); | ||
73 | + if(!str) | ||
74 | + return NULL; | ||
75 | + | ||
76 | + utftext = g_convert(str, -1, "UTF-8", lib3270_get_display_charset(GTK_V3270(widget)->host), NULL, NULL, NULL); | ||
77 | + | ||
78 | + lib3270_free(str); | ||
79 | + | ||
80 | + return utftext; | ||
81 | +} |
src/terminal/selection.c
@@ -1,566 +0,0 @@ | @@ -1,566 +0,0 @@ | ||
1 | -/* | ||
2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | ||
5 | - * | ||
6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
7 | - * | ||
8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
10 | - * Free Software Foundation. | ||
11 | - * | ||
12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
15 | - * obter mais detalhes. | ||
16 | - * | ||
17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | ||
19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | - * | ||
21 | - * Este programa está nomeado como selection.c e possui - linhas de código. | ||
22 | - * | ||
23 | - * Contatos: | ||
24 | - * | ||
25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
27 | - * | ||
28 | - */ | ||
29 | - | ||
30 | - #include <gtk/gtk.h> | ||
31 | - #include <lib3270.h> | ||
32 | - #include <v3270.h> | ||
33 | - #include <terminal.h> | ||
34 | - #include <internals.h> | ||
35 | - #include <lib3270/selection.h> | ||
36 | - #include <lib3270/log.h> | ||
37 | - #include <lib3270/actions.h> | ||
38 | - | ||
39 | -/*--[ Globals ]--------------------------------------------------------------------------------------*/ | ||
40 | - | ||
41 | - enum | ||
42 | - { | ||
43 | - CLIPBOARD_TYPE_TEXT, | ||
44 | - }; | ||
45 | - | ||
46 | - static const GtkTargetEntry targets[] = | ||
47 | - { | ||
48 | - { "COMPOUND_TEXT", 0, CLIPBOARD_TYPE_TEXT }, | ||
49 | - { "UTF8_STRING", 0, CLIPBOARD_TYPE_TEXT }, | ||
50 | - }; | ||
51 | - | ||
52 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
53 | - | ||
54 | -static void clipboard_clear(G_GNUC_UNUSED GtkClipboard *clipboard, G_GNUC_UNUSED GObject *obj) | ||
55 | -{ | ||
56 | -} | ||
57 | - | ||
58 | -static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionData *selection, guint target, GObject *obj) | ||
59 | -{ | ||
60 | - v3270 * widget = GTK_V3270(obj); | ||
61 | - | ||
62 | - switch(target) | ||
63 | - { | ||
64 | - case CLIPBOARD_TYPE_TEXT: /* Get clipboard contents as text */ | ||
65 | - if(!widget->selection.text) | ||
66 | - { | ||
67 | - lib3270_ring_bell(widget->host); | ||
68 | - } | ||
69 | - else | ||
70 | - { | ||
71 | - gchar * text = g_convert(widget->selection.text, -1, "UTF-8", lib3270_get_display_charset(widget->host), NULL, NULL, NULL); | ||
72 | - gtk_selection_data_set_text(selection,text,-1); | ||
73 | - g_free(text); | ||
74 | - } | ||
75 | - break; | ||
76 | - | ||
77 | - default: | ||
78 | - g_warning("Unexpected clipboard type %d\n",target); | ||
79 | - } | ||
80 | -} | ||
81 | - | ||
82 | -/** | ||
83 | - * Clear clipboard contents. | ||
84 | - * | ||
85 | - * @param terminal Pointer to the terminal Widget. | ||
86 | - * | ||
87 | - */ | ||
88 | -void v3270_clear_clipboard(v3270 *terminal) | ||
89 | -{ | ||
90 | - terminal->selection.text = lib3270_free(terminal->selection.text); | ||
91 | -} | ||
92 | - | ||
93 | -/** | ||
94 | - * Get text at informed area. | ||
95 | - * | ||
96 | - * @param widget Widget. | ||
97 | - * @param offset Offset of the desired text. | ||
98 | - * @param len Number of characters to get. | ||
99 | - * | ||
100 | - */ | ||
101 | -LIB3270_EXPORT gchar * v3270_get_text(GtkWidget *widget, int offset, int len) | ||
102 | -{ | ||
103 | - v3270 * terminal; | ||
104 | - gchar * text; | ||
105 | - char * str; | ||
106 | - | ||
107 | - g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | ||
108 | - | ||
109 | - terminal = GTK_V3270(widget); | ||
110 | - | ||
111 | - str = lib3270_get_string_at_address(terminal->host, offset, len, '\n'); | ||
112 | - | ||
113 | - if(!str) | ||
114 | - return NULL; | ||
115 | - | ||
116 | - text = g_convert(str, -1, "UTF-8", lib3270_get_display_charset(terminal->host), NULL, NULL, NULL); | ||
117 | - | ||
118 | - lib3270_free(str); | ||
119 | - return text; | ||
120 | -} | ||
121 | - | ||
122 | -static const char * update_selected_text(GtkWidget *widget, gboolean cut) | ||
123 | -{ | ||
124 | - char * text; | ||
125 | - v3270 * terminal = GTK_V3270(widget); | ||
126 | - | ||
127 | - v3270_clear_clipboard(terminal); | ||
128 | - | ||
129 | - if(cut) | ||
130 | - text = lib3270_cut_selected(terminal->host); | ||
131 | - else | ||
132 | - text = lib3270_get_selected(terminal->host); | ||
133 | - | ||
134 | - if(!text) | ||
135 | - { | ||
136 | - g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, FALSE); | ||
137 | - lib3270_ring_bell(terminal->host); | ||
138 | - return NULL; | ||
139 | - } | ||
140 | - | ||
141 | - if(terminal->table) | ||
142 | - { | ||
143 | - // Convert text to table | ||
144 | - gchar **ln = g_strsplit(text,"\n",-1); | ||
145 | - int width = lib3270_get_width(terminal->host); | ||
146 | - gboolean cols[width]; | ||
147 | - int l; | ||
148 | - GString * buffer; | ||
149 | - | ||
150 | - memset(cols,0,sizeof(gboolean)*width); | ||
151 | - | ||
152 | - // Find column delimiters | ||
153 | - for(l=0;ln[l];l++) | ||
154 | - { | ||
155 | - int c; | ||
156 | - gchar * ptr = ln[l]; | ||
157 | - | ||
158 | - for(c=0;c<width && *ptr;c++) | ||
159 | - { | ||
160 | - if(!g_ascii_isspace(*ptr)) | ||
161 | - cols[c] = TRUE; | ||
162 | - | ||
163 | - ptr++; | ||
164 | - } | ||
165 | - | ||
166 | - } | ||
167 | - | ||
168 | - // Read screen contents | ||
169 | - buffer = g_string_sized_new(strlen(text)); | ||
170 | - for(l=0;ln[l];l++) | ||
171 | - { | ||
172 | - int col = 0; | ||
173 | - gchar * src = ln[l]; | ||
174 | - | ||
175 | - while(col < width && *src) | ||
176 | - { | ||
177 | - if(col) | ||
178 | - g_string_append_c(buffer,'\t'); | ||
179 | - | ||
180 | - // Find column start | ||
181 | - while(!cols[col] && col < width && *src) | ||
182 | - { | ||
183 | - col++; | ||
184 | - src++; | ||
185 | - } | ||
186 | - | ||
187 | - if(col < width && *src) | ||
188 | - { | ||
189 | - gchar tmp[width+1]; | ||
190 | - gchar * dst = tmp; | ||
191 | - | ||
192 | - // Copy column content | ||
193 | - while(cols[col] && col < width && *src) | ||
194 | - { | ||
195 | - *dst = *src; | ||
196 | - col++; | ||
197 | - dst++; | ||
198 | - src++; | ||
199 | - } | ||
200 | - *dst = 0; | ||
201 | - g_string_append(buffer,g_strstrip(tmp)); | ||
202 | - } | ||
203 | - | ||
204 | - } | ||
205 | - g_string_append_c(buffer,'\n'); | ||
206 | - | ||
207 | - } | ||
208 | - | ||
209 | - g_strfreev(ln); | ||
210 | - g_free(text); | ||
211 | - | ||
212 | - text = g_string_free(buffer,FALSE); | ||
213 | - } | ||
214 | - | ||
215 | - return terminal->selection.text = text; | ||
216 | - | ||
217 | -} | ||
218 | - | ||
219 | -/** | ||
220 | - * Get lib3270 selection as a g_malloc buffer. | ||
221 | - * | ||
222 | - * @param widget Widget containing the desired section. | ||
223 | - * | ||
224 | - * @return NULL if error, otherwise the selected buffer contents (release with g_free). | ||
225 | - * | ||
226 | - */ | ||
227 | -LIB3270_EXPORT gchar * v3270_get_selected(GtkWidget *widget, gboolean cut) | ||
228 | -{ | ||
229 | - const char *text; | ||
230 | - | ||
231 | - g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | ||
232 | - | ||
233 | - text = update_selected_text(widget,cut); | ||
234 | - | ||
235 | - if(text) | ||
236 | - return g_convert(text, -1, "UTF-8", lib3270_get_display_charset(GTK_V3270(widget)->host), NULL, NULL, NULL); | ||
237 | - | ||
238 | - return NULL; | ||
239 | -} | ||
240 | - | ||
241 | -LIB3270_EXPORT gchar * v3270_get_copy(GtkWidget *widget) | ||
242 | -{ | ||
243 | - const char *text; | ||
244 | - g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | ||
245 | - | ||
246 | - text = GTK_V3270(widget)->selection.text; | ||
247 | - | ||
248 | - if(!text) | ||
249 | - text = update_selected_text(widget,FALSE); | ||
250 | - | ||
251 | - if(text) | ||
252 | - return g_convert(text, -1, "UTF-8", lib3270_get_display_charset(GTK_V3270(widget)->host), NULL, NULL, NULL); | ||
253 | - | ||
254 | - return NULL; | ||
255 | -} | ||
256 | - | ||
257 | -LIB3270_EXPORT void v3270_set_copy(GtkWidget *widget, const gchar *text) | ||
258 | -{ | ||
259 | - v3270 * terminal; | ||
260 | - gchar * isotext; | ||
261 | - | ||
262 | - g_return_if_fail(GTK_IS_V3270(widget)); | ||
263 | - | ||
264 | - terminal = GTK_V3270(widget); | ||
265 | - v3270_clear_clipboard(terminal); | ||
266 | - | ||
267 | - if(!text) | ||
268 | - { | ||
269 | - /* No string, signal clipboard clear and return */ | ||
270 | - g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, FALSE); | ||
271 | - return; | ||
272 | - } | ||
273 | - | ||
274 | - /* Received text, replace the selection buffer */ | ||
275 | - terminal->table = 0; | ||
276 | - isotext = g_convert(text, -1, lib3270_get_display_charset(terminal->host), "UTF-8", NULL, NULL, NULL); | ||
277 | - | ||
278 | - if(!isotext) | ||
279 | - { | ||
280 | - /* No string, signal clipboard clear and return */ | ||
281 | - g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, FALSE); | ||
282 | - return; | ||
283 | - } | ||
284 | - | ||
285 | - terminal->selection.text = lib3270_strdup(isotext); | ||
286 | - | ||
287 | - g_free(isotext); | ||
288 | - | ||
289 | - g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, TRUE); | ||
290 | -} | ||
291 | - | ||
292 | -static void update_system_clipboard(GtkWidget *widget) | ||
293 | -{ | ||
294 | - if(GTK_V3270(widget)->selection.text) | ||
295 | - { | ||
296 | - GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,GDK_SELECTION_CLIPBOARD); | ||
297 | - | ||
298 | - if(gtk_clipboard_set_with_owner( clipboard, | ||
299 | - targets, | ||
300 | - G_N_ELEMENTS(targets), | ||
301 | - (GtkClipboardGetFunc) clipboard_get, | ||
302 | - (GtkClipboardClearFunc) clipboard_clear, | ||
303 | - G_OBJECT(widget) | ||
304 | - )) | ||
305 | - { | ||
306 | - gtk_clipboard_set_can_store(clipboard,targets,1); | ||
307 | - } | ||
308 | - | ||
309 | - g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_CLIPBOARD], 0, TRUE); | ||
310 | - } | ||
311 | -} | ||
312 | - | ||
313 | - | ||
314 | -LIB3270_EXPORT void v3270_copy_append(GtkWidget *widget) | ||
315 | -{ | ||
316 | - v3270 * terminal; | ||
317 | - char * str; | ||
318 | - | ||
319 | - g_return_if_fail(GTK_IS_V3270(widget)); | ||
320 | - | ||
321 | - terminal = GTK_V3270(widget); | ||
322 | - | ||
323 | - if(!terminal->selection.text) | ||
324 | - { | ||
325 | - // Clipboard is empty, do a single copy | ||
326 | - v3270_copy(widget, V3270_SELECT_TEXT, FALSE); | ||
327 | - return; | ||
328 | - } | ||
329 | - | ||
330 | - str = lib3270_get_selected(terminal->host); | ||
331 | - | ||
332 | - if(str) | ||
333 | - { | ||
334 | - size_t len = strlen(terminal->selection.text)+strlen(str)+2; | ||
335 | - | ||
336 | - terminal->selection.text = lib3270_realloc(terminal->selection.text,len); | ||
337 | - | ||
338 | - strncat(terminal->selection.text,"\n",len); | ||
339 | - strncat(terminal->selection.text,str,len); | ||
340 | - | ||
341 | - lib3270_free(str); | ||
342 | - } | ||
343 | - | ||
344 | - update_system_clipboard(widget); | ||
345 | - | ||
346 | -} | ||
347 | - | ||
348 | -LIB3270_EXPORT void v3270_copy(GtkWidget *widget, V3270_SELECT_FORMAT mode, gboolean cut) | ||
349 | -{ | ||
350 | - g_return_if_fail(GTK_IS_V3270(widget)); | ||
351 | - GTK_V3270(widget)->table = (mode == V3270_SELECT_TABLE ? 1 : 0); | ||
352 | - update_selected_text(widget,cut); | ||
353 | - update_system_clipboard(widget); | ||
354 | -} | ||
355 | - | ||
356 | -#ifdef _WIN32 | ||
357 | - | ||
358 | -LIB3270_EXPORT void v3270_paste(GtkWidget *widget) | ||
359 | -{ | ||
360 | - HGLOBAL hglb; | ||
361 | - | ||
362 | - if (!IsClipboardFormatAvailable(CF_TEXT)) | ||
363 | - return; | ||
364 | - | ||
365 | - if (!OpenClipboard(NULL)) | ||
366 | - return; | ||
367 | - | ||
368 | - hglb = GetClipboardData(CF_TEXT); | ||
369 | - if (hglb != NULL) | ||
370 | - { | ||
371 | - LPTSTR lptstr = GlobalLock(hglb); | ||
372 | - if (lptstr != NULL) | ||
373 | - { | ||
374 | - v3270_paste_string(widget,lptstr,"CP1252"); | ||
375 | - GlobalUnlock(hglb); | ||
376 | - } | ||
377 | - } | ||
378 | - | ||
379 | - CloseClipboard(); | ||
380 | - | ||
381 | -} | ||
382 | - | ||
383 | -#else | ||
384 | - | ||
385 | -static void text_received(G_GNUC_UNUSED GtkClipboard *clipboard, const gchar *text, GtkWidget *widget) | ||
386 | -{ | ||
387 | - v3270_paste_string(widget,text,"UTF-8"); | ||
388 | -} | ||
389 | - | ||
390 | -LIB3270_EXPORT void v3270_paste(GtkWidget *widget) | ||
391 | -{ | ||
392 | - gtk_clipboard_request_text(gtk_widget_get_clipboard(widget,GDK_SELECTION_CLIPBOARD),(GtkClipboardTextReceivedFunc) text_received,(gpointer) widget); | ||
393 | -} | ||
394 | - | ||
395 | -#endif // _WIN32 | ||
396 | - | ||
397 | -LIB3270_EXPORT void v3270_paste_string(GtkWidget *widget, const gchar *text, const gchar *encoding) | ||
398 | -{ | ||
399 | - gchar * buffer = NULL; | ||
400 | - H3270 * session = v3270_get_session(widget); | ||
401 | - const gchar * charset = lib3270_get_display_charset(session); | ||
402 | - gboolean next; | ||
403 | - | ||
404 | - if(!text) | ||
405 | - return; | ||
406 | - else if(g_ascii_strcasecmp(encoding,charset)) | ||
407 | - buffer = g_convert(text, -1, charset, encoding, NULL, NULL, NULL); | ||
408 | - else | ||
409 | - buffer = g_strdup(text); | ||
410 | - | ||
411 | - if(!buffer) | ||
412 | - { | ||
413 | - /* Conversion failed, update special chars and try again */ | ||
414 | - size_t f; | ||
415 | - | ||
416 | - static const struct _xlat | ||
417 | - { | ||
418 | - const gchar *from; | ||
419 | - const gchar *to; | ||
420 | - } xlat[] = | ||
421 | - { | ||
422 | - { "–", "-" }, | ||
423 | - { "→", "->" }, | ||
424 | - { "←", "<-" }, | ||
425 | - { "©", "(c)" }, | ||
426 | - { "↔", "<->" }, | ||
427 | - { "™", "(TM)" }, | ||
428 | - { "®", "(R)" }, | ||
429 | - { "“", "\"" }, | ||
430 | - { "”", "\"" }, | ||
431 | - { "…", "..." }, | ||
432 | - { "•", "*" }, | ||
433 | - { "․", "." }, | ||
434 | - { "·", "*" }, | ||
435 | - | ||
436 | - }; | ||
437 | - | ||
438 | - gchar *string = g_strdup(text); | ||
439 | - | ||
440 | - // FIXME (perry#1#): Is there any better way for a "sed" here? | ||
441 | - for(f=0;f<G_N_ELEMENTS(xlat);f++) | ||
442 | - { | ||
443 | - gchar *ptr = g_strstr_len(string,-1,xlat[f].from); | ||
444 | - | ||
445 | - if(ptr) | ||
446 | - { | ||
447 | - gchar *old = string; | ||
448 | - gchar **tmp = g_strsplit(old,xlat[f].from,-1); | ||
449 | - string = g_strjoinv(xlat[f].to,tmp); | ||
450 | - g_strfreev(tmp); | ||
451 | - g_free(old); | ||
452 | - } | ||
453 | - } | ||
454 | - | ||
455 | - buffer = g_convert(string, -1, charset, encoding, NULL, NULL, NULL); | ||
456 | - | ||
457 | - if(!buffer) | ||
458 | - { | ||
459 | - // Still failing, convert line by line | ||
460 | - gchar **ln = g_strsplit(string,"\n",-1); | ||
461 | - | ||
462 | - for(f=0;ln[f];f++) | ||
463 | - { | ||
464 | - GError *error = NULL; | ||
465 | - gchar *str = g_convert(ln[f], -1, charset, encoding, NULL, NULL, &error); | ||
466 | - | ||
467 | - if(!str) | ||
468 | - { | ||
469 | - GtkWidget *dialog = gtk_message_dialog_new( GTK_WINDOW( gtk_widget_get_toplevel(widget)), | ||
470 | - GTK_DIALOG_DESTROY_WITH_PARENT, | ||
471 | - GTK_MESSAGE_ERROR, | ||
472 | - GTK_BUTTONS_OK, | ||
473 | - _( "Can't convert line %lu from %s to %s" ),(unsigned long) (f+1), encoding, charset); | ||
474 | - | ||
475 | - gtk_window_set_title(GTK_WINDOW(dialog), _( "Charset error" ) ); | ||
476 | - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s\n%s",error->message, ln[f]); | ||
477 | - | ||
478 | - gtk_dialog_run(GTK_DIALOG (dialog)); | ||
479 | - gtk_widget_destroy(dialog); | ||
480 | - | ||
481 | - break; | ||
482 | - } | ||
483 | - else | ||
484 | - { | ||
485 | - g_free(str); | ||
486 | - } | ||
487 | - | ||
488 | - } | ||
489 | - g_strfreev(ln); | ||
490 | - | ||
491 | - } | ||
492 | - | ||
493 | - g_free(string); | ||
494 | - } | ||
495 | - | ||
496 | - if(buffer) | ||
497 | - { | ||
498 | - /* Remove TABS */ | ||
499 | - gchar *ptr; | ||
500 | - | ||
501 | - for(ptr = buffer;*ptr;ptr++) | ||
502 | - { | ||
503 | - if(*ptr == '\t') | ||
504 | - *ptr = ' '; | ||
505 | - } | ||
506 | - } | ||
507 | - else | ||
508 | - { | ||
509 | - g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_PASTENEXT], 0, FALSE); | ||
510 | - return; | ||
511 | - } | ||
512 | - | ||
513 | - next = lib3270_paste(session,(unsigned char *) buffer) ? TRUE : FALSE; | ||
514 | - | ||
515 | - g_free(buffer); | ||
516 | - | ||
517 | - g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_PASTENEXT], 0, next); | ||
518 | - | ||
519 | -} | ||
520 | - | ||
521 | -LIB3270_EXPORT void v3270_unselect(GtkWidget *widget) | ||
522 | -{ | ||
523 | - v3270_disable_updates(widget); | ||
524 | - lib3270_unselect(v3270_get_session(widget)); | ||
525 | - v3270_enable_updates(widget); | ||
526 | -} | ||
527 | - | ||
528 | -gboolean v3270_get_selection_bounds(GtkWidget *widget, gint *start, gint *end) | ||
529 | -{ | ||
530 | - g_return_val_if_fail(GTK_IS_V3270(widget),FALSE); | ||
531 | - return lib3270_get_selection_bounds(GTK_V3270(widget)->host,start,end) == 0 ? FALSE : TRUE; | ||
532 | -} | ||
533 | - | ||
534 | -gchar * v3270_get_region(GtkWidget *widget, gint start_pos, gint end_pos, gboolean all) | ||
535 | -{ | ||
536 | - char * str; | ||
537 | - gchar * utftext; | ||
538 | - | ||
539 | - g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | ||
540 | - | ||
541 | - str = lib3270_get_region(GTK_V3270(widget)->host,start_pos,end_pos,all); | ||
542 | - if(!str) | ||
543 | - return NULL; | ||
544 | - | ||
545 | - utftext = g_convert(str, -1, "UTF-8", lib3270_get_display_charset(GTK_V3270(widget)->host), NULL, NULL, NULL); | ||
546 | - | ||
547 | - lib3270_free(str); | ||
548 | - | ||
549 | - return utftext; | ||
550 | -} | ||
551 | - | ||
552 | -LIB3270_EXPORT void v3270_select_region(GtkWidget *widget, gint start, gint end) | ||
553 | -{ | ||
554 | - g_return_if_fail(GTK_IS_V3270(widget)); | ||
555 | - lib3270_select_region(GTK_V3270(widget)->host,start,end); | ||
556 | -} | ||
557 | - | ||
558 | -LIB3270_EXPORT void v3270_select_all(GtkWidget *widget) | ||
559 | -{ | ||
560 | - g_return_if_fail(GTK_IS_V3270(widget)); | ||
561 | - v3270_disable_updates(widget); | ||
562 | - lib3270_select_all(v3270_get_session(widget)); | ||
563 | - v3270_enable_updates(widget); | ||
564 | -} | ||
565 | - | ||
566 | - |
v3270.cbp
@@ -42,6 +42,18 @@ | @@ -42,6 +42,18 @@ | ||
42 | <Add option="-fPIC" /> | 42 | <Add option="-fPIC" /> |
43 | </Linker> | 43 | </Linker> |
44 | <Unit filename="configure.ac" /> | 44 | <Unit filename="configure.ac" /> |
45 | + <Unit filename="src/clipboard/linux/paste.c"> | ||
46 | + <Option compilerVar="CC" /> | ||
47 | + </Unit> | ||
48 | + <Unit filename="src/clipboard/selection.c"> | ||
49 | + <Option compilerVar="CC" /> | ||
50 | + </Unit> | ||
51 | + <Unit filename="src/clipboard/text.c"> | ||
52 | + <Option compilerVar="CC" /> | ||
53 | + </Unit> | ||
54 | + <Unit filename="src/clipboard/windows/paste.c"> | ||
55 | + <Option compilerVar="CC" /> | ||
56 | + </Unit> | ||
45 | <Unit filename="src/dialogs/colors.c"> | 57 | <Unit filename="src/dialogs/colors.c"> |
46 | <Option compilerVar="CC" /> | 58 | <Option compilerVar="CC" /> |
47 | </Unit> | 59 | </Unit> |
@@ -130,6 +142,7 @@ | @@ -130,6 +142,7 @@ | ||
130 | <Unit filename="src/filetransfer/worker.c"> | 142 | <Unit filename="src/filetransfer/worker.c"> |
131 | <Option compilerVar="CC" /> | 143 | <Option compilerVar="CC" /> |
132 | </Unit> | 144 | </Unit> |
145 | + <Unit filename="src/include/clipboard.h" /> | ||
133 | <Unit filename="src/include/config.h" /> | 146 | <Unit filename="src/include/config.h" /> |
134 | <Unit filename="src/include/config.h.in" /> | 147 | <Unit filename="src/include/config.h.in" /> |
135 | <Unit filename="src/include/hostselect.h" /> | 148 | <Unit filename="src/include/hostselect.h" /> |
@@ -163,6 +176,9 @@ | @@ -163,6 +176,9 @@ | ||
163 | <Unit filename="src/terminal/font.c"> | 176 | <Unit filename="src/terminal/font.c"> |
164 | <Option compilerVar="CC" /> | 177 | <Option compilerVar="CC" /> |
165 | </Unit> | 178 | </Unit> |
179 | + <Unit filename="src/terminal/get.c"> | ||
180 | + <Option compilerVar="CC" /> | ||
181 | + </Unit> | ||
166 | <Unit filename="src/terminal/iocallback.c"> | 182 | <Unit filename="src/terminal/iocallback.c"> |
167 | <Option compilerVar="CC" /> | 183 | <Option compilerVar="CC" /> |
168 | </Unit> | 184 | </Unit> |
@@ -185,9 +201,6 @@ | @@ -185,9 +201,6 @@ | ||
185 | <Unit filename="src/terminal/security.c"> | 201 | <Unit filename="src/terminal/security.c"> |
186 | <Option compilerVar="CC" /> | 202 | <Option compilerVar="CC" /> |
187 | </Unit> | 203 | </Unit> |
188 | - <Unit filename="src/terminal/selection.c"> | ||
189 | - <Option compilerVar="CC" /> | ||
190 | - </Unit> | ||
191 | <Unit filename="src/terminal/widget.c"> | 204 | <Unit filename="src/terminal/widget.c"> |
192 | <Option compilerVar="CC" /> | 205 | <Option compilerVar="CC" /> |
193 | </Unit> | 206 | </Unit> |