diff --git a/src/include/v3270/actions.h b/src/include/v3270/actions.h index 03470b1..13b3685 100644 --- a/src/include/v3270/actions.h +++ b/src/include/v3270/actions.h @@ -33,6 +33,7 @@ #include #include + #include G_BEGIN_DECLS @@ -161,9 +162,11 @@ LIB3270_EXPORT GdkPixbuf * v3270_action_get_pixbuf(GAction *action, GtkIconSize icon_size, GtkIconLookupFlags flags); LIB3270_EXPORT GAction * g_action_new_from_lib3270(const LIB3270_ACTION * definition); + LIB3270_EXPORT GAction * g_action_new_from_toggle(const LIB3270_TOGGLE * definition); LIB3270_EXPORT void g_action_map_add_v3270_actions(GActionMap *action_map); LIB3270_EXPORT void g_action_map_add_lib3270_actions(GActionMap *action_map); + LIB3270_EXPORT void g_action_map_add_lib3270_toggles(GActionMap *action_map); G_END_DECLS diff --git a/src/terminal/actions/action.c b/src/terminal/actions/action.c index 9b28b83..454eaa7 100644 --- a/src/terminal/actions/action.c +++ b/src/terminal/actions/action.c @@ -401,12 +401,20 @@ GVariant * iface_get_state(GAction *object) { - GtkWidget * terminal = V3270_ACTION(object)->terminal; + GtkWidget * terminal = V3270_ACTION(object)->terminal; + GVariant * state; - if(!terminal) - g_variant_new_boolean(FALSE); + if(terminal) { + state = V3270_ACTION_GET_CLASS(object)->get_state(object,terminal); + } else { + state = g_variant_new_boolean(FALSE); + } + + if(state) + g_variant_ref(state); + + return state; - return V3270_ACTION_GET_CLASS(object)->get_state(object,terminal); } const GVariantType * iface_get_parameter_type(GAction G_GNUC_UNUSED(*action)) { diff --git a/src/terminal/actions/toggle.c b/src/terminal/actions/toggle.c new file mode 100644 index 0000000..484d61f --- /dev/null +++ b/src/terminal/actions/toggle.c @@ -0,0 +1,144 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + /** + * @brief Implement GAction "wrapper" for lib3270's toggles. + * + */ + + #include + #include + #include + + #define LIB3270_TYPE_TOGGLE_ACTION (Lib3270ToggleAction_get_type()) + #define LIB3270_TOGGLE_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), LIB3270_TYPE_TOGGLE_ACTION, Lib3270ToggleAction)) + #define LIB3270_IS_TOGGLE_ACTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), LIB3270_TYPE_TOGGLE_ACTION)) + + #define GET_DESCRIPTOR(obj) ((const LIB3270_TOGGLE *) ((V3270Action *) obj)->info) + + typedef struct _Lib3270ToggleActionClass { + V3270ActionClass parent_class; + } Lib3270ToggleActionClass; + + typedef struct _Lib3270ToggleAction { + V3270Action parent; + const void * listener; + } Lib3270ToggleAction; + + static void Lib3270ToggleAction_class_init(Lib3270ToggleActionClass *klass); + static void Lib3270ToggleAction_init(Lib3270ToggleAction *action); + + G_DEFINE_TYPE(Lib3270ToggleAction, Lib3270ToggleAction, V3270_TYPE_ACTION); + + static void change_state(H3270 G_GNUC_UNUSED(*hSession), LIB3270_TOGGLE_ID G_GNUC_UNUSED(id), char G_GNUC_UNUSED(state), void G_GNUC_UNUSED(*action)) { + v3270_action_notify_state(G_ACTION(action)); + } + + static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { + + Lib3270ToggleAction * action = LIB3270_TOGGLE_ACTION(object); + + if(action->listener) { + lib3270_unregister_toggle_listener(v3270_get_session(from),GET_DESCRIPTOR(object)->id,object); + action->listener = NULL; + } + + if(to) + action->listener = lib3270_register_toggle_listener(v3270_get_session(to),GET_DESCRIPTOR(object)->id,change_state,object); + + V3270_ACTION_CLASS(Lib3270ToggleAction_parent_class)->change_widget(object,from,to); + + } + + static void activate(GAction *action, GVariant *parameter, GtkWidget *terminal) { + + debug("Activating \"%s\"",g_action_get_name(action)); + + if(parameter && g_variant_is_of_type(parameter,G_VARIANT_TYPE_BOOLEAN)) { + + lib3270_set_toggle(v3270_get_session(terminal),GET_DESCRIPTOR(action)->id,g_variant_get_boolean(parameter)); + debug("Toggle set to %s",lib3270_get_toggle(v3270_get_session(terminal),GET_DESCRIPTOR(action)->id) ? "ON" : "OFF"); + + } else { + + lib3270_toggle(v3270_get_session(terminal),GET_DESCRIPTOR(action)->id); + debug("Toggle is %s",lib3270_get_toggle(v3270_get_session(terminal),GET_DESCRIPTOR(action)->id) ? "ON" : "OFF"); + + } + + } + + static GVariant * get_state(GAction *action, GtkWidget *terminal) { + + debug("%s(%s)",__FUNCTION__,g_action_get_name(action)); + + return g_variant_new_boolean( + lib3270_get_toggle( + v3270_get_session(terminal), + GET_DESCRIPTOR(action)->id + ) + ); + + } + + void Lib3270ToggleAction_class_init(Lib3270ToggleActionClass *klass) { + + klass->parent_class.change_widget = change_widget; + klass->parent_class.state.type = G_VARIANT_TYPE_BOOLEAN; + klass->parent_class.get_state = get_state; + + } + + void Lib3270ToggleAction_init(Lib3270ToggleAction *action) { + action->parent.activate = activate; + } + + GAction * g_action_new_from_toggle(const LIB3270_TOGGLE * definition) { + + Lib3270ToggleAction * action = (Lib3270ToggleAction *) g_object_new(LIB3270_TYPE_TOGGLE_ACTION, NULL); + action->parent.info = (const LIB3270_PROPERTY *) definition; + + return G_ACTION(action); + + } + + void g_action_map_add_lib3270_toggles(GActionMap *action_map) { + + size_t ix; + const LIB3270_TOGGLE * toggles = lib3270_get_toggles(); + + for(ix = 0; toggles[ix].name; ix++) { + + GAction *action = g_action_new_from_toggle(&toggles[ix]); + g_action_map_add_action(action_map,action); + + } + + } + diff --git a/v3270.cbp b/v3270.cbp index e51a98c..3400f7f 100644 --- a/v3270.cbp +++ b/v3270.cbp @@ -249,6 +249,9 @@ + + -- libgit2 0.21.2