diff --git a/src/include/internals.h b/src/include/internals.h index a0fd878..95c2cfe 100644 --- a/src/include/internals.h +++ b/src/include/internals.h @@ -37,6 +37,7 @@ #define GETTEXT_PACKAGE PACKAGE_NAME #include + #include #include #include #include @@ -133,6 +134,7 @@ G_GNUC_INTERNAL gboolean v3270_draw(GtkWidget * widget, cairo_t * cr); G_GNUC_INTERNAL void v3270_cursor_draw(v3270 *widget); + G_GNUC_INTERNAL void v3270_set_cursor(GtkWidget *widget, LIB3270_POINTER id); G_GNUC_INTERNAL void v3270_draw_oia(v3270 *terminal, cairo_t *cr, int row, int cols); G_GNUC_INTERNAL void v3270_update_mouse_pointer(GtkWidget *widget); diff --git a/src/terminal/callbacks.c b/src/terminal/callbacks.c index 0622d65..95ab36c 100644 --- a/src/terminal/callbacks.c +++ b/src/terminal/callbacks.c @@ -71,7 +71,8 @@ static void set_timer(H3270 *session, unsigned char on) static void update_toggle(H3270 *session, LIB3270_TOGGLE ix, unsigned char value, G_GNUC_UNUSED LIB3270_TOGGLE_TYPE reason, const char *name) { - GtkWidget *widget = GTK_WIDGET(lib3270_get_user_data(session)); + GtkWidget * widget = GTK_WIDGET(lib3270_get_user_data(session)); + v3270Class * klass = GTK_V3270_GET_CLASS(widget); trace("%s(%s,%d)",__FUNCTION__,name,(int) value); @@ -133,7 +134,7 @@ static void update_toggle(H3270 *session, LIB3270_TOGGLE ix, unsigned char value } - g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties.toggle[ix]); + g_object_notify_by_pspec(G_OBJECT(widget), klass->properties.toggle[ix]); g_signal_emit(widget, v3270_widget_signal[V3270_SIGNAL_TOGGLE_CHANGED], 0, (guint) ix, (gboolean) (value != 0), (gchar *) name); } @@ -226,8 +227,7 @@ static void update_connect(H3270 *session, unsigned char connected) g_signal_emit(GTK_WIDGET(widget), v3270_widget_signal[V3270_SIGNAL_DISCONNECTED], 0); } - if(v3270_properties.online) - g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties.online); + g_object_notify_by_pspec(G_OBJECT(widget), GTK_V3270_GET_CLASS(widget)->properties.online); widget->activity.timestamp = time(0); @@ -236,16 +236,16 @@ static void update_connect(H3270 *session, unsigned char connected) static void update_screen_size(H3270 *session, G_GNUC_UNUSED unsigned short rows, G_GNUC_UNUSED unsigned short cols) { - v3270_reload(GTK_WIDGET(lib3270_get_user_data(session))); - gtk_widget_queue_draw(GTK_WIDGET(lib3270_get_user_data(session))); + GtkWidget * widget = GTK_WIDGET(lib3270_get_user_data(session)); + v3270_reload(widget); + gtk_widget_queue_draw(widget); } static void update_model(H3270 *session, const char *name, int model, G_GNUC_UNUSED int rows, G_GNUC_UNUSED int cols) { - if(v3270_properties.model) - g_object_notify_by_pspec(G_OBJECT(lib3270_get_user_data(session)), v3270_properties.model); - - g_signal_emit(GTK_WIDGET(lib3270_get_user_data(session)),v3270_widget_signal[V3270_SIGNAL_MODEL_CHANGED], 0, (guint) model, name); + GtkWidget * widget = GTK_WIDGET(lib3270_get_user_data(session)); + g_object_notify_by_pspec(G_OBJECT(lib3270_get_user_data(session)), GTK_V3270_GET_CLASS(widget)->properties.model); + g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_MODEL_CHANGED], 0, (guint) model, name); } static void changed(H3270 *session, int offset, int len) @@ -299,9 +299,7 @@ static void set_selection(H3270 *session, unsigned char status) { GtkWidget * widget = GTK_WIDGET(lib3270_get_user_data(session)); - if(v3270_properties.selection) - g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties.selection); - + g_object_notify_by_pspec(G_OBJECT(widget), GTK_V3270_GET_CLASS(widget)->properties.selection); g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_SELECTING], 0, status ? TRUE : FALSE); } diff --git a/src/terminal/mouse.c b/src/terminal/mouse.c index 5626c78..9ac7512 100644 --- a/src/terminal/mouse.c +++ b/src/terminal/mouse.c @@ -222,7 +222,7 @@ static void update_mouse_pointer(GtkWidget *widget, int baddr) if(baddr >= 0 && terminal->pointer_id == LIB3270_POINTER_UNLOCKED) { - gdk_window_set_cursor(gtk_widget_get_window(widget),v3270_cursor[lib3270_get_pointer(terminal->host,baddr)]); + v3270_set_cursor(widget,lib3270_get_pointer(terminal->host,baddr)); } } @@ -240,7 +240,7 @@ gboolean v3270_motion_notify_event(GtkWidget *widget, GdkEventMotion *event) if(!lib3270_connected(terminal->host)) { - gdk_window_set_cursor(gtk_widget_get_window(widget),v3270_cursor[LIB3270_POINTER_LOCKED]); + v3270_set_cursor(widget,LIB3270_POINTER_LOCKED); return FALSE; } @@ -292,7 +292,7 @@ gboolean v3270_motion_notify_event(GtkWidget *widget, GdkEventMotion *event) } } - gdk_window_set_cursor(gtk_widget_get_window(widget),v3270_cursor[id]); + v3270_set_cursor(widget,id); } return FALSE; diff --git a/src/terminal/oia.c b/src/terminal/oia.c index bdb6485..51e7db5 100644 --- a/src/terminal/oia.c +++ b/src/terminal/oia.c @@ -721,7 +721,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); } - g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties.luname); + g_object_notify_by_pspec(G_OBJECT(widget), GTK_V3270_GET_CLASS(widget)->properties.luname); } diff --git a/src/terminal/private.h b/src/terminal/private.h index ba9947e..ca98e76 100644 --- a/src/terminal/private.h +++ b/src/terminal/private.h @@ -28,15 +28,8 @@ */ #include - #include -#include -#include - -#include -#include - G_BEGIN_DECLS struct _v3270Class @@ -45,12 +38,31 @@ G_BEGIN_DECLS // Internal properties. struct { + size_t count; // Number of properties. GParamSpec * font_family; + GParamSpec * toggle[LIB3270_TOGGLE_COUNT]; // Toggle properties. + + // Signal related properties + GParamSpec * online; + GParamSpec * luname; + GParamSpec * model; + GParamSpec * selection; + + struct + { + guint toggle; + guint boolean; + guint integer; + guint str; + } type; } properties; + // Cursors + GdkCursor * cursors[LIB3270_POINTER_COUNT]; + // Signals void (*activate)(GtkWidget *widget); void (*toggle_changed)(v3270 *widget,LIB3270_TOGGLE toggle_id,gboolean toggle_state,const gchar *toggle_name); @@ -168,31 +180,4 @@ G_BEGIN_DECLS /*--[ Globals ]--------------------------------------------------------------------------------------*/ - G_GNUC_INTERNAL GdkCursor * v3270_cursor[LIB3270_POINTER_COUNT]; - - G_GNUC_INTERNAL struct _v3270_properties - { - GParamSpec * toggle[LIB3270_TOGGLE_COUNT]; // Toggle properties. - - struct - { - guint toggle; - guint boolean; - guint integer; - guint str; - } type; - - /* - // V3270 Internal properties. - GParamSpec * font_family; - */ - - // Properties who launch signals. - GParamSpec * online; - GParamSpec * luname; - GParamSpec * model; - GParamSpec * selection; - - } v3270_properties; - G_END_DECLS diff --git a/src/terminal/properties.c b/src/terminal/properties.c index 194f346..4fc4fc6 100644 --- a/src/terminal/properties.c +++ b/src/terminal/properties.c @@ -51,41 +51,42 @@ static void v3270_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - v3270 *window = GTK_V3270(object); + v3270 * window = GTK_V3270(object); + v3270Class * klass = GTK_V3270_GET_CLASS(object); debug("%s(%u,%s)",__FUNCTION__,prop_id,g_param_spec_get_name(pspec)); - if(prop_id >= v3270_properties.type.str) + if(prop_id >= klass->properties.type.str) { - const LIB3270_STRING_PROPERTY * prop = (lib3270_get_string_properties_list()+(prop_id - v3270_properties.type.str)); + const LIB3270_STRING_PROPERTY * prop = (lib3270_get_string_properties_list()+(prop_id - klass->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) + else if(prop_id >= klass->properties.type.integer) { - const LIB3270_INT_PROPERTY * prop = (lib3270_get_int_properties_list()+(prop_id - v3270_properties.type.integer)); + const LIB3270_INT_PROPERTY * prop = (lib3270_get_int_properties_list()+(prop_id - klass->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) + else if(prop_id >= klass->properties.type.boolean) { - const LIB3270_INT_PROPERTY * prop = (lib3270_get_boolean_properties_list()+(prop_id - v3270_properties.type.boolean)); + const LIB3270_INT_PROPERTY * prop = (lib3270_get_boolean_properties_list()+(prop_id - klass->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) + else if(prop_id >= klass->properties.type.toggle) { debug("%s.%s",__FUNCTION__,"toggle"); - lib3270_set_toggle(window->host,prop_id - v3270_properties.type.toggle, (int) g_value_get_boolean (value)); + lib3270_set_toggle(window->host,prop_id - klass->properties.type.toggle, (int) g_value_get_boolean (value)); } @@ -104,41 +105,42 @@ static void v3270_get_property(GObject *object,guint prop_id, GValue *value, GParamSpec *pspec) { - v3270 *window = GTK_V3270(object); + v3270 * window = GTK_V3270(object); + v3270Class * klass = GTK_V3270_GET_CLASS(object); debug("%s(%u,%s)",__FUNCTION__,prop_id,g_param_spec_get_name(pspec)); - if(prop_id >= v3270_properties.type.str) + if(prop_id >= klass->properties.type.str) { - const LIB3270_STRING_PROPERTY * prop = (lib3270_get_string_properties_list()+(prop_id - v3270_properties.type.str)); + const LIB3270_STRING_PROPERTY * prop = (lib3270_get_string_properties_list()+(prop_id - klass->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) + else if(prop_id >= klass->properties.type.integer) { - const LIB3270_INT_PROPERTY * prop = (lib3270_get_int_properties_list()+(prop_id - v3270_properties.type.integer)); + const LIB3270_INT_PROPERTY * prop = (lib3270_get_int_properties_list()+(prop_id - klass->properties.type.integer)); debug("%s.%s.%s",__FUNCTION__,"integer",prop->name); if(prop->get) g_value_set_int(value,prop->get(window->host)); } - else if(prop_id >= v3270_properties.type.boolean) + else if(prop_id >= klass->properties.type.boolean) { - const LIB3270_INT_PROPERTY * prop = (lib3270_get_boolean_properties_list()+(prop_id - v3270_properties.type.boolean)); + const LIB3270_INT_PROPERTY * prop = (lib3270_get_boolean_properties_list()+(prop_id - klass->properties.type.boolean)); debug("%s.%s.%s",__FUNCTION__,"boolean",prop->name); if(prop->get) g_value_set_boolean(value,prop->get(window->host) != 0 ? TRUE : FALSE); } - else if(prop_id >= v3270_properties.type.toggle) + else if(prop_id >= klass->properties.type.toggle) { - debug("%s.%s.%s",__FUNCTION__,"toggle",lib3270_get_toggle_name(prop_id - v3270_properties.type.toggle)); - g_value_set_boolean(value,lib3270_get_toggle(window->host,prop_id - v3270_properties.type.toggle) ? TRUE : FALSE ); + debug("%s.%s.%s",__FUNCTION__,"toggle",lib3270_get_toggle_name(prop_id - klass->properties.type.toggle)); + g_value_set_boolean(value,lib3270_get_toggle(window->host,prop_id - klass->properties.type.toggle) ? TRUE : FALSE ); } @@ -159,15 +161,17 @@ void v3270_install_property(GObjectClass *oclass, guint property_id, GParamSpec *pspec) { - static const struct + v3270Class * klass = GTK_V3270_CLASS(oclass); + + const struct { const char *name; GParamSpec **prop; } properties[] = { - { "connected", &v3270_properties.online }, - { "luname", &v3270_properties.luname }, - { "model", &v3270_properties.model }, - { "has-selection", &v3270_properties.selection }, + { "connected", &klass->properties.online }, + { "luname", &klass->properties.luname }, + { "model", &klass->properties.model }, + { "has-selection", &klass->properties.selection }, }; size_t ix; @@ -195,7 +199,6 @@ debug("%s",__FUNCTION__); - memset(&v3270_properties,0,sizeof(v3270_properties)); gobject_class->set_property = v3270_set_property; gobject_class->get_property = v3270_get_property; @@ -221,12 +224,12 @@ // // Extract toggle class. - v3270_properties.type.toggle = klass->properties.count; + klass->properties.type.toggle = klass->properties.count; 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)); + debug("Property %u=%s (Toggle)",(unsigned int) klass->properties.type.toggle + ix, lib3270_get_toggle_name(ix)); - v3270_properties.toggle[ix] = + klass->properties.toggle[ix] = g_param_spec_boolean( lib3270_get_toggle_name(ix), lib3270_get_toggle_name(ix), @@ -235,17 +238,17 @@ G_PARAM_WRITABLE|G_PARAM_READABLE ); - v3270_install_property(gobject_class, klass->properties.count++, v3270_properties.toggle[ix]); + v3270_install_property(gobject_class, klass->properties.count++, klass->properties.toggle[ix]); } // Creating boolean properties. - v3270_properties.type.boolean = klass->properties.count; + klass->properties.type.boolean = klass->properties.count; const LIB3270_INT_PROPERTY * bool_props = lib3270_get_boolean_properties_list(); for(ix = 0; bool_props[ix].name; ix++) { - debug("Property %u=%s (Boolean)",(unsigned int) v3270_properties.type.boolean + ix, bool_props[ix].name); + debug("Property %u=%s (Boolean)",(unsigned int) klass->properties.type.boolean + ix, bool_props[ix].name); spec = g_param_spec_boolean( bool_props[ix].name, bool_props[ix].name, @@ -260,11 +263,11 @@ // Creating integer properties. const LIB3270_INT_PROPERTY * int_props = lib3270_get_int_properties_list(); - v3270_properties.type.integer = klass->properties.count; + klass->properties.type.integer = klass->properties.count; for(ix = 0; int_props[ix].name; ix++) { - debug("Property %u=%s (Integer)",(unsigned int) v3270_properties.type.integer + ix, int_props[ix].name); + debug("Property %u=%s (Integer)",(unsigned int) klass->properties.type.integer + ix, int_props[ix].name); spec = g_param_spec_int( int_props[ix].name, @@ -287,12 +290,12 @@ // Creating string properties. const LIB3270_STRING_PROPERTY * str_props = lib3270_get_string_properties_list(); - v3270_properties.type.str = klass->properties.count; + klass->properties.type.str = klass->properties.count; for(ix = 0; str_props[ix].name; ix++) { - debug("Property %u=%s (String)",(unsigned int) v3270_properties.type.str + ix, str_props[ix].name); + debug("Property %u=%s (String)",(unsigned int) klass->properties.type.str + ix, str_props[ix].name); spec = g_param_spec_string( str_props[ix].name, diff --git a/src/terminal/widget.c b/src/terminal/widget.c index b7d2615..b39d98d 100644 --- a/src/terminal/widget.c +++ b/src/terminal/widget.c @@ -64,7 +64,6 @@ /*--[ Globals ]--------------------------------------------------------------------------------------*/ guint v3270_widget_signal[V3270_SIGNAL_LAST] = { 0 }; - GdkCursor * v3270_cursor[LIB3270_POINTER_COUNT] = { 0 }; /*--[ Prototipes ]-----------------------------------------------------------------------------------*/ @@ -337,9 +336,9 @@ static void v3270_class_init(v3270Class *klass) for(f=0;fcursors[f] = gdk_cursor_new_from_name(gdk_display_get_default(),cr[f]); #else - v3270_cursor[f] = gdk_cursor_new_for_display(gdk_display_get_default(),cr[f]); + klass->cursors[f] = gdk_cursor_new_for_display(gdk_display_get_default(),cr[f]); #endif } } @@ -1041,3 +1040,11 @@ LIB3270_EXPORT GtkWidget * v3270_get_default_widget(void) return GTK_WIDGET(widget); } +void v3270_set_cursor(GtkWidget *widget, LIB3270_POINTER id) +{ + gdk_window_set_cursor( + gtk_widget_get_window(widget), + GTK_V3270_GET_CLASS(widget)->cursors[id % LIB3270_POINTER_COUNT] + ); +} + diff --git a/v3270.cbp b/v3270.cbp index 0495441..09c659f 100644 --- a/v3270.cbp +++ b/v3270.cbp @@ -172,6 +172,9 @@