Commit 63b05b21fe1f0371f29218e351215fa4d3783db9
1 parent
8df52aa9
Exists in
master
and in
1 other branch
Refactoring keyboard accelerators manager.
Showing
9 changed files
with
234 additions
and
61 deletions
Show diff stats
src/include/internals.h
... | ... | @@ -144,6 +144,22 @@ |
144 | 144 | |
145 | 145 | /*--[ Internal Widgets & Tools ]---------------------------------------------------------------------*/ |
146 | 146 | |
147 | + enum | |
148 | + { | |
149 | + V3270_ACCELERATOR_TYPE_INTERNAL, ///< @brief Accelerator is internal. | |
150 | + V3270_ACCELERATOR_TYPE_LIB3270_ACTION, ///< @brief Accelerator is a lib3270 action. | |
151 | + V3270_ACCELERATOR_TYPE_GTK_ACTION, ///< @brief Accelerator is a GTK Action (Deprececated). | |
152 | + }; | |
153 | + | |
154 | + struct _V3270Accelerator | |
155 | + { | |
156 | + unsigned short type; | |
157 | + guint key; | |
158 | + GdkModifierType mods; | |
159 | + gconstpointer arg; | |
160 | + GCallback activate; | |
161 | + }; | |
162 | + | |
147 | 163 | typedef enum v3270_toggleable_dialog |
148 | 164 | { |
149 | 165 | V3270_TOGGLEABLE_DIALOG_PASTE_FAILED, | ... | ... |
src/include/terminal.h
... | ... | @@ -220,6 +220,9 @@ G_BEGIN_DECLS |
220 | 220 | // Keyboard accelerators. |
221 | 221 | GSList * accelerators; ///< @brief Keyboard accelerators. |
222 | 222 | |
223 | + // Scroll actions. | |
224 | + GtkAction * scroll[4]; ///< @brief Scroll actions. | |
225 | + | |
223 | 226 | }; |
224 | 227 | |
225 | 228 | G_GNUC_INTERNAL void v3270_activate(GtkWidget *widget); | ... | ... |
src/include/v3270/actions.h
... | ... | @@ -41,6 +41,9 @@ |
41 | 41 | LIB3270_EXPORT void v3270_tab(GtkWidget *widget); |
42 | 42 | LIB3270_EXPORT void v3270_backtab(GtkWidget *widget); |
43 | 43 | |
44 | + /// @brief Reset accelerator map to defaults. | |
45 | + LIB3270_EXPORT void v3270_accelerator_map_reset(GtkWidget *widget); | |
46 | + | |
44 | 47 | LIB3270_EXPORT void v3270_accelerator_activate(V3270Accelerator * accell, GtkWidget *terminal); |
45 | 48 | LIB3270_EXPORT gboolean v3270_accelerator_compare(const V3270Accelerator * accell, const guint keyval, const GdkModifierType mods); |
46 | 49 | ... | ... |
... | ... | @@ -0,0 +1,80 @@ |
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 properties.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 "private.h" | |
31 | + #include <errno.h> | |
32 | + #include <internals.h> | |
33 | + #include <terminal.h> | |
34 | + #include <lib3270/actions.h> | |
35 | + | |
36 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
37 | + | |
38 | + static gint compare_func(const V3270Accelerator *a, const V3270Accelerator *b) | |
39 | + { | |
40 | + if(a->activate != b->activate) | |
41 | + return a->activate - b->activate; | |
42 | + return a->arg - b->arg; | |
43 | + } | |
44 | + | |
45 | + void v3270_accelerator_map_reset(GtkWidget *widget) | |
46 | + { | |
47 | + v3270 * terminal = GTK_V3270(widget); | |
48 | + | |
49 | + if(terminal) | |
50 | + { | |
51 | + if(terminal->accelerators) | |
52 | + { | |
53 | + g_slist_free_full(terminal->accelerators,g_free); | |
54 | + terminal->accelerators = NULL; | |
55 | + } | |
56 | + v3270_init_accelerators(terminal); | |
57 | + } | |
58 | + | |
59 | + } | |
60 | + | |
61 | + void v3270_accelerator_map_sort(v3270 *widget) | |
62 | + { | |
63 | + widget->accelerators = g_slist_sort(widget->accelerators, (GCompareFunc) compare_func); | |
64 | + } | |
65 | + | |
66 | + gboolean v3270_accelerator_compare(const V3270Accelerator * accell, const guint keyval, const GdkModifierType mods) | |
67 | + { | |
68 | + return accell->key == keyval && accell->mods == mods; | |
69 | + } | |
70 | + | |
71 | + void v3270_accelerator_activate(V3270Accelerator * accell, GtkWidget *terminal) | |
72 | + { | |
73 | + int rc = ((int (*)(GtkWidget *, const void *)) accell->activate)(terminal,accell->arg); | |
74 | + | |
75 | + if(rc) | |
76 | + gdk_display_beep(gdk_display_get_default()); | |
77 | + | |
78 | + } | |
79 | + | |
80 | + | ... | ... |
src/terminal/keyboard/init.c
... | ... | @@ -32,6 +32,19 @@ |
32 | 32 | #include <internals.h> |
33 | 33 | #include <terminal.h> |
34 | 34 | #include <lib3270/actions.h> |
35 | + #include <gdk/gdkkeysyms-compat.h> | |
36 | + | |
37 | + #ifndef GDK_NUMLOCK_MASK | |
38 | + #define GDK_NUMLOCK_MASK GDK_MOD2_MASK | |
39 | + #endif | |
40 | + | |
41 | +/*--[ Globals ]--------------------------------------------------------------------------------------*/ | |
42 | + | |
43 | +/* | |
44 | + static const struct InternalAction InternalActions[] = | |
45 | + { | |
46 | + }; | |
47 | +*/ | |
35 | 48 | |
36 | 49 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
37 | 50 | |
... | ... | @@ -56,54 +69,66 @@ |
56 | 69 | size_t ix; |
57 | 70 | |
58 | 71 | // Create accelerators for lib3270 actions. |
59 | - const LIB3270_ACTION * actions = lib3270_get_actions(); | |
60 | - | |
61 | - for(ix = 0; actions[ix].name; ix++) | |
62 | 72 | { |
63 | - if(actions[ix].keys) | |
73 | + const LIB3270_ACTION * actions = lib3270_get_actions(); | |
74 | + | |
75 | + for(ix = 0; actions[ix].name; ix++) | |
64 | 76 | { |
65 | - size_t key; | |
77 | + if(actions[ix].keys) | |
78 | + { | |
79 | + size_t key; | |
66 | 80 | |
67 | - gchar ** keys = g_strsplit(actions[ix].keys,",",-1); | |
81 | + gchar ** keys = g_strsplit(actions[ix].keys,",",-1); | |
68 | 82 | |
69 | - for(key = 0; keys[key]; key++) | |
70 | - { | |
83 | + for(key = 0; keys[key]; key++) | |
84 | + { | |
71 | 85 | |
72 | - V3270Accelerator * accelerator = g_new0(V3270Accelerator,1); | |
86 | + V3270Accelerator * accelerator = g_new0(V3270Accelerator,1); | |
73 | 87 | |
74 | - accelerator->type = ACCELERATOR_TYPE_LIB3270_ACTION; | |
75 | - accelerator->arg = (gconstpointer) &actions[ix]; | |
76 | - accelerator->activate = G_CALLBACK(fire_lib3270_action); | |
88 | + accelerator->type = V3270_ACCELERATOR_TYPE_LIB3270_ACTION; | |
89 | + accelerator->arg = (gconstpointer) &actions[ix]; | |
90 | + accelerator->activate = G_CALLBACK(fire_lib3270_action); | |
77 | 91 | |
78 | - debug("%s=%s",actions[ix].name,keys[key]); | |
92 | + debug("%s=%s",actions[ix].name,keys[key]); | |
79 | 93 | |
80 | - gtk_accelerator_parse(keys[key],&accelerator->key,&accelerator->mods); | |
94 | + gtk_accelerator_parse(keys[key],&accelerator->key,&accelerator->mods); | |
81 | 95 | |
82 | - widget->accelerators = g_slist_prepend(widget->accelerators,accelerator); | |
96 | + widget->accelerators = g_slist_prepend(widget->accelerators,accelerator); | |
83 | 97 | |
84 | - } | |
98 | + } | |
99 | + | |
100 | + g_strfreev(keys); | |
85 | 101 | |
86 | - g_strfreev(keys); | |
102 | + } | |
87 | 103 | |
88 | 104 | } |
89 | 105 | |
90 | 106 | } |
91 | 107 | |
108 | + /* | |
109 | + // Create accelerators for internal actions. | |
110 | + { | |
111 | + size_t ix; | |
92 | 112 | |
93 | - } | |
113 | + for(ix = 0 ; ix < G_N_ELEMENTS(InternalActions); ix++) | |
114 | + { | |
115 | + V3270Accelerator * accelerator = g_new0(V3270Accelerator,1); | |
94 | 116 | |
95 | - gboolean v3270_accelerator_compare(const V3270Accelerator * accell, const guint keyval, const GdkModifierType mods) | |
96 | - { | |
97 | - return accell->key == keyval && accell->mods == mods; | |
98 | - } | |
117 | + accelerator->type = V3270_ACCELERATOR_TYPE_INTERNAL; | |
118 | + accelerator->arg = (gconstpointer) &InternalActions[ix]; | |
119 | + accelerator->activate = InternalActions[ix].activate; | |
120 | + accelerator->key = InternalActions[ix].key; | |
121 | + accelerator->mods = InternalActions[ix].mods; | |
99 | 122 | |
100 | - void v3270_accelerator_activate(V3270Accelerator * accell, GtkWidget *terminal) | |
101 | - { | |
102 | - int rc = ((int (*)(GtkWidget *, const void *)) accell->activate)(terminal,accell->arg); | |
123 | + widget->accelerators = g_slist_prepend(widget->accelerators,accelerator); | |
103 | 124 | |
104 | - if(rc) | |
105 | - gdk_display_beep(gdk_display_get_default()); | |
125 | + } | |
126 | + } | |
127 | + */ | |
128 | + | |
129 | + v3270_accelerator_map_sort(widget); | |
106 | 130 | |
107 | 131 | } |
108 | 132 | |
109 | 133 | |
134 | + | ... | ... |
src/terminal/keyboard/private.h
... | ... | @@ -30,17 +30,14 @@ |
30 | 30 | #include <config.h> |
31 | 31 | #include <v3270.h> |
32 | 32 | #include <v3270/actions.h> |
33 | + #include <internals.h> | |
33 | 34 | |
34 | - enum | |
35 | + struct InternalAction | |
35 | 36 | { |
36 | - ACCELERATOR_TYPE_LIB3270_ACTION, ///< @brief Accelerator is a lib3270 action | |
37 | - }; | |
38 | - | |
39 | - struct _V3270Accelerator | |
40 | - { | |
41 | - unsigned short type; | |
42 | 37 | guint key; |
43 | 38 | GdkModifierType mods; |
44 | - gconstpointer arg; | |
45 | 39 | GCallback activate; |
46 | 40 | }; |
41 | + | |
42 | + G_GNUC_INTERNAL void v3270_accelerator_map_sort(v3270 *widget); | |
43 | + | ... | ... |
src/terminal/mouse.c
... | ... | @@ -42,7 +42,7 @@ |
42 | 42 | |
43 | 43 | /*--[ Globals ]--------------------------------------------------------------------------------------*/ |
44 | 44 | |
45 | - static GtkAction *action_scroll[] = { NULL, NULL, NULL, NULL }; | |
45 | +// static GtkAction *action_scroll[] = { NULL, NULL, NULL, NULL }; | |
46 | 46 | |
47 | 47 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
48 | 48 | |
... | ... | @@ -314,28 +314,3 @@ gboolean v3270_motion_notify_event(GtkWidget *widget, GdkEventMotion *event) |
314 | 314 | return FALSE; |
315 | 315 | } |
316 | 316 | |
317 | -LIB3270_EXPORT void v3270_set_scroll_action(GtkWidget *widget, GdkScrollDirection direction, GtkAction *action) | |
318 | -{ | |
319 | - g_return_if_fail(GTK_IS_V3270(widget)); | |
320 | - action_scroll[((int) direction) & 0x03] = action; | |
321 | -} | |
322 | - | |
323 | -gboolean v3270_scroll_event(GtkWidget *widget, GdkEventScroll *event) | |
324 | -{ | |
325 | - H3270 * hSession = v3270_get_session(widget); | |
326 | - | |
327 | - lib3270_trace_event(hSession,"scroll event direction=%d",(int) event->direction); | |
328 | - | |
329 | - if(lib3270_get_program_message(hSession) != LIB3270_MESSAGE_NONE || event->direction < 0 || event->direction > G_N_ELEMENTS(action_scroll)) | |
330 | - { | |
331 | - lib3270_trace_event(hSession," dropped (not available)\n"); | |
332 | - return FALSE; | |
333 | - } | |
334 | - | |
335 | - lib3270_trace_event(hSession,"\n"); | |
336 | - | |
337 | - if(action_scroll[event->direction]) | |
338 | - gtk_action_activate(action_scroll[event->direction]); | |
339 | - | |
340 | - return TRUE; | |
341 | - } | ... | ... |
... | ... | @@ -0,0 +1,68 @@ |
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 mouse.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 <v3270.h> | |
31 | + #include <terminal.h> | |
32 | + #include <internals.h> | |
33 | + #include <lib3270/log.h> | |
34 | + #include <lib3270/trace.h> | |
35 | + | |
36 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
37 | + | |
38 | +LIB3270_EXPORT void v3270_set_scroll_action(GtkWidget *widget, GdkScrollDirection direction, GtkAction *action) | |
39 | +{ | |
40 | + g_return_if_fail(GTK_IS_V3270(widget)); | |
41 | + GTK_V3270(widget)->scroll[((int) direction) & 0x03] = action; | |
42 | +} | |
43 | + | |
44 | +gboolean v3270_scroll_event(GtkWidget *widget, GdkEventScroll *event) | |
45 | +{ | |
46 | + v3270 * terminal = GTK_V3270(widget); | |
47 | + | |
48 | + lib3270_trace_event(terminal->host,"scroll event direction=%d",(int) event->direction); | |
49 | + | |
50 | + if(lib3270_get_program_message(terminal->host) != LIB3270_MESSAGE_NONE || event->direction < 0 || event->direction > G_N_ELEMENTS(terminal->scroll)) | |
51 | + { | |
52 | + lib3270_trace_event(terminal->host," dropped (not available)\n"); | |
53 | + return FALSE; | |
54 | + } | |
55 | + | |
56 | + lib3270_trace_event(terminal->host,"\n"); | |
57 | + | |
58 | + debug("%d %p", (int) event->direction, terminal->scroll[event->direction]); | |
59 | + | |
60 | + if(terminal->scroll[event->direction]) | |
61 | + { | |
62 | + debug("%d %s", (int) event->direction, gtk_action_get_name(terminal->scroll[event->direction])); | |
63 | + gtk_action_activate(terminal->scroll[event->direction]); | |
64 | + return TRUE; | |
65 | + } | |
66 | + | |
67 | + return FALSE; | |
68 | + } | ... | ... |
v3270.cbp
... | ... | @@ -268,6 +268,9 @@ |
268 | 268 | <Unit filename="src/terminal/keyboard.c"> |
269 | 269 | <Option compilerVar="CC" /> |
270 | 270 | </Unit> |
271 | + <Unit filename="src/terminal/keyboard/accelerator.c"> | |
272 | + <Option compilerVar="CC" /> | |
273 | + </Unit> | |
271 | 274 | <Unit filename="src/terminal/keyboard/init.c"> |
272 | 275 | <Option compilerVar="CC" /> |
273 | 276 | </Unit> |
... | ... | @@ -292,6 +295,9 @@ |
292 | 295 | <Unit filename="src/terminal/properties/set.c"> |
293 | 296 | <Option compilerVar="CC" /> |
294 | 297 | </Unit> |
298 | + <Unit filename="src/terminal/scroll.c"> | |
299 | + <Option compilerVar="CC" /> | |
300 | + </Unit> | |
295 | 301 | <Unit filename="src/terminal/security.c"> |
296 | 302 | <Option compilerVar="CC" /> |
297 | 303 | </Unit> | ... | ... |