diff --git a/src/terminal/font.c b/src/terminal/font.c index 2ce8fc6..fbf851a 100644 --- a/src/terminal/font.c +++ b/src/terminal/font.c @@ -34,7 +34,7 @@ #define VIEW_HEIGTH_FROM_FONT(font_height) (( ((unsigned int) font_height) * (rows+1)) + OIA_TOP_MARGIN + 2) - #define VIEW_WIDTH_FROM_FONT(max_x_advance) (((unsigned int) max_x_advance) * cols) + #define VIEW_WIDTH_FROM_FONT(max_x_advance) ( ((unsigned int) max_x_advance) * cols) /*--[ Globals ]--------------------------------------------------------------------------------------*/ @@ -68,19 +68,26 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, unsigned int width, cairo_font_extents_t extents; lib3270_get_screen_size(terminal->host,&rows,&cols); - debug("Screen_size: %ux%u Scalled=%s view_rows=%d view_cols=%d",rows,cols,terminal->font.scaled ? "Yes" : "No", (rows+OIA_TOP_MARGIN+3)); + + debug( + "Screen_size: %ux%u Scalled=%s view_rows=%d", + rows, + cols, + terminal->font.scaled ? "Yes" : "No", + (rows+OIA_TOP_MARGIN+3) + ); terminal->font.weight = lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL; cairo_select_font_face(cr,terminal->font.family, CAIRO_FONT_SLANT_NORMAL,terminal->font.weight); + /* if(terminal->font.scaled) { - /* - double w = ((double) width) / ((double)cols); - double h = ((double) height) / ((double) ((rows + OIA_TOP_MARGIN + 3))); - double s = (w < h) ? w : h; - */ + + // double w = ((double) width) / ((double)cols); + // double h = ((double) height) / ((double) ((rows + OIA_TOP_MARGIN + 3))); + // double s = (w < h) ? w : h; double s = 0.1; @@ -100,7 +107,7 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, unsigned int width, cairo_font_extents(cr,&extents); } - else + else */ { static const unsigned int font_size[] = { 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22, 24, 26, 28, 32, 36, 40, 48, 56, 64, 72 }; size_t f; @@ -118,12 +125,14 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, unsigned int width, terminal->minimum_height = ((rows+1) * (extents.height + extents.descent)) + (OIA_TOP_MARGIN+2); } - debug("font_size=%d y_advance=%u font_extents=%u+%u font_height=%u view_height=%u", + debug("font_size=%d x_advance=%lf y_advance=%lf font_extents=%u+%u font_height=%u view_height=%u view_width=%u", font_size[f], - (unsigned int) extents.max_y_advance, + extents.max_x_advance, + extents.max_y_advance, (unsigned int) extents.height, (unsigned int) extents.descent, VIEW_HEIGTH_FROM_FONT( (unsigned int) (extents.height + extents.descent) ), - height + height, + VIEW_WIDTH_FROM_FONT(extents.max_x_advance) ); if( VIEW_HEIGTH_FROM_FONT((extents.height + extents.descent)) < height && VIEW_WIDTH_FROM_FONT(extents.max_x_advance) < width) @@ -228,6 +237,7 @@ LIB3270_EXPORT void v3270_set_font_family(GtkWidget *widget, const gchar *name) terminal->font.weight = lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL; g_signal_emit(widget,v3270_widget_signal[SIGNAL_UPDATE_CONFIG], 0, "font-family", name); + g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties.font_family); v3270_reload(widget); gtk_widget_queue_draw(widget); diff --git a/src/terminal/private.h b/src/terminal/private.h index 197d742..e082065 100644 --- a/src/terminal/private.h +++ b/src/terminal/private.h @@ -246,6 +246,10 @@ G_BEGIN_DECLS guint str; } type; + // V3270 Internal properties. + GParamSpec * font_family; + + // Properties who launch signals. GParamSpec * online; GParamSpec * luname; GParamSpec * model; diff --git a/src/terminal/properties.c b/src/terminal/properties.c index 38729c0..d1f893f 100644 --- a/src/terminal/properties.c +++ b/src/terminal/properties.c @@ -88,10 +88,17 @@ lib3270_set_toggle(window->host,prop_id - v3270_properties.type.toggle, (int) g_value_get_boolean (value)); } - else - { + + // Check for internal properties. + switch(prop_id) { + case PROP_BEGIN: // Font-family + v3270_set_font_family(GTK_WIDGET(object), g_value_get_string(value)); + break; + + default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - } + + } } @@ -134,10 +141,19 @@ g_value_set_boolean(value,lib3270_get_toggle(window->host,prop_id - v3270_properties.type.toggle) ? TRUE : FALSE ); } - else - { + + // Check for internal properties. + switch(prop_id) { + case PROP_BEGIN: // Font-family + g_value_set_string(value,v3270_get_font_family(GTK_WIDGET(object))); + break; + + default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - } + + } + + } @@ -148,10 +164,10 @@ const char *name; GParamSpec **prop; } properties[] = { - { "connected", &v3270_properties.online }, - { "luname", &v3270_properties.luname }, - { "model", &v3270_properties.model }, - { "has-selection", &v3270_properties.selection } + { "connected", &v3270_properties.online }, + { "luname", &v3270_properties.luname }, + { "model", &v3270_properties.model }, + { "has-selection", &v3270_properties.selection }, }; size_t ix; @@ -179,59 +195,75 @@ debug("%s",__FUNCTION__); 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 = PROP_BEGIN; + + // Setup internal properties. + v3270_properties.font_family = g_param_spec_string( + "font_family", + "font_family", + _("Font family for terminal contents"), + FALSE, + G_PARAM_READABLE|G_PARAM_WRITABLE + ); + + g_object_class_install_property( + gobject_class, + v3270_properties.count++, + v3270_properties.font_family + ); + + // + // Extract properties from LIB3270 control tables + // + + // Extract toggle class. + v3270_properties.type.toggle = v3270_properties.count; + for(ix = 0; ix < LIB3270_TOGGLE_COUNT; ix++) { - v3270_properties.count++; - } + debug("Property %u=%s (Toggle)",(unsigned int) v3270_properties.type.toggle + ix, lib3270_get_toggle_name(ix)); + + v3270_properties.toggle[ix] = + 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 + ); - debug("Creating %u properties", (unsigned int) v3270_properties.count); + v3270_install_property(gobject_class, v3270_properties.count++, v3270_properties.toggle[ix]); - // 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)); - v3270_properties.toggle[ix] = 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); - v3270_install_property(gobject_class, v3270_properties.type.toggle + ix, v3270_properties.toggle[ix]); } - // Creating boolean properties. + v3270_properties.type.boolean = v3270_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); - 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))); - v3270_install_property(gobject_class, v3270_properties.type.boolean + ix, spec); + 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)) + ); + + v3270_install_property(gobject_class, v3270_properties.count++, spec); } // Creating integer properties. + const LIB3270_INT_PROPERTY * int_props = lib3270_get_int_properties_list(); + v3270_properties.type.integer = v3270_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) v3270_properties.type.integer + ix, int_props[ix].name); spec = g_param_spec_int( int_props[ix].name, @@ -242,17 +274,34 @@ 0, // Default (int_props[ix].set == NULL ? G_PARAM_READABLE : (G_PARAM_READABLE|G_PARAM_WRITABLE)) ); + debug("Creating %u properties", (unsigned int) v3270_properties.count); + + + + - v3270_install_property(gobject_class, v3270_properties.type.integer + ix, spec); + v3270_install_property(gobject_class, v3270_properties.count++, spec); } // Creating string properties. + const LIB3270_STRING_PROPERTY * str_props = lib3270_get_string_properties_list(); + v3270_properties.type.str = v3270_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); - 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))); - v3270_install_property(gobject_class, v3270_properties.type.str + ix, spec); + + 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)) + ); + + v3270_install_property(gobject_class, v3270_properties.count++, spec); } -- libgit2 0.21.2