Commit 046426dfe3e3721ddcf1ced373ba964fbe95d021

Authored by Perry Werneck
1 parent 63b05b21
Exists in master and in 1 other branch develop

Refactoring keytable manager.

src/include/v3270/actions.h
... ... @@ -44,9 +44,9 @@
44 44 /// @brief Reset accelerator map to defaults.
45 45 LIB3270_EXPORT void v3270_accelerator_map_reset(GtkWidget *widget);
46 46  
47   - LIB3270_EXPORT void v3270_accelerator_activate(V3270Accelerator * accell, GtkWidget *terminal);
48   - LIB3270_EXPORT gboolean v3270_accelerator_compare(const V3270Accelerator * accell, const guint keyval, const GdkModifierType mods);
49   -
  47 + LIB3270_EXPORT const V3270Accelerator * v3270_get_accelerator(GtkWidget *widget, guint keyval, GdkModifierType state);
  48 + LIB3270_EXPORT void v3270_accelerator_activate(const V3270Accelerator * accell, GtkWidget *terminal);
  49 + LIB3270_EXPORT gboolean v3270_accelerator_compare(const V3270Accelerator * accell, const guint keyval, const GdkModifierType mods);
50 50  
51 51 G_END_DECLS
52 52  
... ...
src/terminal/keyboard.c
... ... @@ -150,15 +150,12 @@
150 150 #endif // DEBUG
151 151  
152 152 // Check accelerator table.
153   - GSList * acccelerator;
154   - for(acccelerator = widget->accelerators; acccelerator; acccelerator = g_slist_next(acccelerator))
  153 + const V3270Accelerator * acel = v3270_get_accelerator(GTK_WIDGET(widget), event->keyval, state);
  154 + if(acel)
155 155 {
156   - if(v3270_accelerator_compare((V3270Accelerator *) acccelerator->data, event->keyval, state))
157   - {
158   - v3270_accelerator_activate((V3270Accelerator *) acccelerator->data,GTK_WIDGET(widget));
159   - return TRUE;
160   - }
161   -
  156 + debug("%s will fire",__FUNCTION__);
  157 + v3270_accelerator_activate(acel,GTK_WIDGET(widget));
  158 + return TRUE;
162 159 }
163 160  
164 161 // Check PFKeys
... ... @@ -173,21 +170,6 @@
173 170 }
174 171 }
175 172  
176   - /*
177   - for(f=0; f < (int) G_N_ELEMENTS(keycode);f++)
178   - {
179   - if(keycode[f].keyval == event->keyval && state == keycode[f].state)
180   - {
181   - if(keycode[f].exec)
182   - keycode[f].exec(widget->host);
183   - else
184   - return FALSE;
185   - return TRUE;
186   -
187   - }
188   - }
189   - */
190   -
191 173 return FALSE;
192 174 }
193 175  
... ... @@ -198,6 +180,22 @@
198 180 terminal->activity.timestamp = time(0);
199 181 update_keyboard_state(terminal,event,TRUE);
200 182  
  183 + if(event->state & GDK_NUMLOCK_MASK)
  184 + {
  185 + // Hack for special keys
  186 + const V3270Accelerator * acel = v3270_get_accelerator(widget, event->keyval, event->state);
  187 +
  188 + debug("acel=%p",acel);
  189 +
  190 + if(acel)
  191 + {
  192 + debug("%s will fire",__FUNCTION__);
  193 + v3270_accelerator_activate(acel,GTK_WIDGET(widget));
  194 + gtk_im_context_reset(terminal->input_method);
  195 + return TRUE;
  196 + }
  197 + }
  198 +
201 199 if(gtk_im_context_filter_keypress(terminal->input_method,event))
202 200 return TRUE;
203 201  
... ...
src/terminal/keyboard/accelerator.c
... ... @@ -68,13 +68,25 @@
68 68 return accell->key == keyval && accell->mods == mods;
69 69 }
70 70  
71   - void v3270_accelerator_activate(V3270Accelerator * accell, GtkWidget *terminal)
  71 + void v3270_accelerator_activate(const V3270Accelerator * acel, GtkWidget *terminal)
72 72 {
73   - int rc = ((int (*)(GtkWidget *, const void *)) accell->activate)(terminal,accell->arg);
  73 + int rc = ((int (*)(GtkWidget *, const void *)) acel->activate)(terminal,acel->arg);
74 74  
75 75 if(rc)
76 76 gdk_display_beep(gdk_display_get_default());
77 77  
78 78 }
79 79  
  80 + const V3270Accelerator * v3270_get_accelerator(GtkWidget *widget, guint keyval, GdkModifierType state)
  81 + {
  82 + GSList * acccelerator;
  83 + for(acccelerator = GTK_V3270(widget)->accelerators; acccelerator; acccelerator = g_slist_next(acccelerator))
  84 + {
  85 + if(v3270_accelerator_compare((V3270Accelerator *) acccelerator->data, keyval, state))
  86 + return (V3270Accelerator *) acccelerator->data;
  87 + }
  88 +
  89 + return NULL;
  90 +
  91 + }
80 92  
... ...
src/terminal/keyboard/init.c
... ... @@ -40,11 +40,21 @@
40 40  
41 41 /*--[ Globals ]--------------------------------------------------------------------------------------*/
42 42  
43   -/*
  43 + static int fire_keypad_action(GtkWidget *widget, const struct InternalAction * action);
  44 +
44 45 static const struct InternalAction InternalActions[] =
45 46 {
  47 + {
  48 + GDK_KP_Add,
  49 + GDK_NUMLOCK_MASK,
  50 + G_CALLBACK(fire_keypad_action)
  51 + },
  52 + {
  53 + GDK_KP_Subtract,
  54 + GDK_NUMLOCK_MASK,
  55 + G_CALLBACK(fire_keypad_action)
  56 + }
46 57 };
47   -*/
48 58  
49 59 /*--[ Implement ]------------------------------------------------------------------------------------*/
50 60  
... ... @@ -64,6 +74,27 @@
64 74  
65 75 }
66 76  
  77 + static int fire_keypad_action(GtkWidget *widget, const struct InternalAction * action)
  78 + {
  79 + int rc = 0;
  80 + debug("%s",__FUNCTION__);
  81 +
  82 + if(v3270_get_toggle(widget,LIB3270_TOGGLE_KP_ALTERNATIVE))
  83 + {
  84 + if(action->key == GDK_KP_Add)
  85 + rc = lib3270_nextfield(GTK_V3270(widget)->host);
  86 + else
  87 + rc = lib3270_previousfield(GTK_V3270(widget)->host);
  88 + }
  89 + else
  90 + {
  91 + v3270_set_string(widget, action->key == GDK_KP_Add ? "+" : "-");
  92 + }
  93 +
  94 + return rc;
  95 +
  96 + }
  97 +
67 98 void v3270_init_accelerators(v3270 *widget)
68 99 {
69 100 size_t ix;
... ... @@ -105,7 +136,6 @@
105 136  
106 137 }
107 138  
108   - /*
109 139 // Create accelerators for internal actions.
110 140 {
111 141 size_t ix;
... ... @@ -124,7 +154,6 @@
124 154  
125 155 }
126 156 }
127   - */
128 157  
129 158 v3270_accelerator_map_sort(widget);
130 159  
... ...