From a1bc9024b04c9dabe10cb2c295798659eece921c Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 15 Jan 2020 14:45:26 -0300 Subject: [PATCH] Adding simple & dialog actions. --- src/include/v3270/actions.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/terminal/actions/action.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++---------------------------- src/terminal/actions/dialog.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/terminal/actions/simple.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ v3270.cbp | 6 ++++++ 5 files changed, 333 insertions(+), 28 deletions(-) create mode 100644 src/terminal/actions/dialog.c create mode 100644 src/terminal/actions/simple.c diff --git a/src/include/v3270/actions.h b/src/include/v3270/actions.h index af950f1..684bcd8 100644 --- a/src/include/v3270/actions.h +++ b/src/include/v3270/actions.h @@ -149,6 +149,10 @@ GVariant * (*get_state)(GAction *action, GtkWidget *terminal); const gchar * (*translate)(GAction *action, const gchar *text); + const gchar * (*get_icon_name)(GAction *action); + const gchar * (*get_label)(GAction *action); + const gchar * (*get_tooltip)(GAction *action); + } V3270ActionClass; LIB3270_EXPORT GType V3270Action_get_type(void) G_GNUC_CONST; @@ -179,6 +183,49 @@ LIB3270_EXPORT void g_action_map_add_lib3270_actions(GActionMap *action_map); LIB3270_EXPORT void g_action_map_add_lib3270_toggles(GActionMap *action_map); + // + // "Simple" action + // + #define V3270_TYPE_SIMPLE_ACTION (V3270SimpleAction_get_type()) + #define V3270_SIMPLE_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), V3270_TYPE_SIMPLE_ACTION, V3270SimpleAction)) + #define V3270_SIMPLE_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), V3270_TYPE_SIMPLE_ACTION, V3270SimpleActionClass)) + #define V3270_IS_SIMPLE_ACTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), V3270_TYPE_SIMPLE_ACTION)) + #define V3270_IS_SIMPLE_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), V3270_TYPE_SIMPLE_ACTION)) + #define V3270_SIMPLE_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), V3270_TYPE_SIMPLE_ACTION, V3270SimpleActionClass)) + + typedef struct _V3270SimpleAction { + + V3270Action parent; + + // Fixed data + const gchar * icon_name; + const gchar * label; + const gchar * tooltip; + + // Lib3270 Action group + struct { + LIB3270_ACTION_GROUP id; + const void * listener; + } group; + + /// @brief Activation method. + void (*activate)(GAction *action, GVariant *parameter, GtkWidget *terminal); + + } V3270SimpleAction; + + typedef struct _V3270SimpleActionClass { + + V3270ActionClass parent_class; + + } V3270SimpleActionClass; + + GType V3270SimpleAction_get_type(void) G_GNUC_CONST; + + /// @brief Create an empty simple action. + V3270SimpleAction * v3270_simple_action_new(); + + /// @brief Create a dialog action. + V3270SimpleAction * v3270_dialog_action_new(GtkWidget * (*factory)(V3270SimpleAction *, GtkWidget *)); G_END_DECLS diff --git a/src/terminal/actions/action.c b/src/terminal/actions/action.c index 79eda1d..72e6030 100644 --- a/src/terminal/actions/action.c +++ b/src/terminal/actions/action.c @@ -43,6 +43,10 @@ static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); + static const gchar * get_icon_name(GAction *action); + static const gchar * get_label(GAction *action); + static const gchar * get_tooltip(GAction *action); + static void change_widget(GAction *action, GtkWidget *from, GtkWidget *to); static void finalize(GObject *object); @@ -86,6 +90,10 @@ klass->get_state = get_state; klass->translate = translate; + klass->get_icon_name = get_icon_name; + klass->get_label = get_label; + klass->get_tooltip = get_tooltip; + klass->type.state = NULL; klass->type.parameter = NULL; @@ -321,38 +329,10 @@ g_message("Action %s can't be activated",g_action_get_name(action)); } - const gchar * v3270_action_get_icon_name(GAction *action) { - return V3270_ACTION_GET_DESCRIPTOR(action)->icon; - } - const gchar * v3270_action_translate(GAction *action, const gchar *text) { return V3270_ACTION_GET_CLASS(action)->translate(action,text); } - const gchar * v3270_action_get_label(GAction *action) { - const gchar * label = V3270_ACTION_GET_DESCRIPTOR(action)->label; - - debug("%s(%s): [%s] [%s]",__FUNCTION__,g_action_get_name(action),label,v3270_action_translate(action,label)); - - if(label && *label) - return v3270_action_translate(action,label); - - return NULL; - } - - const gchar * v3270_action_get_tooltip(GAction *action) { - - const gchar * tooltip = V3270_ACTION_GET_DESCRIPTOR(action)->description; - - if(!tooltip) - tooltip = V3270_ACTION_GET_DESCRIPTOR(action)->summary; - - if(tooltip) - return v3270_action_translate(action,tooltip); - - return NULL; - } - // // Action methods. // @@ -488,3 +468,44 @@ } + const gchar * get_icon_name(GAction *action) { + return V3270_ACTION_GET_DESCRIPTOR(action)->icon; + } + + const gchar * get_label(GAction *action) { + const gchar * label = V3270_ACTION_GET_DESCRIPTOR(action)->label; + + debug("%s(%s): [%s] [%s]",__FUNCTION__,g_action_get_name(action),label,v3270_action_translate(action,label)); + + if(label && *label) + return v3270_action_translate(action,label); + + return NULL; + } + + const gchar * get_tooltip(GAction *action) { + + const gchar * tooltip = V3270_ACTION_GET_DESCRIPTOR(action)->description; + + if(!tooltip) + tooltip = V3270_ACTION_GET_DESCRIPTOR(action)->summary; + + if(tooltip) + return v3270_action_translate(action,tooltip); + + return NULL; + + } + + const gchar * v3270_action_get_icon_name(GAction *action) { + return V3270_ACTION_GET_CLASS(action)->get_icon_name(action); + } + + const gchar * v3270_action_get_label(GAction *action) { + return V3270_ACTION_GET_CLASS(action)->get_label(action); + } + + const gchar * v3270_action_get_tooltip(GAction *action) { + return V3270_ACTION_GET_CLASS(action)->get_tooltip(action); + } + diff --git a/src/terminal/actions/dialog.c b/src/terminal/actions/dialog.c new file mode 100644 index 0000000..476a602 --- /dev/null +++ b/src/terminal/actions/dialog.c @@ -0,0 +1,133 @@ +/* + * "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 Implements V3270 Dialog Action. + * + */ + + #include "private.h" + #include + #include + #include + + #define V3270_TYPE_DIALOG_ACTION (V3270DialogAction_get_type()) + #define V3270_DIALOG_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), V3270_TYPE_DIALOG_ACTION, V3270DialogAction)) + #define V3270_DIALOG_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), V3270_TYPE_DIALOG_ACTION, V3270DialogActionClass)) + #define V3270_IS_DIALOG_ACTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), V3270_TYPE_DIALOG_ACTION)) + #define V3270_IS_DIALOG_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), V3270_TYPE_DIALOG_ACTION)) + #define V3270_DIALOG_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), V3270_TYPE_DIALOG_ACTION, V3270DialogActionClass)) + + typedef struct _V3270DialogAction { + + V3270SimpleAction parent; + + GtkWidget * dialog; + GtkWidget * (*factory)(V3270SimpleAction *, GtkWidget *); + + } V3270DialogAction; + + typedef struct _V3270DialogActionClass { + + V3270SimpleActionClass parent_class; + + } V3270DialogActionClass; + + + static void V3270DialogAction_class_init(V3270DialogActionClass *klass); + static void V3270DialogAction_init(V3270DialogAction *action); + static void activate(GAction G_GNUC_UNUSED(*action), GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal); + + G_DEFINE_TYPE(V3270DialogAction, V3270DialogAction, V3270_TYPE_SIMPLE_ACTION); + + static gboolean get_enabled(GAction *action, GtkWidget *terminal) { + + if((V3270_DIALOG_ACTION(action)->dialog)) { + return FALSE; + } + + return V3270_ACTION_CLASS(V3270DialogAction_parent_class)->get_enabled(action,terminal); + + } + + static void V3270DialogAction_class_init(V3270DialogActionClass *klass) { + klass->parent_class.parent_class.get_enabled = get_enabled; + } + + static void V3270DialogAction_init(V3270DialogAction *action) { + + action->dialog = NULL; + action->parent.parent.activate = activate; + + } + + V3270SimpleAction * v3270_dialog_action_new(GtkWidget * (*factory)(V3270SimpleAction *, GtkWidget *)) { + + V3270DialogAction * action = (V3270DialogAction *) g_object_new(V3270_TYPE_DIALOG_ACTION, NULL); + action->factory = factory; + return V3270_SIMPLE_ACTION(action); + + } + + static void on_destroy(GtkWidget *dialog, V3270DialogAction *action) { + + if(action->dialog == dialog) { + action->dialog = NULL; + v3270_action_notify_enabled(G_ACTION(action)); + } + } + + void activate(GAction *object, GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) { + + if(!GTK_IS_V3270(terminal)) + return; + + V3270DialogAction * action = V3270_DIALOG_ACTION(object); + + if(!action->factory) { + g_warning("Action %s is invalid (no factory method)",g_action_get_name(G_ACTION(action))); + return; + } + + if(action->dialog) + return; + + action->dialog = action->factory((V3270SimpleAction *) object, terminal); + v3270_action_notify_enabled(G_ACTION(action)); + + if(action->dialog) { + + g_signal_connect(action->dialog,"destroy",G_CALLBACK(on_destroy),action); + g_signal_connect(action->dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); + gtk_widget_show(GTK_WIDGET(action->dialog)); + + } + + } + diff --git a/src/terminal/actions/simple.c b/src/terminal/actions/simple.c new file mode 100644 index 0000000..e240b4b --- /dev/null +++ b/src/terminal/actions/simple.c @@ -0,0 +1,98 @@ +/* + * "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 V3270 Simple Action. + * + */ + + #include "private.h" + #include + #include + + static void V3270SimpleAction_class_init(V3270SimpleActionClass *klass); + static void V3270SimpleAction_init(V3270SimpleAction *action); + + G_DEFINE_TYPE(V3270SimpleAction, V3270SimpleAction, V3270_TYPE_ACTION); + + static void activate(GAction *action, GVariant G_GNUC_UNUSED(*parameter), GtkWidget G_GNUC_UNUSED(*terminal)) { + g_warning("Action %s activation method is invalid",g_action_get_name(action)); + } + + static const gchar * get_icon_name(GAction *action) { + return V3270_SIMPLE_ACTION(action)->icon_name; + } + + static const gchar * get_label(GAction *action) { + return V3270_SIMPLE_ACTION(action)->label; + } + + static const gchar * get_tooltip(GAction *action) { + return V3270_SIMPLE_ACTION(action)->tooltip; + } + + static void dispose(GObject *object) { + + V3270SimpleAction *action = V3270_SIMPLE_ACTION(object); + + if(action->group.listener) { + lib3270_unregister_action_group_listener(v3270_action_get_session(G_ACTION(object)),action->group.id,action->group.listener); + action->group.listener = NULL; + } + + G_OBJECT_CLASS(V3270SimpleAction_parent_class)->dispose(object); + } + + static void V3270SimpleAction_class_init(V3270SimpleActionClass *klass) { + + klass->parent_class.get_icon_name = get_icon_name; + klass->parent_class.get_label = get_label; + klass->parent_class.get_tooltip = get_tooltip; + + G_OBJECT_CLASS(klass)->dispose = dispose; + + } + + static void V3270SimpleAction_init(V3270SimpleAction *action) { + + action->icon_name = NULL; + action->label = _( "No label" ); + action->tooltip = NULL; + action->activate = activate; + action->group.id = LIB3270_ACTION_GROUP_NONE; + action->group.listener = NULL; + + } + + V3270SimpleAction * v3270_simple_action_new() { + return (V3270SimpleAction *) g_object_new(V3270_TYPE_SIMPLE_ACTION, NULL); + } + + + diff --git a/v3270.cbp b/v3270.cbp index cb8ad44..e32da4f 100644 --- a/v3270.cbp +++ b/v3270.cbp @@ -233,6 +233,9 @@ + + @@ -252,6 +255,9 @@ + + -- libgit2 0.21.2