Commit 660c53c13f7727444df46e1098da27e19f4a9f7c
1 parent
e459184e
Exists in
master
and in
1 other branch
The toggle action now lives in lib3270.
Showing
4 changed files
with
162 additions
and
4 deletions
Show diff stats
src/include/v3270/actions.h
| ... | ... | @@ -33,6 +33,7 @@ |
| 33 | 33 | |
| 34 | 34 | #include <gtk/gtk.h> |
| 35 | 35 | #include <lib3270/actions.h> |
| 36 | + #include <lib3270/toggle.h> | |
| 36 | 37 | |
| 37 | 38 | G_BEGIN_DECLS |
| 38 | 39 | |
| ... | ... | @@ -161,9 +162,11 @@ |
| 161 | 162 | LIB3270_EXPORT GdkPixbuf * v3270_action_get_pixbuf(GAction *action, GtkIconSize icon_size, GtkIconLookupFlags flags); |
| 162 | 163 | |
| 163 | 164 | LIB3270_EXPORT GAction * g_action_new_from_lib3270(const LIB3270_ACTION * definition); |
| 165 | + LIB3270_EXPORT GAction * g_action_new_from_toggle(const LIB3270_TOGGLE * definition); | |
| 164 | 166 | |
| 165 | 167 | LIB3270_EXPORT void g_action_map_add_v3270_actions(GActionMap *action_map); |
| 166 | 168 | LIB3270_EXPORT void g_action_map_add_lib3270_actions(GActionMap *action_map); |
| 169 | + LIB3270_EXPORT void g_action_map_add_lib3270_toggles(GActionMap *action_map); | |
| 167 | 170 | |
| 168 | 171 | G_END_DECLS |
| 169 | 172 | ... | ... |
src/terminal/actions/action.c
| ... | ... | @@ -401,12 +401,20 @@ |
| 401 | 401 | |
| 402 | 402 | GVariant * iface_get_state(GAction *object) { |
| 403 | 403 | |
| 404 | - GtkWidget * terminal = V3270_ACTION(object)->terminal; | |
| 404 | + GtkWidget * terminal = V3270_ACTION(object)->terminal; | |
| 405 | + GVariant * state; | |
| 405 | 406 | |
| 406 | - if(!terminal) | |
| 407 | - g_variant_new_boolean(FALSE); | |
| 407 | + if(terminal) { | |
| 408 | + state = V3270_ACTION_GET_CLASS(object)->get_state(object,terminal); | |
| 409 | + } else { | |
| 410 | + state = g_variant_new_boolean(FALSE); | |
| 411 | + } | |
| 412 | + | |
| 413 | + if(state) | |
| 414 | + g_variant_ref(state); | |
| 415 | + | |
| 416 | + return state; | |
| 408 | 417 | |
| 409 | - return V3270_ACTION_GET_CLASS(object)->get_state(object,terminal); | |
| 410 | 418 | } |
| 411 | 419 | |
| 412 | 420 | const GVariantType * iface_get_parameter_type(GAction G_GNUC_UNUSED(*action)) { | ... | ... |
| ... | ... | @@ -0,0 +1,144 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * @brief Implement GAction "wrapper" for lib3270's toggles. | |
| 32 | + * | |
| 33 | + */ | |
| 34 | + | |
| 35 | + #include <internals.h> | |
| 36 | + #include <v3270.h> | |
| 37 | + #include <v3270/actions.h> | |
| 38 | + | |
| 39 | + #define LIB3270_TYPE_TOGGLE_ACTION (Lib3270ToggleAction_get_type()) | |
| 40 | + #define LIB3270_TOGGLE_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), LIB3270_TYPE_TOGGLE_ACTION, Lib3270ToggleAction)) | |
| 41 | + #define LIB3270_IS_TOGGLE_ACTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), LIB3270_TYPE_TOGGLE_ACTION)) | |
| 42 | + | |
| 43 | + #define GET_DESCRIPTOR(obj) ((const LIB3270_TOGGLE *) ((V3270Action *) obj)->info) | |
| 44 | + | |
| 45 | + typedef struct _Lib3270ToggleActionClass { | |
| 46 | + V3270ActionClass parent_class; | |
| 47 | + } Lib3270ToggleActionClass; | |
| 48 | + | |
| 49 | + typedef struct _Lib3270ToggleAction { | |
| 50 | + V3270Action parent; | |
| 51 | + const void * listener; | |
| 52 | + } Lib3270ToggleAction; | |
| 53 | + | |
| 54 | + static void Lib3270ToggleAction_class_init(Lib3270ToggleActionClass *klass); | |
| 55 | + static void Lib3270ToggleAction_init(Lib3270ToggleAction *action); | |
| 56 | + | |
| 57 | + G_DEFINE_TYPE(Lib3270ToggleAction, Lib3270ToggleAction, V3270_TYPE_ACTION); | |
| 58 | + | |
| 59 | + 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)) { | |
| 60 | + v3270_action_notify_state(G_ACTION(action)); | |
| 61 | + } | |
| 62 | + | |
| 63 | + static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { | |
| 64 | + | |
| 65 | + Lib3270ToggleAction * action = LIB3270_TOGGLE_ACTION(object); | |
| 66 | + | |
| 67 | + if(action->listener) { | |
| 68 | + lib3270_unregister_toggle_listener(v3270_get_session(from),GET_DESCRIPTOR(object)->id,object); | |
| 69 | + action->listener = NULL; | |
| 70 | + } | |
| 71 | + | |
| 72 | + if(to) | |
| 73 | + action->listener = lib3270_register_toggle_listener(v3270_get_session(to),GET_DESCRIPTOR(object)->id,change_state,object); | |
| 74 | + | |
| 75 | + V3270_ACTION_CLASS(Lib3270ToggleAction_parent_class)->change_widget(object,from,to); | |
| 76 | + | |
| 77 | + } | |
| 78 | + | |
| 79 | + static void activate(GAction *action, GVariant *parameter, GtkWidget *terminal) { | |
| 80 | + | |
| 81 | + debug("Activating \"%s\"",g_action_get_name(action)); | |
| 82 | + | |
| 83 | + if(parameter && g_variant_is_of_type(parameter,G_VARIANT_TYPE_BOOLEAN)) { | |
| 84 | + | |
| 85 | + lib3270_set_toggle(v3270_get_session(terminal),GET_DESCRIPTOR(action)->id,g_variant_get_boolean(parameter)); | |
| 86 | + debug("Toggle set to %s",lib3270_get_toggle(v3270_get_session(terminal),GET_DESCRIPTOR(action)->id) ? "ON" : "OFF"); | |
| 87 | + | |
| 88 | + } else { | |
| 89 | + | |
| 90 | + lib3270_toggle(v3270_get_session(terminal),GET_DESCRIPTOR(action)->id); | |
| 91 | + debug("Toggle is %s",lib3270_get_toggle(v3270_get_session(terminal),GET_DESCRIPTOR(action)->id) ? "ON" : "OFF"); | |
| 92 | + | |
| 93 | + } | |
| 94 | + | |
| 95 | + } | |
| 96 | + | |
| 97 | + static GVariant * get_state(GAction *action, GtkWidget *terminal) { | |
| 98 | + | |
| 99 | + debug("%s(%s)",__FUNCTION__,g_action_get_name(action)); | |
| 100 | + | |
| 101 | + return g_variant_new_boolean( | |
| 102 | + lib3270_get_toggle( | |
| 103 | + v3270_get_session(terminal), | |
| 104 | + GET_DESCRIPTOR(action)->id | |
| 105 | + ) | |
| 106 | + ); | |
| 107 | + | |
| 108 | + } | |
| 109 | + | |
| 110 | + void Lib3270ToggleAction_class_init(Lib3270ToggleActionClass *klass) { | |
| 111 | + | |
| 112 | + klass->parent_class.change_widget = change_widget; | |
| 113 | + klass->parent_class.state.type = G_VARIANT_TYPE_BOOLEAN; | |
| 114 | + klass->parent_class.get_state = get_state; | |
| 115 | + | |
| 116 | + } | |
| 117 | + | |
| 118 | + void Lib3270ToggleAction_init(Lib3270ToggleAction *action) { | |
| 119 | + action->parent.activate = activate; | |
| 120 | + } | |
| 121 | + | |
| 122 | + GAction * g_action_new_from_toggle(const LIB3270_TOGGLE * definition) { | |
| 123 | + | |
| 124 | + Lib3270ToggleAction * action = (Lib3270ToggleAction *) g_object_new(LIB3270_TYPE_TOGGLE_ACTION, NULL); | |
| 125 | + action->parent.info = (const LIB3270_PROPERTY *) definition; | |
| 126 | + | |
| 127 | + return G_ACTION(action); | |
| 128 | + | |
| 129 | + } | |
| 130 | + | |
| 131 | + void g_action_map_add_lib3270_toggles(GActionMap *action_map) { | |
| 132 | + | |
| 133 | + size_t ix; | |
| 134 | + const LIB3270_TOGGLE * toggles = lib3270_get_toggles(); | |
| 135 | + | |
| 136 | + for(ix = 0; toggles[ix].name; ix++) { | |
| 137 | + | |
| 138 | + GAction *action = g_action_new_from_toggle(&toggles[ix]); | |
| 139 | + g_action_map_add_action(action_map,action); | |
| 140 | + | |
| 141 | + } | |
| 142 | + | |
| 143 | + } | |
| 144 | + | ... | ... |
v3270.cbp
| ... | ... | @@ -249,6 +249,9 @@ |
| 249 | 249 | <Unit filename="src/terminal/actions/table.c"> |
| 250 | 250 | <Option compilerVar="CC" /> |
| 251 | 251 | </Unit> |
| 252 | + <Unit filename="src/terminal/actions/toggle.c"> | |
| 253 | + <Option compilerVar="CC" /> | |
| 254 | + </Unit> | |
| 252 | 255 | <Unit filename="src/terminal/actions/zoom.c"> |
| 253 | 256 | <Option compilerVar="CC" /> |
| 254 | 257 | </Unit> | ... | ... |