Commit 16a8c05ebb637fa70679394dd5a3980cd88f317b
1 parent
1ae4cd71
Exists in
master
and in
5 other branches
Implementando seleção pelo teclado
Showing
6 changed files
with
110 additions
and
45 deletions
Show diff stats
src/gtk/actions.c
... | ... | @@ -183,41 +183,32 @@ static void selection_move_action(GtkAction *action, GtkWidget *widget) |
183 | 183 | lib3270_move_selection(GTK_V3270(widget)->host,(LIB3270_DIRECTION) g_object_get_data(G_OBJECT(action),"direction")); |
184 | 184 | } |
185 | 185 | |
186 | -void ui_connect_target_action(GtkAction *action, GtkWidget *widget, const gchar *target, const gchar *direction, GError **error) | |
186 | +static void cursor_move_action(GtkAction *action, GtkWidget *widget) | |
187 | 187 | { |
188 | - static const gchar *dirname[] = { "up", "down", "left", "right" }; | |
188 | + int flags = (int) g_object_get_data(G_OBJECT(action),"move_flags"); | |
189 | + trace("Action %s activated on widget %p flags=%04x",gtk_action_get_name(action),widget,g_object_get_data(G_OBJECT(action),"move_flags")); | |
190 | + lib3270_move_cursor(GTK_V3270(widget)->host,(LIB3270_DIRECTION) (flags & 0x03), (flags & 0x80) ); | |
191 | +} | |
189 | 192 | |
190 | - LIB3270_DIRECTION dir = (LIB3270_DIRECTION) -1; | |
193 | +void ui_connect_target_action(GtkAction *action, GtkWidget *widget, const gchar *target, unsigned short flags, GError **error) | |
194 | +{ | |
191 | 195 | int f; |
192 | 196 | |
193 | - if(!(direction && target)) | |
197 | + if(!target) | |
194 | 198 | { |
195 | 199 | gtk_action_set_sensitive(action,FALSE); |
196 | 200 | return; |
197 | 201 | } |
198 | 202 | |
199 | - for(f=0;f<G_N_ELEMENTS(dirname) && dir == -1;f++) | |
200 | - { | |
201 | - if(!g_strcasecmp(direction,dirname[f])) | |
202 | - { | |
203 | - dir = f; | |
204 | - break; | |
205 | - } | |
206 | - } | |
207 | - | |
208 | - if(dir == -1) | |
209 | - { | |
210 | - *error = g_error_new( g_quark_from_static_string(PACKAGE_NAME), | |
211 | - ENOENT, | |
212 | - _( "Unexpected direction \"%s\""), | |
213 | - direction); | |
214 | - } | |
215 | - | |
216 | 203 | if(!g_strcasecmp(target,"selection")) |
217 | 204 | { |
218 | - g_object_set_data(G_OBJECT(action),"direction",(gpointer) dir); | |
205 | + g_object_set_data(G_OBJECT(action),"direction",(gpointer) (flags & 3)); | |
219 | 206 | g_signal_connect(action,"activate",G_CALLBACK(selection_move_action),widget); |
220 | - | |
207 | + } | |
208 | + else if(!g_strcasecmp(target,"cursor")) | |
209 | + { | |
210 | + g_object_set_data(G_OBJECT(action),"move_flags",(gpointer) ((int) flags)); | |
211 | + g_signal_connect(action,"activate",G_CALLBACK(cursor_move_action),widget); | |
221 | 212 | } |
222 | 213 | else |
223 | 214 | { | ... | ... |
src/gtk/uiparser/parsefile.c
... | ... | @@ -139,13 +139,32 @@ |
139 | 139 | |
140 | 140 | static GtkAction * get_action(const gchar *name, struct parser *info, const gchar **names, const gchar **values, GError **error) |
141 | 141 | { |
142 | - const gchar * target = NULL; | |
143 | - const gchar * direction = NULL; | |
144 | - const gchar * id = ui_get_attribute("id",names,values); | |
145 | - GtkAction * action; | |
146 | - gchar * nm; | |
147 | - void (*connect)(GtkAction *action, GtkWidget *widget, const gchar *name, const gchar *id) = ui_connect_action; | |
148 | - GtkAction * (*create)(const gchar *,const gchar *,const gchar *,const gchar *) = gtk_action_new; | |
142 | + const gchar * target = NULL; | |
143 | + const gchar * direction = ui_get_attribute("direction",names,values); | |
144 | + const gchar * id = ui_get_attribute("id",names,values); | |
145 | + unsigned short flags = 0; | |
146 | + GtkAction * action; | |
147 | + gchar * nm; | |
148 | + void (*connect)(GtkAction *action, GtkWidget *widget, const gchar *name, const gchar *id) = ui_connect_action; | |
149 | + GtkAction * (*create)(const gchar *,const gchar *,const gchar *,const gchar *) = gtk_action_new; | |
150 | + | |
151 | + if(direction) | |
152 | + { | |
153 | + static const gchar *dirname[] = { "up", "down", "left", "right" }; | |
154 | + int f; | |
155 | + | |
156 | + for(f=0;f<G_N_ELEMENTS(dirname);f++) | |
157 | + { | |
158 | + if(!g_strcasecmp(direction,dirname[f])) | |
159 | + { | |
160 | + flags |= f; | |
161 | + break; | |
162 | + } | |
163 | + } | |
164 | + } | |
165 | + | |
166 | + if(ui_get_bool_attribute("selecting",names,values,FALSE)) | |
167 | + flags |= 0x80; | |
149 | 168 | |
150 | 169 | if(!g_strcasecmp(name,"toggle")) |
151 | 170 | { |
... | ... | @@ -155,8 +174,7 @@ |
155 | 174 | } |
156 | 175 | else if(!g_strcasecmp(name,"move")) |
157 | 176 | { |
158 | - target = ui_get_attribute("target",names,values); | |
159 | - direction = ui_get_attribute("direction",names,values); | |
177 | + target = ui_get_attribute("target",names,values); | |
160 | 178 | |
161 | 179 | if(!(target && direction)) |
162 | 180 | { |
... | ... | @@ -164,7 +182,8 @@ |
164 | 182 | return NULL; |
165 | 183 | } |
166 | 184 | |
167 | - nm = g_strconcat("move",target,direction,NULL); | |
185 | + nm = g_strconcat((flags & 0x80) ? "select" : "move",target,direction, NULL); | |
186 | + | |
168 | 187 | } |
169 | 188 | else if(!g_strcasecmp(name,"toggleset")) |
170 | 189 | { |
... | ... | @@ -215,7 +234,7 @@ |
215 | 234 | if(ix >= 0) |
216 | 235 | ui_connect_index_action(info->action[ix] = action,info->center_widget,ix,info->action); |
217 | 236 | else if(target) |
218 | - ui_connect_target_action(action,info->center_widget,target,direction,error); | |
237 | + ui_connect_target_action(action,info->center_widget,target,flags,error); | |
219 | 238 | else if(g_strcasecmp(name,"quit")) |
220 | 239 | connect(action,info->center_widget,name,id); |
221 | 240 | else | ... | ... |
src/gtk/uiparser/parser.h
... | ... | @@ -53,7 +53,7 @@ |
53 | 53 | |
54 | 54 | GtkWidget * ui_parse_xml_folder(const gchar *path, const gchar ** groupname, const gchar **popupname, const gchar **actionname, GtkWidget *widget, const UI_WIDGET_SETUP *itn); |
55 | 55 | void ui_connect_action(GtkAction *action, GtkWidget *widget, const gchar *name, const gchar *id); |
56 | - void ui_connect_target_action(GtkAction *action, GtkWidget *widget, const gchar *target, const gchar *direction, GError **error); | |
56 | + void ui_connect_target_action(GtkAction *action, GtkWidget *widget, const gchar *target, unsigned short flags, GError **error); | |
57 | 57 | void ui_connect_index_action(GtkAction *action, GtkWidget *widget, int ix, GtkAction **lst); |
58 | 58 | void ui_connect_toggle(GtkAction *action, GtkWidget *widget, const gchar *name, const gchar *id); |
59 | 59 | void ui_connect_pfkey(GtkAction *action, GtkWidget *widget, const gchar *name, const gchar *id); | ... | ... |
src/include/lib3270.h
... | ... | @@ -388,6 +388,17 @@ |
388 | 388 | LIB3270_EXPORT int lib3270_set_cursor_address(H3270 *h, int baddr); |
389 | 389 | |
390 | 390 | /** |
391 | + * Move cursor | |
392 | + * | |
393 | + * @param h Session handle. | |
394 | + * @param dir Direction to move | |
395 | + * @param sel Non zero to move and selected to the current cursor position | |
396 | + * | |
397 | + * @return 0 if the movement can be done, non zero if failed. | |
398 | + */ | |
399 | + LIB3270_EXPORT int lib3270_move_cursor(H3270 *h, LIB3270_DIRECTION dir, unsigned char sel); | |
400 | + | |
401 | + /** | |
391 | 402 | * get cursor address. |
392 | 403 | * |
393 | 404 | * @param h Session handle. | ... | ... |
src/lib3270/selection.c
... | ... | @@ -202,14 +202,14 @@ LIB3270_EXPORT void lib3270_select_to(H3270 *session, int baddr) |
202 | 202 | if(!lib3270_connected(session)) |
203 | 203 | return; |
204 | 204 | |
205 | - lib3270_set_cursor_address(session,session->select.end = baddr); | |
206 | - | |
207 | 205 | if(!session->selected) |
208 | 206 | { |
209 | 207 | session->select.begin = session->cursor_addr; |
210 | 208 | set_selected(session); |
211 | 209 | } |
212 | 210 | |
211 | + lib3270_set_cursor_address(session,session->select.end = baddr); | |
212 | + | |
213 | 213 | update_selection(session); |
214 | 214 | |
215 | 215 | } |
... | ... | @@ -391,3 +391,47 @@ LIB3270_EXPORT int lib3270_move_selection(H3270 *hSession, LIB3270_DIRECTION dir |
391 | 391 | |
392 | 392 | return 0; |
393 | 393 | } |
394 | + | |
395 | +LIB3270_EXPORT int lib3270_move_cursor(H3270 *hSession, LIB3270_DIRECTION dir, unsigned char sel) | |
396 | +{ | |
397 | + int cursor_addr = hSession->cursor_addr; | |
398 | + | |
399 | + if(!lib3270_connected(hSession)) | |
400 | + return -1; | |
401 | + | |
402 | + switch(dir) | |
403 | + { | |
404 | + case LIB3270_DIR_UP: | |
405 | + if(cursor_addr <= hSession->cols) | |
406 | + return EINVAL; | |
407 | + cursor_addr -= hSession->cols; | |
408 | + break; | |
409 | + | |
410 | + case LIB3270_DIR_DOWN: | |
411 | + if(cursor_addr >= (hSession->cols * (hSession->rows-1))) | |
412 | + return EINVAL; | |
413 | + cursor_addr += hSession->cols; | |
414 | + break; | |
415 | + | |
416 | + case LIB3270_DIR_LEFT: | |
417 | + if( (cursor_addr % hSession->cols) < 1) | |
418 | + return EINVAL; | |
419 | + cursor_addr--; | |
420 | + break; | |
421 | + | |
422 | + case LIB3270_DIR_RIGHT: | |
423 | + if( (cursor_addr % hSession->cols) >= (hSession->cols-1)) | |
424 | + return EINVAL; | |
425 | + cursor_addr++; | |
426 | + break; | |
427 | + | |
428 | + default: | |
429 | + return -1; | |
430 | + } | |
431 | + | |
432 | + if(sel) | |
433 | + lib3270_select_to(hSession,cursor_addr); | |
434 | + else | |
435 | + lib3270_set_cursor_address(hSession,cursor_addr); | |
436 | + | |
437 | +} | ... | ... |
ui/00default.xml
... | ... | @@ -189,20 +189,20 @@ |
189 | 189 | <accelerator action='SysREQ' key='Sys_Req' group='online' /> |
190 | 190 | <accelerator action='SysREQ' key='<shift>Print' group='online' /> |
191 | 191 | |
192 | - <accelerator action='SelectRight' key='<Shift>Right' group='online' /> | |
193 | - <accelerator action='SelectLeft' key='<Shift>Left' group='online' /> | |
194 | - <accelerator action='SelectUp' key='<Shift>Up' group='online' /> | |
195 | - <accelerator action='SelectDown' key='<Shift>Down' group='online' /> | |
192 | + <accelerator action='move' target='cursor' direction='right' selecting='yes' key='<Shift>Right' group='online' /> | |
193 | + <accelerator action='move' target='cursor' direction='left' selecting='yes' key='<Shift>Left' group='online' /> | |
194 | + <accelerator action='move' target='cursor' direction='up' selecting='yes' key='<Shift>Up' group='online' /> | |
195 | + <accelerator action='move' target='cursor' direction='down' selecting='yes' key='<Shift>Down' group='online' /> | |
196 | 196 | |
197 | 197 | <accelerator action='move' target='selection' direction='right' key='<alt>Right' /> |
198 | 198 | <accelerator action='move' target='selection' direction='left' key='<alt>Left' /> |
199 | 199 | <accelerator action='move' target='selection' direction='up' key='<alt>Up' /> |
200 | 200 | <accelerator action='move' target='selection' direction='down' key='<alt>Down' /> |
201 | 201 | |
202 | - <accelerator action='CursorRight' key='Right' group='online' /> | |
203 | - <accelerator action='CursorLeft' key='Left' group='online' /> | |
204 | - <accelerator action='CursorUp' key='Up' group='online' /> | |
205 | - <accelerator action='CursorDown' key='Down' group='online' /> | |
202 | + <accelerator action='move' target='cursor' direction='right' key='Right' group='online' /> | |
203 | + <accelerator action='move' target='cursor' direction='left' key='Left' group='online' /> | |
204 | + <accelerator action='move' target='cursor' direction='up' key='Up' group='online' /> | |
205 | + <accelerator action='move' target='cursor' direction='down' key='Down' group='online' /> | |
206 | 206 | |
207 | 207 | <accelerator action='PreviousField' key='ISO_Left_Tab' group='online' /> |
208 | 208 | <accelerator action='NextField' key='Tab' group='online' /> | ... | ... |