Commit 3d54d8188320af74ce439a797271fddd9bc796f2

Authored by Perry Werneck
1 parent 9f9a7d93
Exists in master and in 1 other branch develop

Adding property for dynamic font space for compatibility with the previous

version.
src/dialogs/save/save.c
... ... @@ -432,7 +432,9 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_
432 432 }
433 433  
434 434 #pragma GCC diagnostic push
  435 +#ifdef _WIN32
435 436 #pragma GCC diagnostic ignored "-Wcast-function-type"
  437 +#endif // _WIN32
436 438  
437 439 if(dynamic)
438 440 g_list_free_full(dynamic,(GDestroyNotify) lib3270_free);
... ...
src/include/internals.h
... ... @@ -166,7 +166,10 @@
166 166 guint ascent;
167 167 guint descent;
168 168  
169   - guint spacing;
  169 + struct {
  170 + gboolean dynamic;
  171 + guint value;
  172 + } spacing;
170 173  
171 174 struct
172 175 {
... ...
src/include/terminal.h
... ... @@ -53,6 +53,7 @@ G_BEGIN_DECLS
53 53 GParamSpec * session_name;
54 54 GParamSpec * auto_disconnect;
55 55 GParamSpec * remap_file;
  56 + GParamSpec * dynamic_spacing;
56 57  
57 58 struct
58 59 {
... ...
src/include/v3270.h
... ... @@ -189,6 +189,9 @@
189 189 LIB3270_EXPORT void v3270_set_auto_disconnect(GtkWidget *widget, guint minutes);
190 190 LIB3270_EXPORT guint v3270_get_auto_disconnect(GtkWidget *widget);
191 191  
  192 + LIB3270_EXPORT void v3270_set_dynamic_font_spacing(GtkWidget *widget, gboolean state);
  193 + LIB3270_EXPORT gboolean v3270_get_dynamic_font_spacing(GtkWidget *widget);
  194 +
192 195 // Clipboard
193 196 typedef enum _v3270_select_format
194 197 {
... ...
src/terminal/accessible.c
... ... @@ -326,9 +326,9 @@ static void v3270_accessible_get_character_extents( AtkText *text,
326 326  
327 327 // Get screen position
328 328 *x += widget->font.margin.left + ((offset%cols) * widget->font.width);
329   - *y += widget->font.margin.top + ((offset/cols) * widget->font.spacing);
  329 + *y += widget->font.margin.top + ((offset/cols) * widget->font.spacing.value);
330 330 *width = widget->font.width;
331   - *height = widget->font.spacing;
  331 + *height = widget->font.spacing.value;
332 332  
333 333 if(coords == ATK_XY_WINDOW)
334 334 {
... ...
src/terminal/drawing/draw.c
... ... @@ -377,7 +377,7 @@ void v3270_redraw(v3270 *terminal, cairo_t * cr, gint width, gint height)
377 377 memset(&rect,0,sizeof(rect));
378 378 rect.y = terminal->font.margin.top;
379 379 rect.width = terminal->font.width;
380   - rect.height = terminal->font.spacing;
  380 + rect.height = terminal->font.spacing.value;
381 381 addr = 0;
382 382 cursor = lib3270_get_cursor_address(terminal->host);
383 383  
... ... @@ -404,7 +404,7 @@ void v3270_redraw(v3270 *terminal, cairo_t * cr, gint width, gint height)
404 404 rect.x += rect.width;
405 405 }
406 406  
407   - rect.y += terminal->font.spacing;
  407 + rect.y += terminal->font.spacing.value;
408 408  
409 409 }
410 410  
... ... @@ -455,9 +455,9 @@ void v3270_update_char(H3270 *session, int addr, unsigned char chr, unsigned sho
455 455  
456 456 memset(&rect,0,sizeof(rect));
457 457 rect.x = terminal->font.margin.left + ((addr % cols) * terminal->font.width);
458   - rect.y = terminal->font.margin.top + ((addr / cols) * terminal->font.spacing);
  458 + rect.y = terminal->font.margin.top + ((addr / cols) * terminal->font.spacing.value);
459 459 rect.width = terminal->font.width;
460   - rect.height = terminal->font.spacing;
  460 + rect.height = terminal->font.spacing.value;
461 461  
462 462 cr = cairo_create(terminal->surface);
463 463 cairo_set_scaled_font(cr,terminal->font.scaled);
... ...
src/terminal/drawing/oia.c
... ... @@ -591,7 +591,7 @@ void v3270_draw_oia(v3270 *terminal, cairo_t *cr, int row, int cols)
591 591 row += 2;
592 592  
593 593 gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_BACKGROUND);
594   - cairo_rectangle(cr, terminal->font.margin.left, row, cols*terminal->font.width, terminal->font.spacing);
  594 + cairo_rectangle(cr, terminal->font.margin.left, row, cols*terminal->font.width, terminal->font.spacing.value);
595 595 cairo_fill(cr);
596 596  
597 597 for(f=0;f< (int) G_N_ELEMENTS(right);f++)
... ... @@ -602,7 +602,7 @@ void v3270_draw_oia(v3270 *terminal, cairo_t *cr, int row, int cols)
602 602 r->x = rCol;
603 603 r->y = row;
604 604 r->width = terminal->font.width;
605   - r->height = terminal->font.spacing;
  605 + r->height = terminal->font.spacing.value;
606 606 gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_FOREGROUND);
607 607 right[f].draw(r,&terminal->font,cr,terminal->host,cols,terminal->color);
608 608 rCol = r->x - (terminal->font.width/3);
... ... @@ -613,7 +613,7 @@ void v3270_draw_oia(v3270 *terminal, cairo_t *cr, int row, int cols)
613 613 draw_centered_char(cr,&terminal->font,lCol,row,'4');
614 614  
615 615 cairo_stroke(cr);
616   - cairo_rectangle(cr, lCol, row, terminal->font.width+2, terminal->font.spacing);
  616 + cairo_rectangle(cr, lCol, row, terminal->font.width+2, terminal->font.spacing.value);
617 617 cairo_stroke(cr);
618 618  
619 619 lCol += (terminal->font.width+5);
... ... @@ -622,7 +622,7 @@ void v3270_draw_oia(v3270 *terminal, cairo_t *cr, int row, int cols)
622 622 terminal->oia.rect[V3270_OIA_UNDERA].x = lCol;
623 623 terminal->oia.rect[V3270_OIA_UNDERA].y = row;
624 624 terminal->oia.rect[V3270_OIA_UNDERA].width = terminal->font.width+3;
625   - terminal->oia.rect[V3270_OIA_UNDERA].height = terminal->font.spacing;
  625 + terminal->oia.rect[V3270_OIA_UNDERA].height = terminal->font.spacing.value;
626 626 draw_undera(cr,terminal->host,&terminal->font,terminal->color,terminal->oia.rect+V3270_OIA_UNDERA);
627 627  
628 628 lCol += (3 + terminal->oia.rect[V3270_OIA_UNDERA].width);
... ... @@ -631,7 +631,7 @@ void v3270_draw_oia(v3270 *terminal, cairo_t *cr, int row, int cols)
631 631 terminal->oia.rect[V3270_OIA_CONNECTION].x = lCol;
632 632 terminal->oia.rect[V3270_OIA_CONNECTION].y = row;
633 633 terminal->oia.rect[V3270_OIA_CONNECTION].width = terminal->font.width+3;
634   - terminal->oia.rect[V3270_OIA_CONNECTION].height = terminal->font.spacing;
  634 + terminal->oia.rect[V3270_OIA_CONNECTION].height = terminal->font.spacing.value;
635 635 v3270_draw_connection(cr,terminal->host,&terminal->font,terminal->color,terminal->oia.rect+V3270_OIA_CONNECTION);
636 636  
637 637 lCol += (4 + terminal->oia.rect[V3270_OIA_CONNECTION].width);
... ... @@ -644,7 +644,7 @@ void v3270_draw_oia(v3270 *terminal, cairo_t *cr, int row, int cols)
644 644 r->x = lCol;
645 645 r->y = row;
646 646 r->width = rCol - lCol;
647   - r->height = terminal->font.spacing;
  647 + r->height = terminal->font.spacing.value;
648 648 draw_status_message(cr,lib3270_get_program_message(terminal->host),&terminal->font,terminal->color,r);
649 649 }
650 650  
... ... @@ -765,7 +765,7 @@ void v3270_update_cursor(H3270 *session, unsigned short row, unsigned short col,
765 765 saved = terminal->cursor.rect;
766 766  
767 767 terminal->cursor.rect.x = terminal->font.margin.left + (col * terminal->cursor.rect.width);
768   - terminal->cursor.rect.y = terminal->font.margin.top + (row * terminal->font.spacing);
  768 + terminal->cursor.rect.y = terminal->font.margin.top + (row * terminal->font.spacing.value);
769 769 terminal->cursor.rect.width = terminal->font.width;
770 770 terminal->cursor.rect.height = terminal->font.height+terminal->font.descent;
771 771 terminal->cursor.show |= 1;
... ...
src/terminal/font/metrics.c
... ... @@ -52,17 +52,29 @@ void v3270_update_font_metrics(v3270 *terminal, unsigned int width, unsigned int
52 52  
53 53 // Update margins.
54 54  
55   - terminal->font.width = (int) extents.max_x_advance;
56   - terminal->font.height = (int) extents.height;
57   - terminal->font.ascent = (int) extents.ascent;
58   - terminal->font.descent = (int) extents.descent;
59   - terminal->font.spacing = terminal->font.height + terminal->font.descent;
  55 + terminal->font.width = (int) extents.max_x_advance;
  56 + terminal->font.height = (int) extents.height;
  57 + terminal->font.ascent = (int) extents.ascent;
  58 + terminal->font.descent = (int) extents.descent;
  59 + terminal->font.spacing.value = terminal->font.height + terminal->font.descent;
  60 +
  61 + if(terminal->font.spacing.dynamic)
  62 + {
  63 + // Compatibility adjustments for line spacing.
  64 +
  65 + // Some users complained about the new fixed line spacing; for them
  66 + // the old style is bettter!
  67 +
  68 + guint spacing = height / (rows+2);
  69 + if(spacing > terminal->font.spacing.value)
  70 + terminal->font.spacing.value = spacing;
  71 + }
60 72  
61 73 // Create new cursor surface
62 74 if(terminal->cursor.surface)
63 75 cairo_surface_destroy(terminal->cursor.surface);
64 76  
65   - terminal->cursor.surface = gdk_window_create_similar_surface(gtk_widget_get_window(GTK_WIDGET(terminal)),CAIRO_CONTENT_COLOR,terminal->font.width,terminal->font.spacing);
  77 + terminal->cursor.surface = gdk_window_create_similar_surface(gtk_widget_get_window(GTK_WIDGET(terminal)),CAIRO_CONTENT_COLOR,terminal->font.width,terminal->font.spacing.value);
66 78  
67 79 // Center image
68 80  
... ... @@ -71,7 +83,7 @@ void v3270_update_font_metrics(v3270 *terminal, unsigned int width, unsigned int
71 83  
72 84 debug("%d",(width - size));
73 85  
74   - size = VIEW_HEIGTH_FROM_FONT(terminal->font.spacing);
  86 + size = VIEW_HEIGTH_FROM_FONT(terminal->font.spacing.value);
75 87 terminal->font.margin.top = (height/2) - (size/2);
76 88  
77 89 debug("%d",(height - size));
... ...
src/terminal/get.c
... ... @@ -79,3 +79,9 @@ gchar * v3270_get_region(GtkWidget *widget, gint start_pos, gint end_pos, gboole
79 79  
80 80 return utftext;
81 81 }
  82 +
  83 +gboolean v3270_get_dynamic_font_spacing(GtkWidget *widget)
  84 +{
  85 + g_return_val_if_fail(GTK_IS_V3270(widget),FALSE);
  86 + return GTK_V3270(widget)->font.spacing.dynamic;
  87 +}
... ...
src/terminal/mouse.c
... ... @@ -56,7 +56,7 @@ gint v3270_get_offset_at_point(v3270 *widget, gint x, gint y)
56 56 if(x > 0 && y > 0)
57 57 {
58 58 point.x = ((x-widget->font.margin.left)/widget->font.width);
59   - point.y = ((y-widget->font.margin.top)/widget->font.spacing);
  59 + point.y = ((y-widget->font.margin.top)/widget->font.spacing.value);
60 60  
61 61 lib3270_get_screen_size(widget->host,&r,&c);
62 62  
... ...
src/terminal/properties/get.c
... ... @@ -104,6 +104,10 @@
104 104 g_value_set_string(value,v3270_get_remap_filename(GTK_WIDGET(object)));
105 105 break;
106 106  
  107 + case V3270_PROPERTY_DYNAMIC_SPACING:
  108 + g_value_set_boolean(value,v3270_get_dynamic_font_spacing(GTK_WIDGET(object)));
  109 + break;
  110 +
107 111 default:
108 112 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
109 113  
... ...
src/terminal/properties/init.c
... ... @@ -152,6 +152,21 @@
152 152 klass->properties.remap_file
153 153 );
154 154  
  155 + // Dynamic font spacing
  156 + klass->properties.dynamic_spacing = g_param_spec_boolean(
  157 + "dynamic_font_spacing",
  158 + "dynamic_font_spacing",
  159 + _( "State of the dynamic font spacing" ),
  160 + FALSE,
  161 + G_PARAM_READABLE|G_PARAM_WRITABLE);
  162 +
  163 + g_object_class_install_property(
  164 + gobject_class,
  165 + V3270_PROPERTY_DYNAMIC_SPACING,
  166 + klass->properties.dynamic_spacing
  167 + );
  168 +
  169 +
155 170 //
156 171 // Create dynamic properties
157 172 klass->properties.count = V3270_PROPERTY_DYNAMIC;
... ...
src/terminal/properties/private.h
... ... @@ -53,9 +53,10 @@
53 53 V3270_PROPERTY_SESSION_NAME = 4, ///< @brief Widget's session name.
54 54 V3270_PROPERTY_AUTO_DISCONNECT = 5, ///< @brief Auto disconnect.
55 55 V3270_PROPERTY_REMAP_FILE = 6, ///< @brief Path of the remap file.
  56 + V3270_PROPERTY_DYNAMIC_SPACING = 7, ///< @brief Toggle dynamic font spacing.
56 57  
57 58  
58   - V3270_PROPERTY_DYNAMIC = 7 ///< @brief Id of the first LIB3270 internal property.
  59 + V3270_PROPERTY_DYNAMIC = 8 ///< @brief Id of the first LIB3270 internal property.
59 60 };
60 61  
61 62 G_GNUC_INTERNAL void v3270_get_property(GObject *object,guint prop_id, GValue *value, GParamSpec *pspec);
... ...
src/terminal/properties/set.c
... ... @@ -122,6 +122,10 @@
122 122 v3270_set_remap_filename(GTK_WIDGET(object), g_value_get_string(value));
123 123 break;
124 124  
  125 + case V3270_PROPERTY_DYNAMIC_SPACING:
  126 + v3270_set_dynamic_font_spacing(GTK_WIDGET(object), g_value_get_boolean(value));
  127 + break;
  128 +
125 129 default:
126 130 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
127 131  
... ... @@ -211,3 +215,19 @@ LIB3270_EXPORT void v3270_set_auto_disconnect(GtkWidget *widget, guint minutes)
211 215  
212 216 }
213 217  
  218 +LIB3270_EXPORT void v3270_set_dynamic_font_spacing(GtkWidget *widget, gboolean state) {
  219 +
  220 + g_return_if_fail(GTK_IS_V3270(widget));
  221 +
  222 + v3270 * terminal = GTK_V3270(widget);
  223 +
  224 + if(terminal->font.spacing.dynamic != state)
  225 + {
  226 + terminal->font.spacing.dynamic = state;
  227 + v3270_reconfigure(terminal);
  228 + g_object_notify_by_pspec(G_OBJECT(widget), GTK_V3270_GET_CLASS(widget)->properties.dynamic_spacing);
  229 + }
  230 +
  231 +}
  232 +
  233 +
... ...