Commit c73219f23613756f81f45dca0898c75134afcc5f
1 parent
c23dd26e
Exists in
master
and in
1 other branch
Adding required macos sources.
Showing
5 changed files
with
713 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,96 @@ | @@ -0,0 +1,96 @@ | ||
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. Registro no INPI sob | ||
5 | + * o nome G3270. | ||
6 | + * | ||
7 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
8 | + * | ||
9 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
10 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
11 | + * Free Software Foundation. | ||
12 | + * | ||
13 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
14 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
15 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
16 | + * obter mais detalhes. | ||
17 | + * | ||
18 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
19 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | ||
20 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | + * | ||
22 | + * Este programa está nomeado como - possui - linhas de código. | ||
23 | + * | ||
24 | + * Contatos: | ||
25 | + * | ||
26 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
27 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
28 | + * | ||
29 | + */ | ||
30 | + | ||
31 | +#include "../private.h" | ||
32 | +#include <stdarg.h> | ||
33 | + | ||
34 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
35 | + | ||
36 | +gchar * v3270_select_file(GtkWidget *widget, const gchar *title, const gchar *button, GtkFileChooserAction action, const gchar *filename) | ||
37 | +{ | ||
38 | + gchar *rc = NULL; | ||
39 | + | ||
40 | +#if GTK_CHECK_VERSION(3,20,0) | ||
41 | + | ||
42 | + debug("%s action=%d",__FUNCTION__,(int) action); | ||
43 | + | ||
44 | + GtkFileChooserNative *native = | ||
45 | + gtk_file_chooser_native_new | ||
46 | + ( | ||
47 | + title, | ||
48 | + GTK_WINDOW(widget), | ||
49 | + action, | ||
50 | + button, | ||
51 | + _( "_Cancel" ) | ||
52 | + ); | ||
53 | + | ||
54 | + | ||
55 | + // Setup filename | ||
56 | + if(filename && *filename) | ||
57 | + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(native),filename); | ||
58 | + | ||
59 | + | ||
60 | + // Run dialog | ||
61 | + if(gtk_native_dialog_run(GTK_NATIVE_DIALOG (native)) == GTK_RESPONSE_ACCEPT) { | ||
62 | + rc = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(native)); | ||
63 | + } | ||
64 | + | ||
65 | + g_object_unref(native); | ||
66 | + | ||
67 | +#else | ||
68 | + | ||
69 | + debug("%s action=%d",__FUNCTION__,(int) action); | ||
70 | + | ||
71 | + GtkWidget * chooser = | ||
72 | + gtk_file_chooser_dialog_new | ||
73 | + ( | ||
74 | + title, | ||
75 | + GTK_WINDOW(widget), | ||
76 | + action, | ||
77 | + _("_Cancel" ), GTK_RESPONSE_CANCEL, | ||
78 | + button, GTK_RESPONSE_ACCEPT, | ||
79 | + NULL | ||
80 | + ); | ||
81 | + | ||
82 | + if(filename && *filename) | ||
83 | + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(chooser),filename); | ||
84 | + | ||
85 | + if(gtk_dialog_run(GTK_DIALOG(chooser)) == GTK_RESPONSE_ACCEPT) { | ||
86 | + rc = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(chooser)); | ||
87 | + } | ||
88 | + | ||
89 | + gtk_widget_destroy(chooser); | ||
90 | + | ||
91 | +#endif // GTK 3.20 | ||
92 | + | ||
93 | + return rc; | ||
94 | + | ||
95 | +} | ||
96 | + |
@@ -0,0 +1,196 @@ | @@ -0,0 +1,196 @@ | ||
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 - 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 | + #include <lib3270/selection.h> | ||
32 | + #include <lib3270/toggle.h> | ||
33 | + | ||
34 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
35 | + | ||
36 | +void v3270_clipboard_clear(G_GNUC_UNUSED GtkClipboard *clipboard, G_GNUC_UNUSED GObject *obj) | ||
37 | +{ | ||
38 | + v3270 * terminal = GTK_V3270(obj); | ||
39 | + | ||
40 | + if(!lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_KEEP_SELECTED)) | ||
41 | + { | ||
42 | + v3270_unselect(GTK_WIDGET(obj)); | ||
43 | + v3270_clear_selection(terminal); | ||
44 | + } | ||
45 | + | ||
46 | +} | ||
47 | + | ||
48 | +void v3270_clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionData *selection, guint target, GObject *obj) | ||
49 | +{ | ||
50 | + v3270 * terminal = GTK_V3270(obj); | ||
51 | + | ||
52 | + if(!terminal->selection.blocks) | ||
53 | + { | ||
54 | + return; | ||
55 | + } | ||
56 | + | ||
57 | + switch(target) | ||
58 | + { | ||
59 | + case CLIPBOARD_TYPE_TEXT: // Get clipboard contents as text | ||
60 | + { | ||
61 | + g_autofree gchar *text = v3270_get_copy_as_text(terminal,"UTF-8"); | ||
62 | + gtk_selection_data_set_text(selection,text,-1); | ||
63 | + } | ||
64 | + break; | ||
65 | + | ||
66 | + case CLIPBOARD_TYPE_CSV: | ||
67 | + { | ||
68 | + g_autofree gchar *text = v3270_get_copy_as_table(terminal,";","UTF-8"); | ||
69 | + debug("Selection:\n%s",text); | ||
70 | + gtk_selection_data_set( | ||
71 | + selection, | ||
72 | + gdk_atom_intern_static_string("text/csv"), | ||
73 | + 8, | ||
74 | + (guchar *) text, | ||
75 | + strlen(text) | ||
76 | + ); | ||
77 | + } | ||
78 | + break; | ||
79 | + | ||
80 | + case CLIPBOARD_TYPE_HTML: | ||
81 | + { | ||
82 | + g_autofree gchar *text = v3270_get_copy_as_html(terminal,"UTF-8"); | ||
83 | + //debug("Selection:\n%s",text); | ||
84 | + gtk_selection_data_set( | ||
85 | + selection, | ||
86 | + gdk_atom_intern_static_string("text/html"), | ||
87 | + 8, | ||
88 | + (guchar *) text, | ||
89 | + strlen(text) | ||
90 | + ); | ||
91 | + } | ||
92 | + break; | ||
93 | + | ||
94 | + case CLIPBOARD_TYPE_V3270_FORMATTED: | ||
95 | + { | ||
96 | + g_autofree gchar *data = v3270_get_copy_as_data_block(terminal); | ||
97 | + gtk_selection_data_set( | ||
98 | + selection, | ||
99 | + GTK_V3270_GET_CLASS(obj)->clipboard_formatted, | ||
100 | + 8, | ||
101 | + (guchar *) data, | ||
102 | + ((struct SelectionHeader *) data)->length | ||
103 | + ); | ||
104 | + } | ||
105 | + break; | ||
106 | + | ||
107 | + case CLIPBOARD_TYPE_PIXBUFF: | ||
108 | + { | ||
109 | + GdkPixbuf * pixbuff = v3270_get_selection_as_pixbuf(terminal, terminal->selection.blocks, FALSE); | ||
110 | + | ||
111 | + debug("%s: pixbuff=%p (blocks=%p)",__FUNCTION__,pixbuff,terminal->selection.blocks); | ||
112 | + | ||
113 | + if(pixbuff) | ||
114 | + { | ||
115 | + gtk_selection_data_set_pixbuf(selection,pixbuff); | ||
116 | + g_object_unref(pixbuff); | ||
117 | + } | ||
118 | + } | ||
119 | + break; | ||
120 | + | ||
121 | + default: | ||
122 | + g_warning("Unexpected clipboard type %d\n",target); | ||
123 | + } | ||
124 | +} | ||
125 | + | ||
126 | +void v3270_update_system_clipboard(GtkWidget *widget) | ||
127 | +{ | ||
128 | + v3270 * terminal = GTK_V3270(widget); | ||
129 | + | ||
130 | + if(!terminal->selection.blocks) | ||
131 | + { | ||
132 | + // No clipboard data, return. | ||
133 | + v3270_emit_copy_state(widget); | ||
134 | + return; | ||
135 | + } | ||
136 | + | ||
137 | + // Has clipboard data, inform system. | ||
138 | + GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,terminal->selection.target); | ||
139 | + | ||
140 | + // Create target list | ||
141 | + // | ||
142 | + // Reference: https://cpp.hotexamples.com/examples/-/-/g_list_insert_sorted/cpp-g_list_insert_sorted-function-examples.html | ||
143 | + // | ||
144 | + GtkTargetList * list = gtk_target_list_new(NULL,0); | ||
145 | + | ||
146 | + gtk_target_list_add_text_targets(list, CLIPBOARD_TYPE_TEXT); | ||
147 | + | ||
148 | + if((terminal->selection.options & V3270_SELECTION_PLAIN_TEXT) == 0) | ||
149 | + { | ||
150 | + static const GtkTargetEntry targets[] = { | ||
151 | + { "text/csv", 0, CLIPBOARD_TYPE_CSV }, | ||
152 | + { "text/html", 0, CLIPBOARD_TYPE_HTML }, | ||
153 | + { "application/x-v3270-formatted", 0, CLIPBOARD_TYPE_V3270_FORMATTED }, | ||
154 | + }; | ||
155 | + | ||
156 | + gtk_target_list_add_table(list, targets, G_N_ELEMENTS(targets)); | ||
157 | + | ||
158 | + } | ||
159 | + | ||
160 | + if(terminal->selection.options & V3270_SELECTION_PIXBUFF) | ||
161 | + { | ||
162 | + gtk_target_list_add_image_targets(list,CLIPBOARD_TYPE_PIXBUFF,TRUE); | ||
163 | + } | ||
164 | + | ||
165 | + int n_targets; | ||
166 | + GtkTargetEntry * targets = gtk_target_table_new_from_list(list, &n_targets); | ||
167 | + | ||
168 | +#ifdef DEBUG | ||
169 | + { | ||
170 | + int ix; | ||
171 | + for(ix = 0; ix < n_targets; ix++) { | ||
172 | + debug("target(%d)=\"%s\"",ix,targets[ix].target); | ||
173 | + } | ||
174 | + } | ||
175 | +#endif // DEBUG | ||
176 | + | ||
177 | + if(gtk_clipboard_set_with_owner( | ||
178 | + clipboard, | ||
179 | + targets, | ||
180 | + n_targets, | ||
181 | + (GtkClipboardGetFunc) v3270_clipboard_get, | ||
182 | + (GtkClipboardClearFunc) v3270_clipboard_clear, | ||
183 | + G_OBJECT(widget) | ||
184 | + )) | ||
185 | + { | ||
186 | + gtk_clipboard_set_can_store(clipboard,targets,1); | ||
187 | + } | ||
188 | + | ||
189 | + gtk_target_table_free(targets, n_targets); | ||
190 | + gtk_target_list_unref(list); | ||
191 | + | ||
192 | + v3270_emit_copy_state(widget); | ||
193 | + | ||
194 | +} | ||
195 | + | ||
196 | + |
@@ -0,0 +1,196 @@ | @@ -0,0 +1,196 @@ | ||
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 - 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 | + #include <lib3270/selection.h> | ||
32 | + #include <lib3270/toggle.h> | ||
33 | + | ||
34 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
35 | + | ||
36 | +void v3270_clipboard_clear(G_GNUC_UNUSED GtkClipboard *clipboard, G_GNUC_UNUSED GObject *obj) | ||
37 | +{ | ||
38 | + v3270 * terminal = GTK_V3270(obj); | ||
39 | + | ||
40 | + if(!lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_KEEP_SELECTED)) | ||
41 | + { | ||
42 | + v3270_unselect(GTK_WIDGET(obj)); | ||
43 | + v3270_clear_selection(terminal); | ||
44 | + } | ||
45 | + | ||
46 | +} | ||
47 | + | ||
48 | +void v3270_clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionData *selection, guint target, GObject *obj) | ||
49 | +{ | ||
50 | + v3270 * terminal = GTK_V3270(obj); | ||
51 | + | ||
52 | + if(!terminal->selection.blocks) | ||
53 | + { | ||
54 | + return; | ||
55 | + } | ||
56 | + | ||
57 | + switch(target) | ||
58 | + { | ||
59 | + case CLIPBOARD_TYPE_TEXT: // Get clipboard contents as text | ||
60 | + { | ||
61 | + g_autofree gchar *text = v3270_get_copy_as_text(terminal,"UTF-8"); | ||
62 | + gtk_selection_data_set_text(selection,text,-1); | ||
63 | + } | ||
64 | + break; | ||
65 | + | ||
66 | + case CLIPBOARD_TYPE_CSV: | ||
67 | + { | ||
68 | + g_autofree gchar *text = v3270_get_copy_as_table(terminal,";","UTF-8"); | ||
69 | + debug("Selection:\n%s",text); | ||
70 | + gtk_selection_data_set( | ||
71 | + selection, | ||
72 | + gdk_atom_intern_static_string("text/csv"), | ||
73 | + 8, | ||
74 | + (guchar *) text, | ||
75 | + strlen(text) | ||
76 | + ); | ||
77 | + } | ||
78 | + break; | ||
79 | + | ||
80 | + case CLIPBOARD_TYPE_HTML: | ||
81 | + { | ||
82 | + g_autofree gchar *text = v3270_get_copy_as_html(terminal,"UTF-8"); | ||
83 | + //debug("Selection:\n%s",text); | ||
84 | + gtk_selection_data_set( | ||
85 | + selection, | ||
86 | + gdk_atom_intern_static_string("text/html"), | ||
87 | + 8, | ||
88 | + (guchar *) text, | ||
89 | + strlen(text) | ||
90 | + ); | ||
91 | + } | ||
92 | + break; | ||
93 | + | ||
94 | + case CLIPBOARD_TYPE_V3270_FORMATTED: | ||
95 | + { | ||
96 | + g_autofree gchar *data = v3270_get_copy_as_data_block(terminal); | ||
97 | + gtk_selection_data_set( | ||
98 | + selection, | ||
99 | + GTK_V3270_GET_CLASS(obj)->clipboard_formatted, | ||
100 | + 8, | ||
101 | + (guchar *) data, | ||
102 | + ((struct SelectionHeader *) data)->length | ||
103 | + ); | ||
104 | + } | ||
105 | + break; | ||
106 | + | ||
107 | + case CLIPBOARD_TYPE_PIXBUFF: | ||
108 | + { | ||
109 | + GdkPixbuf * pixbuff = v3270_get_selection_as_pixbuf(terminal, terminal->selection.blocks, FALSE); | ||
110 | + | ||
111 | + debug("%s: pixbuff=%p (blocks=%p)",__FUNCTION__,pixbuff,terminal->selection.blocks); | ||
112 | + | ||
113 | + if(pixbuff) | ||
114 | + { | ||
115 | + gtk_selection_data_set_pixbuf(selection,pixbuff); | ||
116 | + g_object_unref(pixbuff); | ||
117 | + } | ||
118 | + } | ||
119 | + break; | ||
120 | + | ||
121 | + default: | ||
122 | + g_warning("Unexpected clipboard type %d\n",target); | ||
123 | + } | ||
124 | +} | ||
125 | + | ||
126 | +void v3270_update_system_clipboard(GtkWidget *widget) | ||
127 | +{ | ||
128 | + v3270 * terminal = GTK_V3270(widget); | ||
129 | + | ||
130 | + if(!terminal->selection.blocks) | ||
131 | + { | ||
132 | + // No clipboard data, return. | ||
133 | + v3270_emit_copy_state(widget); | ||
134 | + return; | ||
135 | + } | ||
136 | + | ||
137 | + // Has clipboard data, inform system. | ||
138 | + GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,terminal->selection.target); | ||
139 | + | ||
140 | + // Create target list | ||
141 | + // | ||
142 | + // Reference: https://cpp.hotexamples.com/examples/-/-/g_list_insert_sorted/cpp-g_list_insert_sorted-function-examples.html | ||
143 | + // | ||
144 | + GtkTargetList * list = gtk_target_list_new(NULL,0); | ||
145 | + | ||
146 | + gtk_target_list_add_text_targets(list, CLIPBOARD_TYPE_TEXT); | ||
147 | + | ||
148 | + if((terminal->selection.options & V3270_SELECTION_PLAIN_TEXT) == 0) | ||
149 | + { | ||
150 | + static const GtkTargetEntry targets[] = { | ||
151 | + { "text/csv", 0, CLIPBOARD_TYPE_CSV }, | ||
152 | + { "text/html", 0, CLIPBOARD_TYPE_HTML }, | ||
153 | + { "application/x-v3270-formatted", 0, CLIPBOARD_TYPE_V3270_FORMATTED }, | ||
154 | + }; | ||
155 | + | ||
156 | + gtk_target_list_add_table(list, targets, G_N_ELEMENTS(targets)); | ||
157 | + | ||
158 | + } | ||
159 | + | ||
160 | + if(terminal->selection.options & V3270_SELECTION_PIXBUFF) | ||
161 | + { | ||
162 | + gtk_target_list_add_image_targets(list,CLIPBOARD_TYPE_PIXBUFF,TRUE); | ||
163 | + } | ||
164 | + | ||
165 | + int n_targets; | ||
166 | + GtkTargetEntry * targets = gtk_target_table_new_from_list(list, &n_targets); | ||
167 | + | ||
168 | +#ifdef DEBUG | ||
169 | + { | ||
170 | + int ix; | ||
171 | + for(ix = 0; ix < n_targets; ix++) { | ||
172 | + debug("target(%d)=\"%s\"",ix,targets[ix].target); | ||
173 | + } | ||
174 | + } | ||
175 | +#endif // DEBUG | ||
176 | + | ||
177 | + if(gtk_clipboard_set_with_owner( | ||
178 | + clipboard, | ||
179 | + targets, | ||
180 | + n_targets, | ||
181 | + (GtkClipboardGetFunc) v3270_clipboard_get, | ||
182 | + (GtkClipboardClearFunc) v3270_clipboard_clear, | ||
183 | + G_OBJECT(widget) | ||
184 | + )) | ||
185 | + { | ||
186 | + gtk_clipboard_set_can_store(clipboard,targets,1); | ||
187 | + } | ||
188 | + | ||
189 | + gtk_target_table_free(targets, n_targets); | ||
190 | + gtk_target_list_unref(list); | ||
191 | + | ||
192 | + v3270_emit_copy_state(widget); | ||
193 | + | ||
194 | +} | ||
195 | + | ||
196 | + |
@@ -0,0 +1,56 @@ | @@ -0,0 +1,56 @@ | ||
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 <config.h> | ||
31 | + #include <lib3270.h> | ||
32 | + #include <locale.h> | ||
33 | + #include <libintl.h> | ||
34 | + #include <lib3270/log.h> | ||
35 | + | ||
36 | + int libv3270_loaded(void) __attribute__((constructor)); | ||
37 | + int libv3270_unloaded(void) __attribute__((destructor)); | ||
38 | + | ||
39 | +/*---[ Implement ]-----------------------------------------------------------------------------------------*/ | ||
40 | + | ||
41 | + int libv3270_loaded(void) { | ||
42 | + | ||
43 | + debug("LocaleDIR(%s)=%s",PACKAGE_NAME,LIB3270_STRINGIZE_VALUE_OF(LOCALEDIR)); | ||
44 | + | ||
45 | + bindtextdomain(PACKAGE_NAME, LIB3270_STRINGIZE_VALUE_OF(LOCALEDIR)); | ||
46 | + bind_textdomain_codeset(PACKAGE_NAME, "UTF-8"); | ||
47 | + | ||
48 | + return 0; | ||
49 | + | ||
50 | + } | ||
51 | + | ||
52 | + int libv3270_unloaded(void) { | ||
53 | + | ||
54 | + return 0; | ||
55 | + | ||
56 | + } |
@@ -0,0 +1,169 @@ | @@ -0,0 +1,169 @@ | ||
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 <config.h> | ||
31 | + #include <lib3270.h> | ||
32 | + #include <lib3270/log.h> | ||
33 | + #include <poll.h> | ||
34 | + #include <internals.h> | ||
35 | + #include <terminal.h> | ||
36 | + | ||
37 | +/*---[ Structs ]-------------------------------------------------------------------------------------------*/ | ||
38 | + | ||
39 | + typedef struct _IO_Source | ||
40 | + { | ||
41 | + GSource gsrc; | ||
42 | + GPollFD poll; | ||
43 | + gboolean enabled; | ||
44 | + int fd; | ||
45 | + void (*call)(H3270 *, int, LIB3270_IO_FLAG, void *); | ||
46 | + H3270 * session; | ||
47 | + void * userdata; | ||
48 | + } IO_Source; | ||
49 | + | ||
50 | +static gboolean IO_prepare(GSource *source, gint *timeout); | ||
51 | +static gboolean IO_check(GSource *source); | ||
52 | +static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer user_data); | ||
53 | +static void IO_finalize(GSource *source); /* Can be NULL */ | ||
54 | +static gboolean IO_closure(gpointer data); | ||
55 | + | ||
56 | +/*---[ Implement ]-----------------------------------------------------------------------------------------*/ | ||
57 | + | ||
58 | +GSource * IO_source_new(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*call)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata) | ||
59 | +{ | ||
60 | + static GSourceFuncs IOSources = | ||
61 | + { | ||
62 | + IO_prepare, | ||
63 | + IO_check, | ||
64 | + IO_dispatch, | ||
65 | + IO_finalize, | ||
66 | + IO_closure, | ||
67 | + NULL | ||
68 | + }; | ||
69 | + | ||
70 | + IO_Source *src = (IO_Source *) g_source_new(&IOSources,sizeof(IO_Source)); | ||
71 | + | ||
72 | + src->fd = fd; | ||
73 | + src->enabled = TRUE; | ||
74 | + src->call = call; | ||
75 | + src->userdata = userdata; | ||
76 | + src->session = session; | ||
77 | + | ||
78 | + src->poll.fd = (int) fd; | ||
79 | + src->poll.events = G_IO_HUP|G_IO_ERR; | ||
80 | + | ||
81 | + if(flag & LIB3270_IO_FLAG_READ) | ||
82 | + src->poll.events |= G_IO_IN; | ||
83 | + | ||
84 | + if(flag & LIB3270_IO_FLAG_WRITE) | ||
85 | + src->poll.events |= G_IO_OUT; | ||
86 | + | ||
87 | + IO_source_set_state((GSource *) src, TRUE); | ||
88 | + | ||
89 | + g_source_attach((GSource *) src,NULL); | ||
90 | + g_source_add_poll((GSource *) src, &((IO_Source *)src)->poll); | ||
91 | + | ||
92 | + return (GSource *) src; | ||
93 | +} | ||
94 | + | ||
95 | +void IO_source_set_state(GSource *source, gboolean enable) | ||
96 | +{ | ||
97 | + ((IO_Source *)source)->enabled = enable; | ||
98 | +} | ||
99 | + | ||
100 | +gboolean IO_prepare(G_GNUC_UNUSED GSource *source, G_GNUC_UNUSED gint *timeout) | ||
101 | +{ | ||
102 | + /* | ||
103 | + * Called before all the file descriptors are polled. | ||
104 | + * If the source can determine that it is ready here | ||
105 | + * (without waiting for the results of the poll() call) | ||
106 | + * it should return TRUE. | ||
107 | + * | ||
108 | + * It can also return a timeout_ value which should be the maximum | ||
109 | + * timeout (in milliseconds) which should be passed to the poll() call. | ||
110 | + * The actual timeout used will be -1 if all sources returned -1, | ||
111 | + * or it will be the minimum of all the timeout_ values | ||
112 | + * returned which were >= 0. | ||
113 | + * | ||
114 | + */ | ||
115 | + return 0; | ||
116 | +} | ||
117 | + | ||
118 | +gboolean IO_check(GSource *source) | ||
119 | +{ | ||
120 | + /* | ||
121 | + * Called after all the file descriptors are polled. | ||
122 | + * The source should return TRUE if it is ready to be dispatched. | ||
123 | + * Note that some time may have passed since the previous prepare | ||
124 | + * function was called, so the source should be checked again here. | ||
125 | + * | ||
126 | + */ | ||
127 | + if(((IO_Source *) source)->enabled) | ||
128 | + { | ||
129 | + struct pollfd fds; | ||
130 | + | ||
131 | + memset(&fds,0,sizeof(fds)); | ||
132 | + | ||
133 | + fds.fd = ((IO_Source *) source)->poll.fd; | ||
134 | + fds.events = ((IO_Source *) source)->poll.events; | ||
135 | + | ||
136 | + if(poll(&fds,1,0) > 0) | ||
137 | + return TRUE; | ||
138 | + } | ||
139 | + | ||
140 | + return FALSE; | ||
141 | +} | ||
142 | + | ||
143 | +gboolean IO_dispatch(GSource *source, G_GNUC_UNUSED GSourceFunc callback, G_GNUC_UNUSED gpointer user_data) | ||
144 | +{ | ||
145 | + /* | ||
146 | + * Called to dispatch the event source, | ||
147 | + * after it has returned TRUE in either its prepare or its check function. | ||
148 | + * The dispatch function is passed in a callback function and data. | ||
149 | + * The callback function may be NULL if the source was never connected | ||
150 | + * to a callback using g_source_set_callback(). The dispatch function | ||
151 | + * should call the callback function with user_data and whatever additional | ||
152 | + * parameters are needed for this type of event source. | ||
153 | + */ | ||
154 | + IO_Source *obj = (IO_Source *) source; | ||
155 | + | ||
156 | + obj->call(obj->session,obj->fd,0,obj->userdata); | ||
157 | + | ||
158 | + return TRUE; | ||
159 | +} | ||
160 | + | ||
161 | +void IO_finalize(G_GNUC_UNUSED GSource *source) | ||
162 | +{ | ||
163 | + | ||
164 | +} | ||
165 | + | ||
166 | +gboolean IO_closure(G_GNUC_UNUSED gpointer data) | ||
167 | +{ | ||
168 | + return 0; | ||
169 | +} |