diff --git a/src/gtk/actions.c b/src/gtk/actions.c index 2e1ce7e..8e67451 100644 --- a/src/gtk/actions.c +++ b/src/gtk/actions.c @@ -183,41 +183,32 @@ static void selection_move_action(GtkAction *action, GtkWidget *widget) lib3270_move_selection(GTK_V3270(widget)->host,(LIB3270_DIRECTION) g_object_get_data(G_OBJECT(action),"direction")); } -void ui_connect_target_action(GtkAction *action, GtkWidget *widget, const gchar *target, const gchar *direction, GError **error) +static void cursor_move_action(GtkAction *action, GtkWidget *widget) { - static const gchar *dirname[] = { "up", "down", "left", "right" }; + int flags = (int) g_object_get_data(G_OBJECT(action),"move_flags"); + trace("Action %s activated on widget %p flags=%04x",gtk_action_get_name(action),widget,g_object_get_data(G_OBJECT(action),"move_flags")); + lib3270_move_cursor(GTK_V3270(widget)->host,(LIB3270_DIRECTION) (flags & 0x03), (flags & 0x80) ); +} - LIB3270_DIRECTION dir = (LIB3270_DIRECTION) -1; +void ui_connect_target_action(GtkAction *action, GtkWidget *widget, const gchar *target, unsigned short flags, GError **error) +{ int f; - if(!(direction && target)) + if(!target) { gtk_action_set_sensitive(action,FALSE); return; } - for(f=0;f= 0) ui_connect_index_action(info->action[ix] = action,info->center_widget,ix,info->action); else if(target) - ui_connect_target_action(action,info->center_widget,target,direction,error); + ui_connect_target_action(action,info->center_widget,target,flags,error); else if(g_strcasecmp(name,"quit")) connect(action,info->center_widget,name,id); else diff --git a/src/gtk/uiparser/parser.h b/src/gtk/uiparser/parser.h index e798e16..ebf4724 100644 --- a/src/gtk/uiparser/parser.h +++ b/src/gtk/uiparser/parser.h @@ -53,7 +53,7 @@ GtkWidget * ui_parse_xml_folder(const gchar *path, const gchar ** groupname, const gchar **popupname, const gchar **actionname, GtkWidget *widget, const UI_WIDGET_SETUP *itn); void ui_connect_action(GtkAction *action, GtkWidget *widget, const gchar *name, const gchar *id); - void ui_connect_target_action(GtkAction *action, GtkWidget *widget, const gchar *target, const gchar *direction, GError **error); + void ui_connect_target_action(GtkAction *action, GtkWidget *widget, const gchar *target, unsigned short flags, GError **error); void ui_connect_index_action(GtkAction *action, GtkWidget *widget, int ix, GtkAction **lst); void ui_connect_toggle(GtkAction *action, GtkWidget *widget, const gchar *name, const gchar *id); void ui_connect_pfkey(GtkAction *action, GtkWidget *widget, const gchar *name, const gchar *id); diff --git a/src/include/lib3270.h b/src/include/lib3270.h index e587d7e..dfe0d4b 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -388,6 +388,17 @@ LIB3270_EXPORT int lib3270_set_cursor_address(H3270 *h, int baddr); /** + * Move cursor + * + * @param h Session handle. + * @param dir Direction to move + * @param sel Non zero to move and selected to the current cursor position + * + * @return 0 if the movement can be done, non zero if failed. + */ + LIB3270_EXPORT int lib3270_move_cursor(H3270 *h, LIB3270_DIRECTION dir, unsigned char sel); + + /** * get cursor address. * * @param h Session handle. diff --git a/src/lib3270/selection.c b/src/lib3270/selection.c index e965fb2..3d1fa22 100644 --- a/src/lib3270/selection.c +++ b/src/lib3270/selection.c @@ -202,14 +202,14 @@ LIB3270_EXPORT void lib3270_select_to(H3270 *session, int baddr) if(!lib3270_connected(session)) return; - lib3270_set_cursor_address(session,session->select.end = baddr); - if(!session->selected) { session->select.begin = session->cursor_addr; set_selected(session); } + lib3270_set_cursor_address(session,session->select.end = baddr); + update_selection(session); } @@ -391,3 +391,47 @@ LIB3270_EXPORT int lib3270_move_selection(H3270 *hSession, LIB3270_DIRECTION dir return 0; } + +LIB3270_EXPORT int lib3270_move_cursor(H3270 *hSession, LIB3270_DIRECTION dir, unsigned char sel) +{ + int cursor_addr = hSession->cursor_addr; + + if(!lib3270_connected(hSession)) + return -1; + + switch(dir) + { + case LIB3270_DIR_UP: + if(cursor_addr <= hSession->cols) + return EINVAL; + cursor_addr -= hSession->cols; + break; + + case LIB3270_DIR_DOWN: + if(cursor_addr >= (hSession->cols * (hSession->rows-1))) + return EINVAL; + cursor_addr += hSession->cols; + break; + + case LIB3270_DIR_LEFT: + if( (cursor_addr % hSession->cols) < 1) + return EINVAL; + cursor_addr--; + break; + + case LIB3270_DIR_RIGHT: + if( (cursor_addr % hSession->cols) >= (hSession->cols-1)) + return EINVAL; + cursor_addr++; + break; + + default: + return -1; + } + + if(sel) + lib3270_select_to(hSession,cursor_addr); + else + lib3270_set_cursor_address(hSession,cursor_addr); + +} diff --git a/ui/00default.xml b/ui/00default.xml index 4e33c4d..16ff1eb 100644 --- a/ui/00default.xml +++ b/ui/00default.xml @@ -189,20 +189,20 @@ - - - - + + + + - - - - + + + + -- libgit2 0.21.2