actions.c
5.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
* (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
* aplicativos mainframe. Registro no INPI sob o nome G3270.
*
* Copyright (C) <2008> <Banco do Brasil S.A.>
*
* Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
* os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
* Free Software Foundation.
*
* Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
* GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
* A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
* obter mais detalhes.
*
* Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
* programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA, 02111-1307, USA
*
* Este programa está nomeado como actions.c e possui - linhas de código.
*
* Contatos:
*
* perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
* erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
* licinio@bb.com.br (Licínio Luis Branco)
* kraucer@bb.com.br (Kraucer Fernandes Mazuco)
*
*/
#include "globals.h"
#include "uiparser/parser.h"
/*--[ Implement ]------------------------------------------------------------------------------------*/
static void lib3270_action(GtkAction *action, GtkWidget *widget)
{
int (*call)(H3270 *h) = (int (*)(H3270 *h)) g_object_get_data(G_OBJECT(action),"lib3270_call");
trace("Action %s activated on widget %p",gtk_action_get_name(action),widget);
call(GTK_V3270(widget)->host);
}
static void connect_action(GtkAction *action, GtkWidget *widget)
{
trace("Action %s activated on widget %p",gtk_action_get_name(action),widget);
v3270_connect(widget,g_object_get_data(G_OBJECT(action),"host"));
}
static void disconnect_action(GtkAction *action, GtkWidget *widget)
{
trace("Action %s activated on widget %p",gtk_action_get_name(action),widget);
v3270_disconnect(widget);
}
void ui_connect_action(GtkAction *action, GtkWidget *widget, const gchar *name, const gchar *id)
{
#undef DECLARE_LIB3270_ACTION
#undef DECLARE_LIB3270_CLEAR_SELECTION_ACTION
#undef DECLARE_LIB3270_KEY_ACTION
#undef DECLARE_LIB3270_CURSOR_ACTION
#undef DECLARE_LIB3270_FKEY_ACTION
#define DECLARE_LIB3270_ACTION( name ) { #name, lib3270_ ## name },
#define DECLARE_LIB3270_CLEAR_SELECTION_ACTION( name ) { #name, lib3270_ ## name },
#define DECLARE_LIB3270_KEY_ACTION( name ) { #name, lib3270_ ## name },
#define DECLARE_LIB3270_CURSOR_ACTION( name ) { #name, lib3270_cursor_ ## name },
#define DECLARE_LIB3270_FKEY_ACTION( name ) /* name */
static const struct _lib3270_action
{
const gchar * name;
int (*call)(H3270 *h);
} lib3270_entry[] =
{
#include <lib3270/action_table.h>
};
static const struct _gtk_action
{
const gchar * name;
void (*call)(GtkAction *action, GtkWidget *widget);
}
gtk_action[] =
{
{ "connect", connect_action },
{ "disconnect", disconnect_action },
};
int f;
// Search for lib3270 predefined actions
for(f=0;f<G_N_ELEMENTS(lib3270_entry);f++)
{
if(!g_strcasecmp(name,lib3270_entry[f].name))
{
g_object_set_data(G_OBJECT(action),"lib3270_call",lib3270_entry[f].call);
g_signal_connect(action,"activate",G_CALLBACK(lib3270_action),widget);
return;
}
}
// Search for application actions
for(f=0;f<G_N_ELEMENTS(gtk_action);f++)
{
if(!g_strcasecmp(name,gtk_action[f].name))
{
g_signal_connect(action,"activate",G_CALLBACK(gtk_action[f].call),widget);
return;
}
}
if(!g_strcasecmp(name,"screensizes"))
return;
// Not-found, disable action
gtk_action_set_sensitive(action,FALSE);
}
static void lib3270_toggle_action(GtkToggleAction *action,GtkWidget *widget)
{
LIB3270_TOGGLE toggle = (LIB3270_TOGGLE) g_object_get_data(G_OBJECT(action),"toggle_id");
trace("Action %s toggled on widget %p (id=%d)",gtk_action_get_name(GTK_ACTION(action)),widget,(int) toggle);
lib3270_set_toggle(GTK_V3270(widget)->host,toggle,gtk_toggle_action_get_active(action));
}
void ui_connect_toggle(GtkAction *action, GtkWidget *widget, const gchar *name, const gchar *id)
{
LIB3270_TOGGLE toggle = lib3270_get_toggle_id(id);
if(toggle != -1)
{
g_object_set_data(G_OBJECT(action),"toggle_id",(gpointer) toggle);
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action),(lib3270_get_toggle(GTK_V3270(widget)->host,toggle) != 0));
g_signal_connect(action,"toggled",G_CALLBACK(lib3270_toggle_action),widget);
return;
}
trace("Action %s with toggle %s on widget %p",gtk_action_get_name(action),id,widget);
// Not found, disable action
gtk_action_set_sensitive(action,FALSE);
}
static void action_pfkey(GtkAction *action, GtkWidget *widget)
{
trace("Action %s activated on widget %p key=%d",gtk_action_get_name(action),widget,g_object_get_data(G_OBJECT(action),"pfkey"));
lib3270_pfkey(GTK_V3270(widget)->host,(int) g_object_get_data(G_OBJECT(action),"pfkey"));
}
void ui_connect_pfkey(GtkAction *action, GtkWidget *widget, const gchar *name, const gchar *id)
{
g_object_set_data(G_OBJECT(action),"pfkey",(gpointer) atoi(id));
g_signal_connect(action,"activate",G_CALLBACK(action_pfkey),widget);
}
static void action_pakey(GtkAction *action, GtkWidget *widget)
{
trace("Action %s activated on widget %p key=%d",gtk_action_get_name(action),widget,g_object_get_data(G_OBJECT(action),"pakey"));
lib3270_pakey(GTK_V3270(widget)->host,(int) g_object_get_data(G_OBJECT(action),"pakey"));
}
void ui_connect_pakey(GtkAction *action, GtkWidget *widget, const gchar *name, const gchar *id)
{
g_object_set_data(G_OBJECT(action),"pakey",(gpointer) atoi(id));
g_signal_connect(action,"activate",G_CALLBACK(action_pakey),widget);
}