diff --git a/src/actions/abstract.c b/src/actions/abstract.c
index 1de5758..8da34cb 100644
--- a/src/actions/abstract.c
+++ b/src/actions/abstract.c
@@ -34,11 +34,15 @@
static void pw3270Action_init(pw3270Action *action);
static void pw3270_action_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
static void pw3270_action_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
+ static void pw3270_action_set_state(GAction *action, GVariant *value);
+
+ static void finalize(GObject *object);
static const GVariantType * pw3270_action_get_state_type(GAction *action);
static GVariant * pw3270_action_get_state_property(GAction *action);
- static GVariantType * pw3270_action_get_parameter_type(GAction *action);
-
+ static const GVariantType * pw3270_action_get_parameter_type(GAction *action);
+ static GVariant * pw3270_action_get_state_hint(GAction *action);
+ static void pw3270_action_change_state(GAction *action, GVariant *value);
enum {
PROP_NONE,
@@ -53,12 +57,12 @@
void pw3270_action_iface_init(GActionInterface *iface) {
iface->get_name = pw3270_action_get_name;
-// iface->get_parameter_type = pw3270_action_get_parameter_type;
+ iface->get_parameter_type = pw3270_action_get_parameter_type;
iface->get_state_type = pw3270_action_get_state_type;
-// iface->get_state_hint = pw3270_action_get_state_hint;
+ iface->get_state_hint = pw3270_action_get_state_hint;
iface->get_enabled = pw3270_action_get_enabled;
iface->get_state = pw3270_action_get_state_property;
-// iface->change_state = pw3270_action_change_state;
+ iface->change_state = pw3270_action_change_state;
iface->activate = pw3270_action_activate;
}
@@ -70,8 +74,9 @@
GObjectClass *object_class = G_OBJECT_CLASS(klass);
- object_class->set_property = pw3270_action_set_property;
- object_class->get_property = pw3270_action_get_property;
+ object_class->finalize = finalize;
+ object_class->set_property = pw3270_action_set_property;
+ object_class->get_property = pw3270_action_get_property;
klass->get_enabled = return_false;
@@ -124,15 +129,38 @@
void pw3270Action_init(pw3270Action *action) {
- action->name = "unnamed";
+ action->name = NULL;
action->window = NULL;
+ action->state = NULL;
+
+ }
+
+ void finalize(GObject *object) {
+
+ pw3270Action * action = PW3270_ACTION(object);
+
+ if(action->name) {
+
+ debug("Finalizing action \"%s\"",action->name);
+ g_free(action->name);
+ action->name = NULL;
+
+ }
+
+ if(action->parameter_type)
+ g_variant_type_free(action->parameter_type);
+
+ G_OBJECT_CLASS(pw3270Action_parent_class)->finalize(object);
}
+
void pw3270_action_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) {
GAction *action = G_ACTION(object);
+ debug("%s(%d)",__FUNCTION__,prop_id);
+
switch (prop_id) {
case PROP_NAME:
g_value_set_string(value, pw3270_action_get_name(action));
@@ -161,22 +189,57 @@
}
void pw3270_action_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) {
+
+ debug("%s(%d)",__FUNCTION__,prop_id);
+
+ GAction *action = G_ACTION(object);
+
+ switch (prop_id)
+ {
+ case PROP_NAME:
+ pw3270_action_set_name(action, g_value_get_string(value));
+ break;
+
+ case PROP_PARAMETER_TYPE:
+// action->parameter_type = g_value_dup_boxed (value);
+ break;
+
+ case PROP_ENABLED:
+// action->enabled = g_value_get_boolean (value);
+ break;
+
+ case PROP_STATE:
+ pw3270_action_set_state(action, g_value_get_variant(value));
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+
}
const gchar * pw3270_action_get_name(GAction *action) {
return PW3270_ACTION(action)->name;
}
- const GVariantType * pw3270_action_get_state_type(GAction *action) {
- return NULL;
- }
+ void pw3270_action_set_name(GAction *object, const gchar *name) {
+
+ pw3270Action * action = PW3270_ACTION(object);
+
+ debug("%s %s -> %s", __FUNCTION__, action->name, name);
+
+ if(action->name)
+ g_free(action->name);
+
+ if(name)
+ action->name = g_strdup(name);
+ else
+ action->name = NULL;
- GVariant * pw3270_action_get_state_property(GAction *action) {
- return g_variant_new_int16(0);
}
- GVariantType * pw3270_action_get_parameter_type(GAction *action) {
- return NULL;
+ GVariant * pw3270_action_get_state_property(GAction *action) {
+ return PW3270_ACTION(action)->state;
}
gboolean pw3270_action_get_enabled(GAction *action) {
@@ -195,3 +258,33 @@
PW3270_ACTION_GET_CLASS(action)->activate(action,window);
}
+
+ const GVariantType * pw3270_action_get_parameter_type(GAction *action) {
+ debug("%s",__FUNCTION__);
+ return NULL;
+ }
+
+ const GVariantType * pw3270_action_get_state_type(GAction *object) {
+
+ pw3270Action * action = PW3270_ACTION(object);
+
+ if(action->state != NULL)
+ return g_variant_get_type(action->state);
+ else
+ return NULL;
+
+ }
+
+ GVariant * pw3270_action_get_state_hint(GAction *action) {
+ debug("%s",__FUNCTION__);
+ return NULL;
+ }
+
+ void pw3270_action_change_state(GAction *action, GVariant *value) {
+ debug("%s",__FUNCTION__);
+ pw3270_action_set_state (action, value);
+ }
+
+ void pw3270_action_set_state(GAction *action, GVariant *value) {
+ debug("%s",__FUNCTION__);
+ }
diff --git a/src/actions/actions.cbp b/src/actions/actions.cbp
index fa843cf..c130b56 100644
--- a/src/actions/actions.cbp
+++ b/src/actions/actions.cbp
@@ -50,6 +50,9 @@
+
+
+
diff --git a/src/actions/lib3270.c b/src/actions/lib3270.c
index 7d92316..c4f7289 100644
--- a/src/actions/lib3270.c
+++ b/src/actions/lib3270.c
@@ -47,15 +47,13 @@
typedef struct _Lib3270Action {
pw3270Action parent;
- const LIB3270_ACTION * definition;
-
+ const LIB3270_ACTION * definition;
} Lib3270Action;
static void Lib3270Action_class_init(Lib3270ActionClass *klass);
static void Lib3270Action_init(Lib3270Action *action);
-
G_DEFINE_TYPE(Lib3270Action, Lib3270Action, PW3270_TYPE_ACTION);
static gboolean action_enabled(GAction *action, GtkWidget *window) {
@@ -84,23 +82,23 @@
action->get_enabled = action_enabled;
action->activate = action_activate;
-
}
void Lib3270Action_init(Lib3270Action *action) {
}
- GAction * pw3270_action_get_from_lib3270(const LIB3270_ACTION * definition) {
+ GAction * pw3270_action_new_from_lib3270(const LIB3270_ACTION * definition, GtkWidget *window) {
- Lib3270Action * action = (Lib3270Action *) g_object_new(PW3270_TYPE_LIB3270_ACTION, NULL);
- action->definition = definition;
+ Lib3270Action * action = (Lib3270Action *) g_object_new(PW3270_TYPE_LIB3270_ACTION, NULL);
+ pw3270Action * abstract = PW3270_ACTION(action);
- {
- pw3270Action * abstract = PW3270_ACTION(action);
+ action->definition = definition;
+ abstract->window = window;
- abstract->name = definition->name;
+ if(abstract->name)
+ g_free(abstract->name);
- }
+ abstract->name = g_strconcat("win.",definition->name,NULL);
return G_ACTION(action);
}
diff --git a/src/actions/private.h b/src/actions/private.h
index a8af5fb..a5ec49e 100644
--- a/src/actions/private.h
+++ b/src/actions/private.h
@@ -47,8 +47,10 @@
struct _pw3270Action {
GObject parent;
- GtkWidget * window;
- const gchar * name;
+ GVariantType * parameter_type;
+ GVariant * state;
+ GtkWidget * window;
+ gchar * name;
};
diff --git a/src/actions/testprogram/testprogram.c b/src/actions/testprogram/testprogram.c
index b420a7f..20775e4 100644
--- a/src/actions/testprogram/testprogram.c
+++ b/src/actions/testprogram/testprogram.c
@@ -29,10 +29,10 @@
*/
#include
- #include
- #include
- #include
+ #include
+ #include
#include
+ #include
/*---[ Implement ]----------------------------------------------------------------------------------*/
@@ -44,17 +44,60 @@
return NULL;
}
- int main (int argc, char **argv) {
+ static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) {
- GAction * action = pw3270_action_get_from_lib3270(lib3270_action_get_by_name("testpattern"));
+ GtkWidget * window = gtk_application_window_new(app);
+ GtkWidget * terminal = v3270_new();
+ GtkWidget * vBox = gtk_box_new(GTK_ORIENTATION_VERTICAL,2);
+ GtkWidget * notebook = gtk_notebook_new();
+ GtkWidget * toolbar = gtk_toolbar_new();
- g_message("Action name is \"%s\"",g_action_get_name(action));
- g_message("Action is %s",g_action_get_enabled(action) ? "enabled" : "disabled");
+ pw3270_window_add_actions(window);
- g_object_unref(action);
- return 0;
+ gtk_box_pack_start(GTK_BOX(vBox),toolbar,FALSE,TRUE,0);
+ gtk_box_pack_start(GTK_BOX(vBox),notebook,TRUE,TRUE,0);
- }
+ // Create Terminal window
+ {
+ gtk_widget_set_can_default(terminal,TRUE);
+
+ gtk_notebook_append_page(GTK_NOTEBOOK(notebook),terminal,gtk_label_new("Terminal"));
+
+#ifdef _WIN32
+ v3270_set_font_family(terminal,"Droid Sans Mono");
+#endif // _WIN32
+
+ }
+
+ // Create trace window
+ gtk_notebook_append_page(GTK_NOTEBOOK(notebook),v3270_trace_new(terminal),gtk_label_new("Trace"));
+
+ // Setup and show main window
+ gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
+ gtk_window_set_default_size (GTK_WINDOW (window), 800, 500);
+ gtk_container_add(GTK_CONTAINER(window),vBox);
+ gtk_widget_show_all(window);
+
+ gtk_widget_grab_focus(terminal);
+
+}
+
+int main (int argc, char **argv) {
+
+ GtkApplication *app;
+ int status;
+
+ app = gtk_application_new ("br.com.bb.pw3270",G_APPLICATION_FLAGS_NONE);
+
+ g_signal_connect (app, "activate", G_CALLBACK(activate), NULL);
+
+ status = g_application_run (G_APPLICATION (app), argc, argv);
+ g_object_unref (app);
+
+ g_message("rc=%d",status);
+
+ return 0;
+}
diff --git a/src/actions/window.c b/src/actions/window.c
new file mode 100644
index 0000000..3c9578e
--- /dev/null
+++ b/src/actions/window.c
@@ -0,0 +1,69 @@
+/*
+ * "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 Integrate pw3270 actions with the application window.
+ *
+ */
+
+ #include "private.h"
+ #include
+
+ void pw3270_window_add_actions(GtkWidget * appwindow) {
+
+ GActionMap *map = G_ACTION_MAP(appwindow);
+
+ // g_action_map_add_action(map,pw3270_action_new_from_lib3270(lib3270_action_get_by_name("testpattern"), appwindow));
+
+ GAction *action = pw3270_action_new_from_lib3270(lib3270_action_get_by_name("testpattern"), appwindow);
+
+ debug("--> \"%s\"",pw3270_action_get_name(action));
+
+ g_action_map_add_action(map,action);
+
+ debug("--> \"%s\"",pw3270_action_get_name(action));
+
+ /*
+ size_t ix;
+
+ // Map lib3270 actions
+ const LIB3270_ACTION * actions = lib3270_get_actions();
+
+ for(ix = 0; actions[ix].name; ix++) {
+
+ // g_autofree gchar * name = g_strconcat("win.", actions[ix].name, NULL);
+ debug("Creating action %s", actions[ix].name);
+ g_action_map_add_action(map,pw3270_action_new_from_lib3270(&actions[ix],appwindow));
+
+ }
+ */
+
+
+ debug("%s ends",__FUNCTION__);
+ }
diff --git a/src/include/pw3270/actions.h b/src/include/pw3270/actions.h
index cd425ea..2a87de3 100644
--- a/src/include/pw3270/actions.h
+++ b/src/include/pw3270/actions.h
@@ -54,11 +54,17 @@
GType pw3270Action_get_type(void) G_GNUC_CONST;
- GAction * pw3270_action_get_from_lib3270(const LIB3270_ACTION * definition);
+ GAction * pw3270_action_new_from_lib3270(const LIB3270_ACTION * definition, GtkWidget *window);
+
const gchar * pw3270_action_get_name(GAction *action);
+ void pw3270_action_set_name(GAction *action, const gchar *name);
+
gboolean pw3270_action_get_enabled(GAction *action);
void pw3270_action_activate(GAction *action, GVariant *parameter);
+ /// @brief Add lib3270 actions to an application window.
+ void pw3270_window_add_actions(GtkWidget * appwindow);
+
G_END_DECLS
#endif // PW3270_ACTIONS_H_INCLUDED
--
libgit2 0.21.2