Commit e42f96cccce7b35a9db9a577fcbdc8fca67095e3
1 parent
104cd184
Exists in
master
and in
1 other branch
Adding fallbacks for scroll actions.
Showing
5 changed files
with
162 additions
and
72 deletions
Show diff stats
src/include/terminal.h
... | ... | @@ -221,7 +221,11 @@ G_BEGIN_DECLS |
221 | 221 | GSList * accelerators; ///< @brief Keyboard accelerators. |
222 | 222 | |
223 | 223 | // Scroll actions. |
224 | - GtkAction * scroll[4]; ///< @brief Scroll actions. | |
224 | + struct | |
225 | + { | |
226 | + void (*activate)(GtkWidget *, gpointer); ///< @brief Callback for scroll activation. | |
227 | + gpointer arg; ///< @brief Argument for callback. | |
228 | + } scroll[4]; ///< @brief Scroll actions. | |
225 | 229 | |
226 | 230 | }; |
227 | 231 | ... | ... |
src/include/v3270/actions.h
... | ... | @@ -70,6 +70,8 @@ |
70 | 70 | // |
71 | 71 | // Misc |
72 | 72 | // |
73 | + LIB3270_EXPORT void v3270_set_scroll_handler(GtkWidget *widget, GdkScrollDirection direction, GCallback callback, gpointer data); | |
74 | + | |
73 | 75 | LIB3270_EXPORT void v3270_set_scroll_action(GtkWidget *widget, GdkScrollDirection direction, GtkAction *action) G_GNUC_DEPRECATED; |
74 | 76 | |
75 | 77 | // | ... | ... |
... | ... | @@ -0,0 +1,152 @@ |
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 <v3270/actions.h> | |
32 | + #include <terminal.h> | |
33 | + #include <internals.h> | |
34 | + #include <lib3270/log.h> | |
35 | + #include <lib3270/trace.h> | |
36 | + #include <gdk/gdkkeysyms-compat.h> | |
37 | + | |
38 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
39 | + | |
40 | +// Callback for compatibility with the old application. | |
41 | +static void activate_action(GtkWidget *terminal, GtkAction *action) | |
42 | +{ | |
43 | + gtk_action_activate(action); | |
44 | +} | |
45 | + | |
46 | +LIB3270_EXPORT void v3270_set_scroll_action(GtkWidget *widget, GdkScrollDirection direction, GtkAction *action) | |
47 | +{ | |
48 | + v3270_set_scroll_handler(widget, direction, G_CALLBACK(activate_action), action); | |
49 | +} | |
50 | + | |
51 | +gboolean v3270_scroll_event(GtkWidget *widget, GdkEventScroll *event) | |
52 | +{ | |
53 | + v3270 * terminal = GTK_V3270(widget); | |
54 | + | |
55 | + lib3270_write_event_trace(terminal->host,"scroll event direction=%d",(int) event->direction); | |
56 | + | |
57 | + if(lib3270_get_program_message(terminal->host) != LIB3270_MESSAGE_NONE || event->direction < 0 || event->direction > G_N_ELEMENTS(terminal->scroll)) | |
58 | + { | |
59 | + lib3270_write_event_trace(terminal->host," dropped (not available)\n"); | |
60 | + return FALSE; | |
61 | + } | |
62 | + | |
63 | + lib3270_write_event_trace(terminal->host,"\n"); | |
64 | + | |
65 | + debug("%d %p", (int) event->direction, terminal->scroll[event->direction]); | |
66 | + | |
67 | + // Do I have scroll method?? | |
68 | + if(terminal->scroll[event->direction].activate) | |
69 | + { | |
70 | + // Yes, fire it. | |
71 | + terminal->scroll[event->direction].activate(widget,terminal->scroll[event->direction].arg); | |
72 | + return TRUE; | |
73 | + } | |
74 | + | |
75 | + // Has selection? | |
76 | + if(lib3270_has_selection(terminal->host)) | |
77 | + { | |
78 | + switch(event->direction) | |
79 | + { | |
80 | + case GDK_SCROLL_UP: | |
81 | + lib3270_move_selection(terminal->host,LIB3270_DIR_UP); | |
82 | + return TRUE; | |
83 | + | |
84 | + case GDK_SCROLL_DOWN: | |
85 | + lib3270_move_selection(terminal->host,LIB3270_DIR_DOWN); | |
86 | + return TRUE; | |
87 | + | |
88 | + case GDK_SCROLL_LEFT: | |
89 | + lib3270_move_selection(terminal->host,LIB3270_DIR_LEFT); | |
90 | + return TRUE; | |
91 | + | |
92 | + case GDK_SCROLL_RIGHT: | |
93 | + lib3270_move_selection(terminal->host,LIB3270_DIR_RIGHT); | |
94 | + return TRUE; | |
95 | + } | |
96 | + | |
97 | + } | |
98 | + | |
99 | + // Check for fallbacks | |
100 | + size_t ix; | |
101 | + | |
102 | + static const struct | |
103 | + { | |
104 | + GdkScrollDirection direction; | |
105 | + guint keyval; | |
106 | + GdkModifierType state; | |
107 | + } fallbacks[] = { | |
108 | + | |
109 | + { GDK_SCROLL_UP, GDK_Page_Up, 0 }, | |
110 | + { GDK_SCROLL_DOWN, GDK_Page_Down, 0 }, | |
111 | + | |
112 | + { GDK_SCROLL_UP, GDK_ISO_Left_Tab, GDK_SHIFT_MASK }, | |
113 | + { GDK_SCROLL_DOWN, GDK_Tab, 0 }, | |
114 | + | |
115 | + { GDK_SCROLL_UP, GDK_Up, 0 }, | |
116 | + { GDK_SCROLL_DOWN, GDK_Down, 0 }, | |
117 | + | |
118 | + }; | |
119 | + | |
120 | + for(ix = 0; ix < G_N_ELEMENTS(fallbacks); ix++) { | |
121 | + | |
122 | + if(fallbacks[ix].direction == event->direction) { | |
123 | + | |
124 | + const V3270Accelerator * accel = v3270_get_accelerator(widget, fallbacks[ix].keyval, fallbacks[ix].state); | |
125 | + if(accel) | |
126 | + { | |
127 | + debug("Activating fallback mouse action \"%s\"\n",v3270_accelerator_get_name(accel)); | |
128 | +// lib3270_write_event_trace(terminal->hSession,"Activating fallback mouse action \"%s\"\n",v3270_accelerator_get_name(accel)); | |
129 | + v3270_accelerator_activate(accel,widget); | |
130 | + return TRUE; | |
131 | + } | |
132 | + | |
133 | + } | |
134 | + | |
135 | + } | |
136 | + | |
137 | + return FALSE; | |
138 | + } | |
139 | + | |
140 | + void v3270_set_scroll_handler(GtkWidget *widget, GdkScrollDirection direction, GCallback callback, gpointer data) | |
141 | + { | |
142 | + size_t ix = (size_t) direction; | |
143 | + | |
144 | + g_return_if_fail(GTK_IS_V3270(widget) && ix < 4); | |
145 | + | |
146 | + v3270 * terminal = GTK_V3270(widget); | |
147 | + | |
148 | + terminal->scroll[ix].activate = (void (*)(GtkWidget *, gpointer)) callback; | |
149 | + terminal->scroll[ix].arg = data; | |
150 | + | |
151 | + } | |
152 | + | ... | ... |
src/terminal/scroll.c
... | ... | @@ -1,68 +0,0 @@ |
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_write_event_trace(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_write_event_trace(terminal->host," dropped (not available)\n"); | |
53 | - return FALSE; | |
54 | - } | |
55 | - | |
56 | - lib3270_write_event_trace(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
... | ... | @@ -226,6 +226,9 @@ |
226 | 226 | <Option compilerVar="CC" /> |
227 | 227 | </Unit> |
228 | 228 | <Unit filename="src/terminal/actions/private.h" /> |
229 | + <Unit filename="src/terminal/actions/scroll.c"> | |
230 | + <Option compilerVar="CC" /> | |
231 | + </Unit> | |
229 | 232 | <Unit filename="src/terminal/actions/table.c"> |
230 | 233 | <Option compilerVar="CC" /> |
231 | 234 | </Unit> |
... | ... | @@ -308,9 +311,6 @@ |
308 | 311 | <Unit filename="src/terminal/properties/set.c"> |
309 | 312 | <Option compilerVar="CC" /> |
310 | 313 | </Unit> |
311 | - <Unit filename="src/terminal/scroll.c"> | |
312 | - <Option compilerVar="CC" /> | |
313 | - </Unit> | |
314 | 314 | <Unit filename="src/terminal/security.c"> |
315 | 315 | <Option compilerVar="CC" /> |
316 | 316 | </Unit> | ... | ... |