Commit 3d6d26cdd90c0fbd5310fbffba851073bf26915e
1 parent
bf73e967
Exists in
master
and in
5 other branches
Incluindo suporte a macros na barra de botoes
Showing
5 changed files
with
235 additions
and
135 deletions
Show diff stats
... | ... | @@ -0,0 +1,136 @@ |
1 | + | |
2 | +/* | |
3 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
4 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
5 | + * aplicativos mainframe. Registro no INPI sob 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 button.c e 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 "keypad.h" | |
32 | + #include <pw3270/v3270.h> | |
33 | + | |
34 | +/*--[ Globals ]--------------------------------------------------------------------------------------*/ | |
35 | + | |
36 | + | |
37 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
38 | + | |
39 | + GtkReliefStyle ui_get_relief(const gchar **names, const gchar **values, GtkReliefStyle def) | |
40 | + { | |
41 | + | |
42 | + const gchar *name = ui_get_attribute("relief",names,values); | |
43 | + if(name) | |
44 | + { | |
45 | + static const struct _style | |
46 | + { | |
47 | + GtkReliefStyle val; | |
48 | + const gchar * name; | |
49 | + } style[] = | |
50 | + { | |
51 | + { GTK_RELIEF_NORMAL, "normal" }, | |
52 | + { GTK_RELIEF_HALF, "half" }, | |
53 | + { GTK_RELIEF_NONE, "none" } | |
54 | + }; | |
55 | + | |
56 | + int f; | |
57 | + | |
58 | + for(f=0;f<G_N_ELEMENTS(style);f++) | |
59 | + { | |
60 | + if(!g_ascii_strcasecmp(style[f].name,name)) | |
61 | + return style[f].val; | |
62 | + } | |
63 | + } | |
64 | + | |
65 | + return def; | |
66 | + } | |
67 | + | |
68 | + static void button_clicked(GtkButton *button, GtkAction *action) | |
69 | + { | |
70 | + gtk_action_activate(action); | |
71 | + } | |
72 | + | |
73 | + static void button_script(GtkButton *button, GtkWidget *widget) | |
74 | + { | |
75 | + v3270_run_script(widget,g_object_get_data(G_OBJECT(button),"script_text")); | |
76 | + } | |
77 | + | |
78 | + void keypad_button_start(GMarkupParseContext *context, const gchar **names,const gchar **values, GError **error, struct keypad *keypad) | |
79 | + { | |
80 | + const gchar * label = ui_get_attribute("label", names, values); | |
81 | + const gchar * icon = ui_get_attribute("icon", names, values); | |
82 | + const gchar * name = ui_get_attribute("action", names, values); | |
83 | + struct parser * info = keypad->parser; | |
84 | + GtkAction * action = NULL; | |
85 | + GtkWidget * widget = NULL; | |
86 | + | |
87 | + if(++keypad->col > keypad->num_cols) | |
88 | + keypad->num_cols = keypad->col; | |
89 | + | |
90 | + keypad->row->num_cols++; | |
91 | + | |
92 | + if(label) | |
93 | + { | |
94 | + widget = gtk_button_new_with_label(gettext(g_strcompress(label))); | |
95 | + } | |
96 | + else if(icon) | |
97 | + { | |
98 | + gchar *text = g_strconcat("gtk-",icon,NULL); | |
99 | + widget = gtk_button_new(); | |
100 | + gtk_container_add(GTK_CONTAINER(widget),gtk_image_new_from_stock(text,GTK_ICON_SIZE_SMALL_TOOLBAR)); | |
101 | + g_free(text); | |
102 | + } | |
103 | + | |
104 | + keypad->row->cols = g_list_append(keypad->row->cols,widget); | |
105 | + | |
106 | + if(!widget) | |
107 | + return; | |
108 | + | |
109 | +#if GTK_CHECK_VERSION(2,18,0) | |
110 | + gtk_widget_set_can_focus(widget,FALSE); | |
111 | + gtk_widget_set_can_default(widget,FALSE); | |
112 | +#else | |
113 | + GTK_WIDGET_UNSET_FLAGS(widget,GTK_CAN_FOCUS); | |
114 | + GTK_WIDGET_UNSET_FLAGS(widget,GTK_CAN_DEFAULT); | |
115 | +#endif // GTK(2,18) | |
116 | + | |
117 | + gtk_button_set_relief(GTK_BUTTON(widget),ui_get_relief(names, values, keypad->relief)); | |
118 | + gtk_button_set_alignment(GTK_BUTTON(widget),0.5,0.5); | |
119 | + gtk_button_set_focus_on_click(GTK_BUTTON(widget),FALSE); | |
120 | + | |
121 | + if(name) | |
122 | + action = ui_get_action(info->center_widget,name,info->actions,names,values,error); | |
123 | + | |
124 | + if(action) | |
125 | + { | |
126 | + ui_action_set_options(action,info,names,values,error); | |
127 | + g_signal_connect(G_OBJECT(widget),"clicked",G_CALLBACK(button_clicked),action); | |
128 | + } | |
129 | + else | |
130 | + { | |
131 | + keypad->widget = widget; | |
132 | + gtk_widget_set_sensitive(widget,FALSE); | |
133 | + g_signal_connect(G_OBJECT(widget),"clicked",G_CALLBACK(button_script),info->center_widget); | |
134 | + } | |
135 | + } | |
136 | + | ... | ... |
src/pw3270/uiparser/keypad.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 accelerator.c e possui - linhas de código. | |
21 | + * Este programa está nomeado como keypad.c e possui - linhas de código. | |
22 | 22 | * |
23 | 23 | * Contatos: |
24 | 24 | * |
... | ... | @@ -27,66 +27,11 @@ |
27 | 27 | * |
28 | 28 | */ |
29 | 29 | |
30 | - #include <gtk/gtk.h> | |
31 | - #include "private.h" | |
32 | - | |
33 | -/*--[ Globals ]--------------------------------------------------------------------------------------*/ | |
34 | - | |
35 | - struct row | |
36 | - { | |
37 | - unsigned short pos; | |
38 | - unsigned short num_cols; | |
39 | - GList * cols; | |
40 | - }; | |
41 | - | |
42 | - struct keypad | |
43 | - { | |
44 | - struct parser * parser; | |
45 | - unsigned short num_rows; | |
46 | - unsigned short num_cols; | |
47 | - unsigned short col; | |
48 | - unsigned short button_width; | |
49 | - struct row * row; | |
50 | - GtkWidget * box; | |
51 | - GtkWidget * handle; | |
52 | - GtkWidget * table; | |
53 | - GtkReliefStyle relief; | |
54 | - UI_ATTR_DIRECTION pos; | |
55 | - GList * rows; | |
56 | - }; | |
30 | + #include "keypad.h" | |
57 | 31 | |
58 | 32 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
59 | 33 | |
60 | - static GtkReliefStyle get_relief(const gchar **names, const gchar **values, GtkReliefStyle def) | |
61 | - { | |
62 | - | |
63 | - const gchar *name = ui_get_attribute("relief",names,values); | |
64 | - if(name) | |
65 | - { | |
66 | - static const struct _style | |
67 | - { | |
68 | - GtkReliefStyle val; | |
69 | - const gchar * name; | |
70 | - } style[] = | |
71 | - { | |
72 | - { GTK_RELIEF_NORMAL, "normal" }, | |
73 | - { GTK_RELIEF_HALF, "half" }, | |
74 | - { GTK_RELIEF_NONE, "none" } | |
75 | - }; | |
76 | - | |
77 | - int f; | |
78 | - | |
79 | - for(f=0;f<G_N_ELEMENTS(style);f++) | |
80 | - { | |
81 | - if(!g_strcasecmp(style[f].name,name)) | |
82 | - return style[f].val; | |
83 | - } | |
84 | - } | |
85 | - | |
86 | - return def; | |
87 | - } | |
88 | - | |
89 | - static void row_start(struct keypad *keypad, const gchar **names,const gchar **values, GError **error) | |
34 | + void keypad_row_start(GMarkupParseContext *context, const gchar **names,const gchar **values, GError **error, struct keypad *keypad) | |
90 | 35 | { |
91 | 36 | keypad->row = g_malloc0(sizeof(struct row)); |
92 | 37 | |
... | ... | @@ -96,84 +41,16 @@ |
96 | 41 | keypad->rows = g_list_append(keypad->rows,keypad->row); |
97 | 42 | } |
98 | 43 | |
99 | - static void button_clicked(GtkButton *button, GtkAction *action) | |
100 | - { | |
101 | - gtk_action_activate(action); | |
102 | - } | |
103 | - | |
104 | - static void button_start(struct keypad *keypad, const gchar **names,const gchar **values, GError **error) | |
105 | - { | |
106 | - const gchar * label = ui_get_attribute("label", names, values); | |
107 | - const gchar * icon = ui_get_attribute("icon", names, values); | |
108 | - const gchar * name = ui_get_attribute("action", names, values); | |
109 | - struct parser * info = keypad->parser; | |
110 | - GtkAction * action; | |
111 | - GtkWidget * widget = NULL; | |
112 | - | |
113 | - if(++keypad->col > keypad->num_cols) | |
114 | - keypad->num_cols = keypad->col; | |
115 | - | |
116 | - keypad->row->num_cols++; | |
117 | - | |
118 | - if(label) | |
119 | - { | |
120 | - widget = gtk_button_new_with_label(gettext(g_strcompress(label))); | |
121 | - } | |
122 | - else if(icon) | |
123 | - { | |
124 | - gchar *text = g_strconcat("gtk-",icon,NULL); | |
125 | - widget = gtk_button_new(); | |
126 | - gtk_container_add(GTK_CONTAINER(widget),gtk_image_new_from_stock(text,GTK_ICON_SIZE_SMALL_TOOLBAR)); | |
127 | - g_free(text); | |
128 | - } | |
129 | - | |
130 | - keypad->row->cols = g_list_append(keypad->row->cols,widget); | |
131 | - | |
132 | - if(!widget) | |
133 | - return; | |
134 | - | |
135 | -#if GTK_CHECK_VERSION(2,18,0) | |
136 | - gtk_widget_set_can_focus(widget,FALSE); | |
137 | - gtk_widget_set_can_default(widget,FALSE); | |
138 | -#else | |
139 | - GTK_WIDGET_UNSET_FLAGS(widget,GTK_CAN_FOCUS); | |
140 | - GTK_WIDGET_UNSET_FLAGS(widget,GTK_CAN_DEFAULT); | |
141 | -#endif // GTK(2,18) | |
142 | - | |
143 | - if(!name) | |
144 | - { | |
145 | - // Invalid unnamed element | |
146 | - *error = g_error_new(ERROR_DOMAIN,EINVAL,_( "Can't accept unnamed %s"),"button"); | |
147 | - return; | |
148 | - } | |
149 | - | |
150 | - gtk_button_set_relief(GTK_BUTTON(widget),get_relief(names, values, keypad->relief)); | |
151 | - gtk_button_set_alignment(GTK_BUTTON(widget),0.5,0.5); | |
152 | - gtk_button_set_focus_on_click(GTK_BUTTON(widget),FALSE); | |
153 | - | |
154 | - action = ui_get_action(info->center_widget,name,info->actions,names,values,error); | |
155 | - | |
156 | - if(action) | |
157 | - { | |
158 | - ui_action_set_options(action,info,names,values,error); | |
159 | - g_signal_connect(G_OBJECT(widget),"clicked",G_CALLBACK(button_clicked),action); | |
160 | - } | |
161 | - else | |
162 | - { | |
163 | - gtk_widget_set_sensitive(widget,FALSE); | |
164 | - } | |
165 | - } | |
166 | - | |
167 | 44 | static void element_start(GMarkupParseContext *context, const gchar *element_name, const gchar **names,const gchar **values, struct keypad *keypad, GError **error) |
168 | 45 | { |
169 | 46 | static const struct _cmd |
170 | 47 | { |
171 | 48 | const gchar *element_name; |
172 | - void (*start)(struct keypad *, const gchar **, const gchar **, GError **); | |
49 | + void (*start)(GMarkupParseContext *, const gchar **,const gchar **, GError **, struct keypad *); | |
173 | 50 | } cmd[] = |
174 | 51 | { |
175 | - { "row", row_start }, | |
176 | - { "button", button_start }, | |
52 | + { "row", keypad_row_start }, | |
53 | + { "button", keypad_button_start }, | |
177 | 54 | }; |
178 | 55 | |
179 | 56 | int f; |
... | ... | @@ -182,7 +59,7 @@ |
182 | 59 | { |
183 | 60 | if(!g_strcasecmp(cmd[f].element_name,element_name)) |
184 | 61 | { |
185 | - cmd[f].start(keypad,names,values,error); | |
62 | + cmd[f].start(context,names,values,error,keypad); | |
186 | 63 | return; |
187 | 64 | } |
188 | 65 | } |
... | ... | @@ -191,7 +68,8 @@ |
191 | 68 | } |
192 | 69 | |
193 | 70 | static void element_end(GMarkupParseContext *context, const gchar *element_name, struct keypad *keypad, GError **error) |
194 | - { | |
71 | + { | |
72 | + keypad->widget = NULL; | |
195 | 73 | // trace("%s: %s",__FUNCTION__,element_name); |
196 | 74 | } |
197 | 75 | |
... | ... | @@ -227,6 +105,28 @@ |
227 | 105 | |
228 | 106 | return UI_ATTR_DIRECTION_NONE; |
229 | 107 | } |
108 | + | |
109 | + static void element_text(GMarkupParseContext *context, const gchar *text, gsize sz, struct keypad *keypad, GError **error) | |
110 | + { | |
111 | + if(keypad->widget) | |
112 | + { | |
113 | + gchar *base = g_strstrip(g_strdup(text)); | |
114 | + gchar *text = g_strdup(base); | |
115 | + g_free(base); | |
116 | + | |
117 | + if(*text) | |
118 | + { | |
119 | + gtk_widget_set_sensitive(keypad->widget,TRUE); | |
120 | + g_object_set_data_full(G_OBJECT(keypad->widget),"script_text",text,g_free); | |
121 | + } | |
122 | + else | |
123 | + { | |
124 | + g_free(text); | |
125 | + } | |
126 | + | |
127 | + } | |
128 | + | |
129 | + } | |
230 | 130 | |
231 | 131 | GObject * ui_create_keypad(GMarkupParseContext *context,GtkAction *action,struct parser *info,const gchar **names, const gchar **values, GError **error) |
232 | 132 | { |
... | ... | @@ -237,7 +137,7 @@ |
237 | 137 | (void (*)(GMarkupParseContext *, const gchar *, gpointer, GError **)) |
238 | 138 | element_end, |
239 | 139 | (void (*)(GMarkupParseContext *, const gchar *, gsize, gpointer, GError **)) |
240 | - NULL, | |
140 | + element_text, | |
241 | 141 | |
242 | 142 | // (void (*)(GMarkupParseContext *, GError *, gpointer)) |
243 | 143 | NULL |
... | ... | @@ -264,7 +164,7 @@ |
264 | 164 | keypad->parser = info; |
265 | 165 | keypad->handle = gtk_handle_box_new(); |
266 | 166 | keypad->pos = ui_get_position_attribute(names,values); |
267 | - keypad->relief = get_relief(names, values, GTK_RELIEF_NORMAL); | |
167 | + keypad->relief = ui_get_relief(names, values, GTK_RELIEF_NORMAL); | |
268 | 168 | |
269 | 169 | switch(keypad->pos) |
270 | 170 | { |
... | ... | @@ -350,7 +250,7 @@ |
350 | 250 | keypad->col = 0; |
351 | 251 | keypad->button_width = keypad->num_cols / info->num_cols; |
352 | 252 | |
353 | - trace("Max cols=%d row cols=%d width=%d",keypad->num_cols,info->num_cols,keypad->button_width); | |
253 | +// trace("Max cols=%d row cols=%d width=%d",keypad->num_cols,info->num_cols,keypad->button_width); | |
354 | 254 | |
355 | 255 | g_list_foreach(info->cols,(GFunc) create_col,keypad); |
356 | 256 | g_list_free(info->cols); | ... | ... |
... | ... | @@ -0,0 +1,62 @@ |
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 keypad.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 | + | |
31 | + #include <gtk/gtk.h> | |
32 | + #include "private.h" | |
33 | + | |
34 | +/*--[ Globals ]--------------------------------------------------------------------------------------*/ | |
35 | + | |
36 | + struct row | |
37 | + { | |
38 | + unsigned short pos; | |
39 | + unsigned short num_cols; | |
40 | + GList * cols; | |
41 | + }; | |
42 | + | |
43 | + struct keypad | |
44 | + { | |
45 | + struct parser * parser; | |
46 | + unsigned short num_rows; | |
47 | + unsigned short num_cols; | |
48 | + unsigned short col; | |
49 | + unsigned short button_width; | |
50 | + struct row * row; | |
51 | + GtkWidget * box; | |
52 | + GtkWidget * handle; | |
53 | + GtkWidget * table; | |
54 | + GtkReliefStyle relief; | |
55 | + UI_ATTR_DIRECTION pos; | |
56 | + GList * rows; | |
57 | + | |
58 | + GtkWidget * widget; | |
59 | + | |
60 | + }; | |
61 | + | |
62 | + G_GNUC_INTERNAL void keypad_button_start(GMarkupParseContext *context, const gchar **names,const gchar **values, GError **error, struct keypad *keypad); | ... | ... |
src/pw3270/uiparser/private.h
... | ... | @@ -93,6 +93,8 @@ |
93 | 93 | |
94 | 94 | int ui_parse_file(struct parser *info, const gchar *filename); |
95 | 95 | void ui_action_set_options(GtkAction *action, struct parser *info, const gchar **names, const gchar **values, GError **error); |
96 | + | |
97 | + G_GNUC_INTERNAL GtkReliefStyle ui_get_relief(const gchar **names, const gchar **values, GtkReliefStyle def); | |
96 | 98 | |
97 | 99 | GObject * ui_get_element(struct parser *info, GtkAction *action, enum ui_element id, const gchar **names, const gchar **values, GError **error); |
98 | 100 | GObject * ui_insert_element(struct parser *info, GtkAction *action, enum ui_element id, const gchar **names, const gchar **values, GObject *widget, GError **error); | ... | ... |