Commit add2e7baa013aa7b62883c4ca23ff86e621473e7
1 parent
63a2fe4d
Exists in
master
and in
1 other branch
Moving map method to their own source.
Showing
3 changed files
with
164 additions
and
125 deletions
Show diff stats
src/terminal/keyboard/accelerator.c
@@ -18,7 +18,7 @@ | @@ -18,7 +18,7 @@ | ||
18 | * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | 18 | * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin |
19 | * St, Fifth Floor, Boston, MA 02110-1301 USA | 19 | * St, Fifth Floor, Boston, MA 02110-1301 USA |
20 | * | 20 | * |
21 | - * Este programa está nomeado como properties.c e possui - linhas de código. | 21 | + * Este programa está nomeado como - e possui - linhas de código. |
22 | * | 22 | * |
23 | * Contatos: | 23 | * Contatos: |
24 | * | 24 | * |
@@ -36,13 +36,6 @@ | @@ -36,13 +36,6 @@ | ||
36 | 36 | ||
37 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 37 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
38 | 38 | ||
39 | - static gint compare_func(const V3270Accelerator *a, const V3270Accelerator *b) | ||
40 | - { | ||
41 | - if(a->activate != b->activate) | ||
42 | - return a->activate - b->activate; | ||
43 | - return a->arg - b->arg; | ||
44 | - } | ||
45 | - | ||
46 | V3270Accelerator * v3270_accelerator_copy(const V3270Accelerator *accel) | 39 | V3270Accelerator * v3270_accelerator_copy(const V3270Accelerator *accel) |
47 | { | 40 | { |
48 | V3270Accelerator * rc = NULL; | 41 | V3270Accelerator * rc = NULL; |
@@ -63,27 +56,6 @@ | @@ -63,27 +56,6 @@ | ||
63 | } | 56 | } |
64 | 57 | ||
65 | 58 | ||
66 | - void v3270_accelerator_map_reset(GtkWidget *widget) | ||
67 | - { | ||
68 | - v3270 * terminal = GTK_V3270(widget); | ||
69 | - | ||
70 | - if(terminal) | ||
71 | - { | ||
72 | - if(terminal->accelerators) | ||
73 | - { | ||
74 | - g_slist_free_full(terminal->accelerators,g_free); | ||
75 | - terminal->accelerators = NULL; | ||
76 | - } | ||
77 | - v3270_init_accelerators(terminal); | ||
78 | - } | ||
79 | - | ||
80 | - } | ||
81 | - | ||
82 | - void v3270_accelerator_map_sort(v3270 *widget) | ||
83 | - { | ||
84 | - widget->accelerators = g_slist_sort(widget->accelerators, (GCompareFunc) compare_func); | ||
85 | - } | ||
86 | - | ||
87 | gboolean v3270_accelerator_compare(const V3270Accelerator * accell, const guint keyval, const GdkModifierType mods) | 59 | gboolean v3270_accelerator_compare(const V3270Accelerator * accell, const guint keyval, const GdkModifierType mods) |
88 | { | 60 | { |
89 | return accell->key == keyval && accell->mods == mods; | 61 | return accell->key == keyval && accell->mods == mods; |
@@ -151,104 +123,8 @@ | @@ -151,104 +123,8 @@ | ||
151 | return NULL; | 123 | return NULL; |
152 | } | 124 | } |
153 | 125 | ||
154 | - void v3270_accelerator_map_foreach(GtkWidget *widget,void (*call)(const V3270Accelerator * accel, const char *keys, gpointer ptr), gpointer ptr) | ||
155 | - { | ||
156 | - GSList * accelerator = GTK_V3270(widget)->accelerators; | ||
157 | - GString * str = g_string_new(""); | ||
158 | - | ||
159 | - while(accelerator) | ||
160 | - { | ||
161 | - V3270Accelerator * current = (V3270Accelerator *) accelerator->data; | ||
162 | - | ||
163 | - g_string_truncate(str,0); | ||
164 | - | ||
165 | - while(accelerator && (((V3270Accelerator *) accelerator->data)->activate == current->activate) && (((V3270Accelerator *) accelerator->data)->arg == current->arg)) | ||
166 | - { | ||
167 | - V3270Accelerator *accel = (V3270Accelerator *) accelerator->data; | ||
168 | - if(accel->key) | ||
169 | - { | ||
170 | - | ||
171 | - if(str->str[0]) | ||
172 | - g_string_append(str," "); | ||
173 | - | ||
174 | - if(accel->key) | ||
175 | - { | ||
176 | - g_autofree gchar * keyname = gtk_accelerator_name(accel->key,accel->mods); | ||
177 | - g_string_append(str,keyname); | ||
178 | - } | ||
179 | - | ||
180 | - } | ||
181 | - | ||
182 | - accelerator = g_slist_next(accelerator); | ||
183 | - } | ||
184 | - | ||
185 | - call(current,str->str,ptr); | ||
186 | - | ||
187 | - } | ||
188 | - | ||
189 | - g_string_free(str,TRUE); | ||
190 | - | ||
191 | - } | ||
192 | - | ||
193 | gchar * v3270_accelerator_get_label(const V3270Accelerator * accel) | 126 | gchar * v3270_accelerator_get_label(const V3270Accelerator * accel) |
194 | { | 127 | { |
195 | return gtk_accelerator_get_label(accel->key,accel->mods); | 128 | return gtk_accelerator_get_label(accel->key,accel->mods); |
196 | } | 129 | } |
197 | 130 | ||
198 | - V3270Accelerator * v3270_accelerator_map_add_entry(GtkWidget *widget, const gchar *name, guint accel_key, GdkModifierType accel_mods, GCallback callback, gpointer data) | ||
199 | - { | ||
200 | - GSList * ix; | ||
201 | - v3270 * terminal = GTK_V3270(widget); | ||
202 | - V3270Accelerator * accel = NULL; | ||
203 | - | ||
204 | - // Find accel by name | ||
205 | - for(ix = terminal->accelerators; ix; ix = g_slist_next(ix)) | ||
206 | - { | ||
207 | - const gchar * nm = v3270_accelerator_get_name((V3270Accelerator *) ix->data); | ||
208 | - if(nm && !g_ascii_strcasecmp(name,nm)) | ||
209 | - { | ||
210 | - accel = (V3270Accelerator *) ix->data; | ||
211 | - break; | ||
212 | - } | ||
213 | - } | ||
214 | - | ||
215 | - if(!accel) | ||
216 | - { | ||
217 | - // Not found, create a custom accelerator. | ||
218 | - debug("%s: Adding accelerator %s",__FUNCTION__,name); | ||
219 | - | ||
220 | - V3270CustomAccelerator *customAccel = g_new0(V3270CustomAccelerator,1); | ||
221 | - | ||
222 | - customAccel->parent.type = V3270_ACCELERATOR_TYPE_CUSTOM; | ||
223 | - customAccel->name = name; | ||
224 | - | ||
225 | - terminal->accelerators = g_slist_prepend(terminal->accelerators,customAccel); | ||
226 | - | ||
227 | - accel = (V3270Accelerator *) customAccel; | ||
228 | - } | ||
229 | - | ||
230 | - accel->arg = data; | ||
231 | - accel->activate = callback; | ||
232 | - accel->key = accel_key; | ||
233 | - accel->mods = accel_mods; | ||
234 | - | ||
235 | - // Any other accell in the same key? If yes, clear it. | ||
236 | - for(ix = terminal->accelerators; ix; ix = g_slist_next(ix)) | ||
237 | - { | ||
238 | - V3270Accelerator * acc = (V3270Accelerator *) ix->data; | ||
239 | - if((acc == accel) || !(acc->key == accel->key && acc->mods == accel->mods)) | ||
240 | - continue; | ||
241 | - | ||
242 | - debug("Resetting accelerator \"%s\"",v3270_accelerator_get_name(acc)); | ||
243 | - | ||
244 | - acc->key = 0; | ||
245 | - acc->mods = 0; | ||
246 | - | ||
247 | - } | ||
248 | - | ||
249 | - // Sort! | ||
250 | - v3270_accelerator_map_sort(terminal); | ||
251 | - | ||
252 | - return accel; | ||
253 | - | ||
254 | - } |
@@ -0,0 +1,160 @@ | @@ -0,0 +1,160 @@ | ||
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 "private.h" | ||
31 | + #include <terminal.h> | ||
32 | + #include <v3270/actions.h> | ||
33 | + | ||
34 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
35 | + | ||
36 | + void v3270_accelerator_map_reset(GtkWidget *widget) | ||
37 | + { | ||
38 | + v3270 * terminal = GTK_V3270(widget); | ||
39 | + | ||
40 | + if(terminal) | ||
41 | + { | ||
42 | + if(terminal->accelerators) | ||
43 | + { | ||
44 | + g_slist_free_full(terminal->accelerators,g_free); | ||
45 | + terminal->accelerators = NULL; | ||
46 | + } | ||
47 | + v3270_init_accelerators(terminal); | ||
48 | + } | ||
49 | + | ||
50 | + } | ||
51 | + | ||
52 | + static gint compare_func(const V3270Accelerator *a, const V3270Accelerator *b) | ||
53 | + { | ||
54 | + if(a->activate != b->activate) | ||
55 | + return a->activate - b->activate; | ||
56 | + | ||
57 | + return a->arg - b->arg; | ||
58 | + } | ||
59 | + | ||
60 | + void v3270_accelerator_map_sort(v3270 *widget) | ||
61 | + { | ||
62 | + widget->accelerators = g_slist_sort(widget->accelerators, (GCompareFunc) compare_func); | ||
63 | + } | ||
64 | + | ||
65 | + void v3270_accelerator_map_foreach(GtkWidget *widget,void (*call)(const V3270Accelerator * accel, const char *keys, gpointer ptr), gpointer ptr) | ||
66 | + { | ||
67 | + GSList * accelerator = GTK_V3270(widget)->accelerators; | ||
68 | + GString * str = g_string_new(""); | ||
69 | + | ||
70 | + while(accelerator) | ||
71 | + { | ||
72 | + V3270Accelerator * current = (V3270Accelerator *) accelerator->data; | ||
73 | + | ||
74 | + g_string_truncate(str,0); | ||
75 | + | ||
76 | + while(accelerator && (((V3270Accelerator *) accelerator->data)->activate == current->activate) && (((V3270Accelerator *) accelerator->data)->arg == current->arg)) | ||
77 | + { | ||
78 | + V3270Accelerator *accel = (V3270Accelerator *) accelerator->data; | ||
79 | + if(accel->key) | ||
80 | + { | ||
81 | + | ||
82 | + if(str->str[0]) | ||
83 | + g_string_append(str," "); | ||
84 | + | ||
85 | + if(accel->key) | ||
86 | + { | ||
87 | + g_autofree gchar * keyname = gtk_accelerator_name(accel->key,accel->mods); | ||
88 | + g_string_append(str,keyname); | ||
89 | + } | ||
90 | + | ||
91 | + } | ||
92 | + | ||
93 | + accelerator = g_slist_next(accelerator); | ||
94 | + } | ||
95 | + | ||
96 | + call(current,str->str,ptr); | ||
97 | + | ||
98 | + } | ||
99 | + | ||
100 | + g_string_free(str,TRUE); | ||
101 | + | ||
102 | + } | ||
103 | + | ||
104 | + V3270Accelerator * v3270_accelerator_map_add_entry(GtkWidget *widget, const gchar *name, guint accel_key, GdkModifierType accel_mods, GCallback callback, gpointer data) | ||
105 | + { | ||
106 | + GSList * ix; | ||
107 | + v3270 * terminal = GTK_V3270(widget); | ||
108 | + V3270Accelerator * accel = NULL; | ||
109 | + | ||
110 | + // Find accel by name | ||
111 | + for(ix = terminal->accelerators; ix; ix = g_slist_next(ix)) | ||
112 | + { | ||
113 | + const gchar * nm = v3270_accelerator_get_name((V3270Accelerator *) ix->data); | ||
114 | + if(nm && !g_ascii_strcasecmp(name,nm)) | ||
115 | + { | ||
116 | + accel = (V3270Accelerator *) ix->data; | ||
117 | + break; | ||
118 | + } | ||
119 | + } | ||
120 | + | ||
121 | + if(!accel) | ||
122 | + { | ||
123 | + // Not found, create a custom accelerator. | ||
124 | + debug("%s: Adding accelerator %s",__FUNCTION__,name); | ||
125 | + | ||
126 | + V3270CustomAccelerator *customAccel = g_new0(V3270CustomAccelerator,1); | ||
127 | + | ||
128 | + customAccel->parent.type = V3270_ACCELERATOR_TYPE_CUSTOM; | ||
129 | + customAccel->name = g_intern_string(name); | ||
130 | + | ||
131 | + terminal->accelerators = g_slist_prepend(terminal->accelerators,customAccel); | ||
132 | + | ||
133 | + accel = (V3270Accelerator *) customAccel; | ||
134 | + } | ||
135 | + | ||
136 | + accel->arg = data; | ||
137 | + accel->activate = callback; | ||
138 | + accel->key = accel_key; | ||
139 | + accel->mods = accel_mods; | ||
140 | + | ||
141 | + // Any other accell in the same key? If yes, clear it. | ||
142 | + for(ix = terminal->accelerators; ix; ix = g_slist_next(ix)) | ||
143 | + { | ||
144 | + V3270Accelerator * acc = (V3270Accelerator *) ix->data; | ||
145 | + if((acc == accel) || !(acc->key == accel->key && acc->mods == accel->mods)) | ||
146 | + continue; | ||
147 | + | ||
148 | + debug("Resetting accelerator \"%s\"",v3270_accelerator_get_name(acc)); | ||
149 | + | ||
150 | + acc->key = 0; | ||
151 | + acc->mods = 0; | ||
152 | + | ||
153 | + } | ||
154 | + | ||
155 | + // Sort! | ||
156 | + v3270_accelerator_map_sort(terminal); | ||
157 | + | ||
158 | + return accel; | ||
159 | + | ||
160 | + } |
v3270.cbp
@@ -293,6 +293,9 @@ | @@ -293,6 +293,9 @@ | ||
293 | <Unit filename="src/terminal/keyboard/keyfile.c"> | 293 | <Unit filename="src/terminal/keyboard/keyfile.c"> |
294 | <Option compilerVar="CC" /> | 294 | <Option compilerVar="CC" /> |
295 | </Unit> | 295 | </Unit> |
296 | + <Unit filename="src/terminal/keyboard/map.c"> | ||
297 | + <Option compilerVar="CC" /> | ||
298 | + </Unit> | ||
296 | <Unit filename="src/terminal/keyboard/private.h" /> | 299 | <Unit filename="src/terminal/keyboard/private.h" /> |
297 | <Unit filename="src/terminal/keyfile.c"> | 300 | <Unit filename="src/terminal/keyfile.c"> |
298 | <Option compilerVar="CC" /> | 301 | <Option compilerVar="CC" /> |