From c5066fd55d5785e9f9302043fa9eee3f9c9bcbda Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 30 Oct 2019 17:06:15 -0300 Subject: [PATCH] Adding method to get the "activatable" state of an action group. --- src/core/actions/table.c | 27 +++++++++++++++++++++++++++ src/include/lib3270/actions.h | 10 ++++++++++ 2 files changed, 37 insertions(+), 0 deletions(-) diff --git a/src/core/actions/table.c b/src/core/actions/table.c index 7aec060..fb525b1 100644 --- a/src/core/actions/table.c +++ b/src/core/actions/table.c @@ -731,3 +731,30 @@ return actions; } + static int default_activatable_state(const H3270 *hSession) + { + return hSession == NULL ? 0 : 1; + } + + LIB3270_EXPORT int lib3270_action_group_get_activatable(const H3270 *hSession, const LIB3270_ACTION_GROUP group) + { + static const struct + { + int (*get)(const H3270 *); + } activatable[LIB3270_ACTION_CUSTOM] = + { + { default_activatable_state }, // LIB3270_ACTION_GROUP_NONE + { lib3270_is_connected }, // LIB3270_ACTION_GROUP_ONLINE + { lib3270_is_disconnected }, // LIB3270_ACTION_GROUP_OFFLINE + { lib3270_has_selection }, // LIB3270_ACTION_GROUP_SELECTION + { lib3270_is_unlocked }, // LIB3270_ACTION_GROUP_LOCK_STATE + { lib3270_is_formatted }, // LIB3270_ACTION_GROUP_FORMATTED + }; + + if(group < (sizeof(activatable)/sizeof(activatable[0]))) { + return activatable[group].get(hSession); + } + + return default_activatable_state(hSession); + + } diff --git a/src/include/lib3270/actions.h b/src/include/lib3270/actions.h index da85aff..5e20677 100644 --- a/src/include/lib3270/actions.h +++ b/src/include/lib3270/actions.h @@ -73,6 +73,16 @@ } LIB3270_ACTION; +/** + * @brief Query if the action group can be activated. + * + * @param hSession TN3270 Session handle. + * @param group The group to listen. + * + * @return The current state of the group. + * + */ + LIB3270_EXPORT int lib3270_action_group_get_activatable(const H3270 *hSession, const LIB3270_ACTION_GROUP group); /** * @brief Register an action group listener. -- libgit2 0.21.2