diff --git a/src/testprogram/testprogram.c b/src/testprogram/testprogram.c index 3df27c6..86303a2 100644 --- a/src/testprogram/testprogram.c +++ b/src/testprogram/testprogram.c @@ -92,12 +92,21 @@ static void activate(GtkApplication* app, gpointer user_data) { GtkWidget * window = gtk_application_window_new(app); GtkWidget * terminal = v3270_new(); gchar * filename = NULL; + GValue val = G_VALUE_INIT; const gchar *url = getenv("LIB3270_DEFAULT_HOST"); if(url) { + /* v3270_set_url(terminal,url); v3270_connect(terminal); + */ + + g_value_init (&val, G_TYPE_STRING); + g_value_set_string(&val,url); + g_object_set_property(G_OBJECT(terminal), "url", &val); + g_value_unset(&val); + gchar * title = g_strdup_printf("%s - %s", v3270_get_session_name(terminal), url); gtk_window_set_title(GTK_WINDOW(window), title); g_free(title); @@ -106,6 +115,11 @@ static void activate(GtkApplication* app, gpointer user_data) { gtk_window_set_title(GTK_WINDOW(window), v3270_get_session_name(terminal)); } + g_value_init(&val, G_TYPE_STRING); + g_object_get_property(G_OBJECT(terminal),"url",&val); + g_message("URL=%s",g_value_get_string(&val)); + g_value_unset(&val); + g_signal_connect(terminal,"popup",G_CALLBACK(popup_menu),NULL); // Setup and show window diff --git a/src/v3270/oia.c b/src/v3270/oia.c index 259460d..03a2dd1 100644 --- a/src/v3270/oia.c +++ b/src/v3270/oia.c @@ -711,11 +711,7 @@ void v3270_update_luname(GtkWidget *widget,const gchar *name) v3270_queue_draw_area(GTK_WIDGET(terminal),rect->x,rect->y,rect->width,rect->height); } -#if GTK_CHECK_VERSION(2,26,0) - g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties[PROP_LUNAME]); -#else - g_object_notify(G_OBJECT(widget),"luname"); -#endif // GTK_CHECK_VERSION +// g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties[PROP_LUNAME]); } diff --git a/src/v3270/private.h b/src/v3270/private.h index 8392667..757ef06 100644 --- a/src/v3270/private.h +++ b/src/v3270/private.h @@ -201,15 +201,15 @@ G_BEGIN_DECLS /*--[ Properties ]-----------------------------------------------------------------------------------*/ + /* enum { PROP_0, - /* Construct */ + // Construct PROP_TYPE, - - /* Widget properties */ + // Widget properties PROP_ONLINE, PROP_SELECTION, PROP_MODEL, @@ -218,21 +218,37 @@ G_BEGIN_DECLS PROP_URL, PROP_SESSION_NAME, - /* Toggles - always the last one, the real values are PROP_TOGGLE+LIB3270_TOGGLE */ + // Toggles - always the last one, the real values are PROP_TOGGLE+LIB3270_TOGGLE PROP_TOGGLE }; #define PROP_LAST (PROP_TOGGLE+LIB3270_TOGGLE_COUNT) - + */ /*--[ Globals ]--------------------------------------------------------------------------------------*/ G_GNUC_INTERNAL guint v3270_widget_signal[LAST_SIGNAL]; G_GNUC_INTERNAL GdkCursor * v3270_cursor[LIB3270_POINTER_COUNT]; - G_GNUC_INTERNAL GParamSpec * v3270_properties[PROP_LAST]; +// G_GNUC_INTERNAL GParamSpec * v3270_properties[PROP_LAST]; G_GNUC_INTERNAL const gchar * v3270_default_colors; G_GNUC_INTERNAL const gchar * v3270_default_font; + G_GNUC_INTERNAL struct _v3270_properties + { + size_t count; // Number of properties. + GParamSpec **toggle; // Toggle properties. + + struct + { + guint toggle; + guint boolean; + guint integer; + guint str; + } type; + + } v3270_properties; + + /*--[ Prototipes ]-----------------------------------------------------------------------------------*/ const GtkWidgetClass * v3270_get_parent_class(void); diff --git a/src/v3270/properties.c b/src/v3270/properties.c index 388252e..d36f23e 100644 --- a/src/v3270/properties.c +++ b/src/v3270/properties.c @@ -34,28 +34,74 @@ #endif // WIN32 #include + #include #include #include #include #include - #include + #include #include #include #include #include "private.h" + #define PROP_BEGIN 2 + /*--[ Globals ]--------------------------------------------------------------------------------------*/ - GParamSpec * v3270_properties[PROP_LAST] = { 0 }; +// GParamSpec * v3270_properties[PROP_LAST] = { 0 }; /*--[ Implement ]------------------------------------------------------------------------------------*/ static void v3270_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - debug("%s(%u)",__FUNCTION__,prop_id); - v3270 *window = GTK_V3270(object); + debug("%s(%u,%s)",__FUNCTION__,prop_id,g_param_spec_get_name(pspec)); + + if(prop_id < v3270_properties.type.toggle) + { + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } + else if(prop_id >= v3270_properties.type.str) + { + const LIB3270_STRING_PROPERTY * prop = (lib3270_get_string_properties_list()+(prop_id - v3270_properties.type.str)); + debug("%s.%s.%s=%s",__FUNCTION__,"string",prop->name,g_value_get_string(value)); + + if(prop->set) + prop->set(window->host,g_value_get_string(value)); + + } + else if(prop_id >= v3270_properties.type.integer) + { + const LIB3270_INT_PROPERTY * prop = (lib3270_get_int_properties_list()+(prop_id - v3270_properties.type.integer)); + debug("%s.%s.%s",__FUNCTION__,"integer",prop->name); + + if(prop->set) + prop->set(window->host,g_value_get_int(value)); + + } + else if(prop_id >= v3270_properties.type.boolean) + { + const LIB3270_INT_PROPERTY * prop = (lib3270_get_boolean_properties_list()+(prop_id - v3270_properties.type.boolean)); + debug("%s.%s.%s",__FUNCTION__,"boolean",prop->name); + + if(prop->set) + prop->set(window->host,g_value_get_boolean(value) ? 1 : 0); + + } + else if(prop_id >= v3270_properties.type.toggle) + { + debug("%s.%s",__FUNCTION__,"toggle"); + + } + else + { + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } + + /* + switch (prop_id) { case PROP_MODEL: @@ -82,13 +128,54 @@ } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } + */ } static void v3270_get_property(GObject *object,guint prop_id, GValue *value, GParamSpec *pspec) { - debug("%s(%u)",__FUNCTION__,prop_id); + v3270 *window = GTK_V3270(object); + + debug("%s(%u,%s)",__FUNCTION__,prop_id,g_param_spec_get_name(pspec)); + + if(prop_id < v3270_properties.type.toggle) + { + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } + else if(prop_id >= v3270_properties.type.str) + { + const LIB3270_STRING_PROPERTY * prop = (lib3270_get_string_properties_list()+(prop_id - v3270_properties.type.str)); + debug("%s.%s.%s",__FUNCTION__,"string",prop->name); + + if(prop->get) + g_value_set_string(value,prop->get(window->host)); + + } + else if(prop_id >= v3270_properties.type.integer) + { + const LIB3270_INT_PROPERTY * prop = (lib3270_get_int_properties_list()+(prop_id - v3270_properties.type.integer)); + debug("%s.%s.%s",__FUNCTION__,"integer",prop->name); + + + } + else if(prop_id >= v3270_properties.type.boolean) + { + const LIB3270_INT_PROPERTY * prop = (lib3270_get_boolean_properties_list()+(prop_id - v3270_properties.type.boolean)); + debug("%s.%s.%s",__FUNCTION__,"boolean",prop->name); + + } + else if(prop_id >= v3270_properties.type.toggle) + { + debug("%s.%s",__FUNCTION__,"toggle"); + + } + else + { + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } + + /* v3270 *window = GTK_V3270(object); switch (prop_id) @@ -129,17 +216,96 @@ } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } + */ } void v3270_init_properties(GObjectClass * gobject_class) { + size_t ix; + GParamSpec * spec; + debug("%s",__FUNCTION__); - memset(v3270_properties,0,sizeof(v3270_properties)); + memset(&v3270_properties,0,sizeof(v3270_properties)); + v3270_properties.count = LIB3270_TOGGLE_COUNT; + v3270_properties.type.toggle = PROP_BEGIN; gobject_class->set_property = v3270_set_property; gobject_class->get_property = v3270_get_property; + // Get property tables + const LIB3270_INT_PROPERTY * bool_props = lib3270_get_boolean_properties_list(); + const LIB3270_INT_PROPERTY * int_props = lib3270_get_int_properties_list(); + const LIB3270_STRING_PROPERTY * str_props = lib3270_get_string_properties_list(); + + v3270_properties.type.boolean = v3270_properties.count + PROP_BEGIN; + for(ix = 0; bool_props[ix].name; ix++) + { + v3270_properties.count++; + } + + v3270_properties.type.integer = v3270_properties.count + PROP_BEGIN; + for(ix = 0; int_props[ix].name; ix++) + { + v3270_properties.count++; + } + + v3270_properties.type.str = v3270_properties.count + PROP_BEGIN; + for(ix = 0; str_props[ix].name; ix++) + { + v3270_properties.count++; + } + + debug("Creating %u properties", (unsigned int) v3270_properties.count); + + // Creating toggle properties. + for(ix = 0; ix < LIB3270_TOGGLE_COUNT; ix++) + { + debug("Property %u=%s (Toggle)",(unsigned int) v3270_properties.type.toggle + ix, lib3270_get_toggle_name(ix)); + spec = g_param_spec_boolean(lib3270_get_toggle_name(ix),lib3270_get_toggle_name(ix),lib3270_get_toggle_description(ix),FALSE,G_PARAM_WRITABLE|G_PARAM_READABLE); + g_object_class_install_property(gobject_class, v3270_properties.type.toggle + ix, spec); + } + + + // Creating boolean properties. + for(ix = 0; bool_props[ix].name; ix++) + { + debug("Property %u=%s (Boolean)",(unsigned int) v3270_properties.type.boolean + ix, bool_props[ix].name); + spec = g_param_spec_boolean(bool_props[ix].name, bool_props[ix].name, bool_props[ix].description, FALSE,(bool_props[ix].set == NULL ? G_PARAM_READABLE : (G_PARAM_READABLE|G_PARAM_WRITABLE))); + g_object_class_install_property(gobject_class, v3270_properties.type.boolean + ix, spec); + + } + + // Creating integer properties. + for(ix = 0; int_props[ix].name; ix++) + { + debug("Property %u=%s (Integer)",(unsigned int) v3270_properties.type.integer + ix, int_props[ix].name); + + spec = g_param_spec_int( + int_props[ix].name, + int_props[ix].name, + int_props[ix].description, + 0, // Minimo + INT_MAX, // Máximo + 0, // Default + (int_props[ix].set == NULL ? G_PARAM_READABLE : (G_PARAM_READABLE|G_PARAM_WRITABLE)) + ); + + g_object_class_install_property(gobject_class, v3270_properties.type.integer + ix, spec); + + } + + // Creating string properties. + for(ix = 0; str_props[ix].name; ix++) + { + debug("Property %u=%s (String)",(unsigned int) v3270_properties.type.str + ix, str_props[ix].name); + spec = g_param_spec_string(str_props[ix].name, str_props[ix].name, str_props[ix].description, FALSE,(str_props[ix].set == NULL ? G_PARAM_READABLE : (G_PARAM_READABLE|G_PARAM_WRITABLE))); + g_object_class_install_property(gobject_class, v3270_properties.type.str + ix, spec); + + } + + + /* v3270_properties[PROP_ONLINE] = g_param_spec_boolean( "online", "online", @@ -206,6 +372,7 @@ g_object_class_install_property(gobject_class,PROP_TOGGLE+f,v3270_properties[PROP_TOGGLE+f]); } debug("%s",__FUNCTION__); + */ } void v3270_set_auto_disconnect(GtkWidget *widget, guint minutes) diff --git a/src/v3270/widget.c b/src/v3270/widget.c index 784b529..2b87e70 100644 --- a/src/v3270/widget.c +++ b/src/v3270/widget.c @@ -718,13 +718,10 @@ static void update_toggle(H3270 *session, LIB3270_TOGGLE ix, unsigned char value break; } -#if GTK_CHECK_VERSION(2,26,0) - g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties[PROP_TOGGLE+ix]); -#else - g_object_notify(G_OBJECT(widget),name); -#endif // GTK_CHECK_VERSION + g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties.toggle[ix]); g_signal_emit(widget, v3270_widget_signal[SIGNAL_TOGGLE_CHANGED], 0, (guint) ix, (gboolean) (value != 0), (gchar *) name); + } static void update_message(H3270 *session, LIB3270_MESSAGE id) @@ -785,11 +782,7 @@ static void update_connect(H3270 *session, unsigned char connected) g_signal_emit(GTK_WIDGET(widget), v3270_widget_signal[SIGNAL_DISCONNECTED], 0); } -#if GTK_CHECK_VERSION(2,26,0) - g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties[PROP_ONLINE]); -#else - g_object_notify(G_OBJECT(widget),"online"); -#endif // GTK_CHECK_VERSION + // g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties[PROP_ONLINE]); widget->activity.timestamp = time(0); @@ -804,11 +797,7 @@ static void update_screen_size(H3270 *session,unsigned short rows, unsigned shor static void update_model(H3270 *session, const char *name, int model, int rows, int cols) { -#if GTK_CHECK_VERSION(2,26,0) - g_object_notify_by_pspec(G_OBJECT(lib3270_get_user_data(session)), v3270_properties[PROP_MODEL]); -#else - g_object_notify(G_OBJECT(lib3270_get_user_data(session)),"model"); -#endif // GTK_CHECK_VERSION +// g_object_notify_by_pspec(G_OBJECT(lib3270_get_user_data(session)), v3270_properties[PROP_MODEL]); g_signal_emit(GTK_WIDGET(lib3270_get_user_data(session)),v3270_widget_signal[SIGNAL_MODEL_CHANGED], 0, (guint) model, name); } @@ -863,13 +852,9 @@ static void set_selection(H3270 *session, unsigned char status) { GtkWidget * widget = GTK_WIDGET(lib3270_get_user_data(session)); -#if GTK_CHECK_VERSION(2,26,0) - g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties[PROP_SELECTION]); -#else - g_object_notify(G_OBJECT(widget),"selection"); -#endif // GTK_CHECK_VERSION - +// g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties[PROP_SELECTION]); g_signal_emit(widget,v3270_widget_signal[SIGNAL_SELECTING], 0, status ? TRUE : FALSE); + } static void update_selection(H3270 *session, int start, int end) -- libgit2 0.21.2