Commit 1053cc4165d3383138bb597bdc31a34cec67fcf4

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

Adding "zoom" methods.

src/dialogs/colorscheme.c
... ... @@ -268,9 +268,9 @@
268 268 GtkTreeModel * model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
269 269  
270 270 #ifdef DEBUG
271   - lib3270_autoptr(char) filename = lib3270_strdup_printf("%s/%s",".","colors.conf");
  271 + g_autofree gchar * filename = g_build_filename("conf","colors.conf",NULL);
272 272 #else
273   - lib3270_autoptr(char) filename = lib3270_build_data_filename("colors.conf");
  273 + lib3270_autoptr(char) filename = lib3270_build_data_filename("colors.conf",NULL);
274 274 #endif // DEBUG
275 275  
276 276 if(!g_file_test(filename,G_FILE_TEST_IS_REGULAR))
... ...
src/dialogs/print/begin.c
... ... @@ -41,8 +41,7 @@
41 41 // Setup FONT
42 42 if(!operation->font.name)
43 43 {
44   - operation->font.name = g_strdup("monospace");
45   - debug("No font, assuming %s !!!!!!!!!!!!!!!!!!!!!!!!!!",operation->font.name);
  44 + operation->font.name = g_strdup(v3270_get_default_font_name());
46 45 g_warning("No font, assuming %s",operation->font.name);
47 46 }
48 47  
... ... @@ -85,9 +84,9 @@
85 84  
86 85 operation->font.info.width++;
87 86  
88   - operation->font.info.left = (gtk_print_context_get_width(context)- (operation->font.info.width * operation->contents.width))/2;
89   - if(operation->font.info.left < 2)
90   - operation->font.info.left = 2;
  87 + operation->font.info.margin.left = (gtk_print_context_get_width(context)- (operation->font.info.width * operation->contents.width))/2;
  88 + if(operation->font.info.margin.left < 2)
  89 + operation->font.info.margin.left = 2;
91 90  
92 91 // Setup page size
93 92 operation->lpp = (gtk_print_context_get_height(context) / (extents.height + extents.descent));
... ...
src/dialogs/print/draw.c
... ... @@ -29,6 +29,7 @@
29 29  
30 30 #include "private.h"
31 31 #include <string.h>
  32 + #include <internals.h>
32 33 #include <lib3270/selection.h>
33 34  
34 35 /*--[ Implement ]------------------------------------------------------------------------------------*/
... ... @@ -86,7 +87,7 @@
86 87 gdk_cairo_set_source_rgba(cr,operation->settings.colors + V3270_COLOR_BACKGROUND);
87 88 cairo_rectangle(
88 89 cr,
89   - operation->font.info.left-1,0,
  90 + operation->font.info.margin.left-1,0,
90 91 (rect.width * operation->contents.width) + 4,
91 92 (rect.height * operation->contents.height) + 4
92 93 );
... ... @@ -111,7 +112,7 @@
111 112 // Draw columns
112 113 size_t pos = (row * selection->bounds.width);
113 114 size_t col;
114   - rect.x = operation->font.info.left;
  115 + rect.x = operation->font.info.margin.left;
115 116  
116 117 debug("Drawing: %u row=%u selection=%p pos=%u", (unsigned int) drawing, row, selection, (unsigned int) pos);
117 118  
... ...
src/dialogs/print/private.h
... ... @@ -31,6 +31,7 @@
31 31 #include <v3270/print.h>
32 32 #include <lib3270/log.h>
33 33 #include <lib3270/trace.h>
  34 + #include <internals.h>
34 35  
35 36 /*--[ Widget definition ]----------------------------------------------------------------------------*/
36 37  
... ...
src/include/internals.h
... ... @@ -157,11 +157,47 @@
157 157  
158 158 G_GNUC_INTERNAL GtkWidget * v3270_charset_combo_box_new();
159 159  
  160 +
  161 +/*--[ Font Info ]------------------------------------------------------------------------------------*/
  162 +
  163 + typedef struct _v3270FontInfo {
  164 +
  165 + double size; ///< @brief Current font size.
  166 + double step; ///< @brief Steps for zoom in/out.
  167 +
  168 + guint width;
  169 + guint height;
  170 + guint ascent;
  171 + guint descent;
  172 +
  173 + guint spacing;
  174 +
  175 + struct
  176 + {
  177 + gint left;
  178 + gint top;
  179 +
  180 + } margin;
  181 +
  182 + gchar * family;
  183 + cairo_font_face_t * face;
  184 + cairo_font_weight_t weight;
  185 + cairo_scaled_font_t * scaled;
  186 +
  187 + } v3270FontInfo;
  188 +
  189 +G_GNUC_INTERNAL void v3270_font_info_init(v3270FontInfo *info);
  190 +G_GNUC_INTERNAL void v3270_font_info_unset(v3270FontInfo *info);
  191 +
  192 +G_GNUC_INTERNAL void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, v3270FontInfo *font, GdkRectangle *rect, GdkRGBA *color);
  193 +
160 194 /*--[ Internal Methods ]-----------------------------------------------------------------------------*/
161 195  
162 196  
163 197 const GtkWidgetClass * v3270_get_parent_class(void);
164 198  
  199 + G_GNUC_INTERNAL void v3270_reconfigure(v3270 * terminal);
  200 +
165 201 G_GNUC_INTERNAL gboolean v3270_draw(GtkWidget * widget, cairo_t * cr);
166 202 G_GNUC_INTERNAL void v3270_cursor_draw(v3270 *widget);
167 203 G_GNUC_INTERNAL void v3270_set_cursor(GtkWidget *widget, LIB3270_POINTER id);
... ... @@ -209,6 +245,8 @@
209 245 G_GNUC_INTERNAL void v3270_start_timer(GtkWidget *terminal);
210 246 G_GNUC_INTERNAL void v3270_stop_timer(GtkWidget *terminal);
211 247  
  248 + G_GNUC_INTERNAL void v3270_redraw(v3270 *terminal, cairo_t * cr, gint width, gint height);
  249 +
212 250 G_GNUC_INTERNAL void v3270_draw_connection(cairo_t *cr, H3270 *host, v3270FontInfo *metrics, GdkRGBA *color, const GdkRectangle *rect);
213 251  
214 252 G_GNUC_INTERNAL void v3270_draw_ssl_status(v3270 *widget, cairo_t *cr, GdkRectangle *rect);
... ...
src/include/terminal.h
... ... @@ -108,12 +108,14 @@ G_BEGIN_DECLS
108 108 int scaled_fonts : 1; /**< Use scaled fonts */
109 109 int drawing : 1; /**< Draw widget? */
110 110  
  111 + /*
111 112 #if GTK_CHECK_VERSION(3,0,0)
112 113  
113 114 #else
114 115 gint width;
115 116 gint height;
116 117 #endif // GTK_CHECK_VERSION(3,0,0)
  118 + */
117 119  
118 120 GSource * timer;
119 121 GtkIMContext * input_method;
... ... @@ -135,10 +137,6 @@ G_BEGIN_DECLS
135 137 cairo_surface_t * surface;
136 138 v3270FontInfo font;
137 139  
138   - struct {
139   - double step; ///< @brief Steps for zoom in/out.
140   - } zoom;
141   -
142 140 gint minimum_width;
143 141 gint minimum_height;
144 142  
... ...
src/include/v3270.h
... ... @@ -63,25 +63,6 @@
63 63 typedef struct _v3270 v3270;
64 64 typedef struct _v3270Class v3270Class;
65 65  
66   - typedef struct _v3270FontInfo {
67   -
68   - guint width;
69   - guint height;
70   - guint ascent;
71   - guint descent;
72   -
73   - guint spacing;
74   -
75   - guint left;
76   - guint top;
77   -
78   - gchar * family;
79   - cairo_font_face_t * face;
80   - cairo_font_weight_t weight;
81   - cairo_scaled_font_t * scaled;
82   -
83   - } v3270FontInfo;
84   -
85 66 enum V3270_COLOR
86 67 {
87 68 V3270_COLOR_BACKGROUND,
... ... @@ -218,7 +199,6 @@
218 199 LIB3270_EXPORT void v3270_set_color_table(GdkRGBA *table, const gchar *colors);
219 200 LIB3270_EXPORT const GdkRGBA * v3270_get_color_table(GtkWidget *widget);
220 201 LIB3270_EXPORT void v3270_set_mono_color_table(GdkRGBA *table, const gchar *fg, const gchar *bg);
221   - LIB3270_EXPORT void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, v3270FontInfo *font, GdkRectangle *rect, GdkRGBA *color);
222 202 LIB3270_EXPORT void v3270_set_color(GtkWidget *widget, enum V3270_COLOR id, const GdkRGBA *color);
223 203 LIB3270_EXPORT GdkRGBA * v3270_get_color(GtkWidget *widget, enum V3270_COLOR id);
224 204  
... ... @@ -277,6 +257,9 @@
277 257  
278 258 // Misc
279 259 LIB3270_EXPORT int v3270_exec_command(GtkWidget *widget, const gchar *cmdline);
  260 + LIB3270_EXPORT void v3270_zoom_best(GtkWidget *widget);
  261 + LIB3270_EXPORT void v3270_zoom_in(GtkWidget *widget);
  262 + LIB3270_EXPORT void v3270_zoom_out(GtkWidget *widget);
280 263  
281 264 // Convenience
282 265 LIB3270_EXPORT void gtk_entry_set_printf(GtkEntry *entry, const gchar *fmt, ...) G_GNUC_PRINTF(2,3);
... ...
src/terminal/accessible.c
... ... @@ -325,8 +325,8 @@ static void v3270_accessible_get_character_extents( AtkText *text,
325 325 gdk_window_get_origin(window, x, y);
326 326  
327 327 // Get screen position
328   - *x += widget->font.left + ((offset%cols) * widget->font.width);
329   - *y += widget->font.top + ((offset/cols) * widget->font.spacing);
  328 + *x += widget->font.margin.left + ((offset%cols) * widget->font.width);
  329 + *y += widget->font.margin.top + ((offset/cols) * widget->font.spacing);
330 330 *width = widget->font.width;
331 331 *height = widget->font.spacing;
332 332  
... ...
src/terminal/draw.c
... ... @@ -122,7 +122,7 @@ static void get_element_colors(unsigned short attr, GdkRGBA **fg, GdkRGBA **bg,
122 122 }
123 123 }
124 124  
125   -LIB3270_EXPORT void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, v3270FontInfo *fontInfo, GdkRectangle *rect, GdkRGBA *color)
  125 +void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, v3270FontInfo *fontInfo, GdkRectangle *rect, GdkRGBA *color)
126 126 {
127 127 GdkRGBA *fg;
128 128 GdkRGBA *bg;
... ... @@ -341,55 +341,40 @@ cairo_surface_t *gdk_window_create_similar_surface(GdkWindow *window, cairo_cont
341 341 }
342 342 #endif // GTK_CHECK_VERSION(2, 22, 0)
343 343  
344   -LIB3270_EXPORT void v3270_reload(GtkWidget *widget)
  344 +/// @brief Draw terminal contents.
  345 +///
  346 +/// @param terminal Terminal widget.
  347 +/// @param cr a cairo context.
  348 +/// @param width the width of the rectangle.
  349 +/// @param height the height of the rectangle.
  350 +///
  351 +void v3270_redraw(v3270 *terminal, cairo_t * cr, gint width, gint height)
345 352 {
346   - v3270 * terminal = GTK_V3270(widget);
347   -
348   - gint width = gtk_widget_get_allocated_width(widget);
349   - gint height = gtk_widget_get_allocated_height(widget);
350   -
  353 + unsigned int rows, cols, r;
351 354 GdkRectangle rect;
352 355 int addr, cursor;
353   - unsigned int rows, cols, r;
354   -
355   - cairo_t * cr;
356   -
357   - if(!(gtk_widget_get_realized(widget) && terminal->drawing))
358   - {
359   - return;
360   - }
361   -
362   - // Create new terminal image
363   - if(terminal->surface)
364   - cairo_surface_destroy(terminal->surface);
365   -
366   - terminal->surface = (cairo_surface_t *) gdk_window_create_similar_surface(gtk_widget_get_window(widget),CAIRO_CONTENT_COLOR,width,height);
367   -
368   - // Update the created image
369   - cr = cairo_create(terminal->surface);
370   - v3270_compute_font_size(terminal, cr, width, height);
371   - v3270_update_font_metrics(terminal, width, height);
372 356  
373 357 gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_BACKGROUND);
374 358 cairo_rectangle(cr, 0, 0, width, height);
375 359 cairo_fill(cr);
376 360 cairo_stroke(cr);
377 361  
378   - // Draw terminal contents
379 362 lib3270_get_screen_size(terminal->host,&rows,&cols);
380 363  
381 364 memset(&rect,0,sizeof(rect));
382   - rect.y = terminal->font.top;
  365 + rect.y = terminal->font.margin.top;
383 366 rect.width = terminal->font.width;
384 367 rect.height = terminal->font.spacing;
385 368 addr = 0;
386 369 cursor = lib3270_get_cursor_address(terminal->host);
387 370  
  371 + cairo_set_scaled_font(cr,terminal->font.scaled);
  372 +
388 373 for(r = 0; r < rows; r++)
389 374 {
390 375 unsigned int c;
391 376  
392   - rect.x = terminal->font.left;
  377 + rect.x = terminal->font.margin.left;
393 378  
394 379 for(c=0;c < cols;c++)
395 380 {
... ... @@ -410,11 +395,47 @@ LIB3270_EXPORT void v3270_reload(GtkWidget *widget)
410 395  
411 396 }
412 397  
413   - cairo_set_scaled_font(cr,terminal->font.scaled);
414 398 v3270_draw_oia(terminal, cr, rect.y, cols);
415 399  
  400 +}
  401 +
  402 +LIB3270_EXPORT void v3270_reload(GtkWidget *widget)
  403 +{
  404 + v3270 * terminal = GTK_V3270(widget);
  405 +
  406 + if(!(gtk_widget_get_realized(widget) && terminal->drawing))
  407 + return;
  408 +
  409 + gint width = gtk_widget_get_allocated_width(widget);
  410 + gint height = gtk_widget_get_allocated_height(widget);
  411 +
  412 + cairo_t * cr = cairo_create(terminal->surface);
  413 +
  414 + v3270_redraw(terminal, cr, width, height);
  415 +
416 416 cairo_destroy(cr);
417 417  
  418 + /*
  419 + v3270 * terminal = GTK_V3270(widget);
  420 + cairo_t * cr;
  421 +
  422 +
  423 +
  424 + // Create new terminal image
  425 + if(terminal->surface)
  426 + cairo_surface_destroy(terminal->surface);
  427 +
  428 + terminal->surface = (cairo_surface_t *) gdk_window_create_similar_surface(gtk_widget_get_window(widget),CAIRO_CONTENT_COLOR,width,height);
  429 +
  430 + // Update the created image
  431 + cr = cairo_create(terminal->surface);
  432 + v3270_compute_font_size(terminal, cr, width, height);
  433 + v3270_update_font_metrics(terminal, width, height);
  434 +
  435 + v3270_redraw(terminal, cr, width, height);
  436 +
  437 + cairo_destroy(cr);
  438 + */
418 439 }
419 440  
420 441 void v3270_update_char(H3270 *session, int addr, unsigned char chr, unsigned short attr, unsigned char cursor)
... ... @@ -441,8 +462,8 @@ void v3270_update_char(H3270 *session, int addr, unsigned char chr, unsigned sho
441 462 lib3270_get_screen_size(terminal->host,&rows,&cols);
442 463  
443 464 memset(&rect,0,sizeof(rect));
444   - rect.x = terminal->font.left + ((addr % cols) * terminal->font.width);
445   - rect.y = terminal->font.top + ((addr / cols) * terminal->font.spacing);
  465 + rect.x = terminal->font.margin.left + ((addr % cols) * terminal->font.width);
  466 + rect.y = terminal->font.margin.top + ((addr / cols) * terminal->font.spacing);
446 467 rect.width = terminal->font.width;
447 468 rect.height = terminal->font.spacing;
448 469  
... ...
src/terminal/font/actions.c 0 → 100644
... ... @@ -0,0 +1,137 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como - e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 + #include <config.h>
  31 + #include "private.h"
  32 +
  33 +/*--[ Implement ]------------------------------------------------------------------------------------*/
  34 +
  35 +/*
  36 +static void update_font_size(v3270 * terminal, cairo_t *cr, gint width, gint height, int step)
  37 +{
  38 +
  39 +
  40 + cairo_set_font_face(cr,terminal->font.face);
  41 +
  42 + cairo_set_font_size(cr,terminal->font.size);
  43 +
  44 + v3270_update_font_metrics(terminal, width, height);
  45 +
  46 + if(terminal->font.scaled)
  47 + cairo_scaled_font_destroy(terminal->font.scaled);
  48 +
  49 + terminal->font.scaled = cairo_get_scaled_font(cr);
  50 + cairo_scaled_font_reference(terminal->font.scaled);
  51 +
  52 + v3270_redraw(terminal, cr, width, height);
  53 +
  54 + gtk_widget_queue_draw(GTK_WIDGET(terminal));
  55 +
  56 +}
  57 +*/
  58 +
  59 +void v3270_zoom_best(GtkWidget *widget)
  60 +{
  61 + debug("%s",__FUNCTION__);
  62 +
  63 + g_return_if_fail(GTK_IS_V3270(widget));
  64 + v3270 * terminal = GTK_V3270(widget);
  65 + if(!(gtk_widget_get_realized(widget) && terminal->drawing && lib3270_is_connected(terminal->host)))
  66 + {
  67 + gdk_display_beep(gdk_display_get_default());
  68 + return;
  69 + }
  70 +
  71 + gint width = gtk_widget_get_allocated_width(widget);
  72 + gint height = gtk_widget_get_allocated_height(widget);
  73 +
  74 + cairo_t *cr = cairo_create(terminal->surface);
  75 +
  76 + v3270_compute_font_size(terminal, cr, width, height);
  77 + v3270_update_font_metrics(terminal, width, height);
  78 +
  79 + v3270_redraw(terminal, cr, width, height);
  80 +
  81 + cairo_destroy(cr);
  82 +
  83 + gtk_widget_queue_draw(widget);
  84 +
  85 +}
  86 +
  87 +static void zoom(GtkWidget *widget, double step)
  88 +{
  89 + debug("%s",__FUNCTION__);
  90 +
  91 + g_return_if_fail(GTK_IS_V3270(widget));
  92 + v3270 * terminal = GTK_V3270(widget);
  93 + if(!(gtk_widget_get_realized(widget) && terminal->drawing && lib3270_is_connected(terminal->host)))
  94 + {
  95 + gtk_widget_error_bell(widget);
  96 + return;
  97 + }
  98 +
  99 + terminal->font.size += step;
  100 +
  101 + // Redraw window
  102 +
  103 + gint width = gtk_widget_get_allocated_width(widget);
  104 + gint height = gtk_widget_get_allocated_height(widget);
  105 +
  106 + cairo_t *cr = cairo_create(terminal->surface);
  107 +
  108 + cairo_set_font_face(cr,terminal->font.face);
  109 + cairo_set_font_size(cr,terminal->font.size);
  110 +
  111 + v3270_update_font_metrics(terminal, width, height);
  112 +
  113 + if(terminal->font.scaled)
  114 + cairo_scaled_font_destroy(terminal->font.scaled);
  115 +
  116 + terminal->font.scaled = cairo_get_scaled_font(cr);
  117 + cairo_scaled_font_reference(terminal->font.scaled);
  118 +
  119 + v3270_redraw(terminal, cr, width, height);
  120 +
  121 + cairo_destroy(cr);
  122 +
  123 + gtk_widget_queue_draw(GTK_WIDGET(terminal));
  124 +
  125 +}
  126 +
  127 +void v3270_zoom_in(GtkWidget *widget)
  128 +{
  129 + zoom(widget,1);
  130 +}
  131 +
  132 +void v3270_zoom_out(GtkWidget *widget)
  133 +{
  134 + debug("%s",__FUNCTION__);
  135 + zoom(widget,-1);
  136 +}
  137 +
... ...
src/terminal/font/compute.c
... ... @@ -67,27 +67,25 @@
67 67 cairo_set_font_face(cr,terminal->font.face);
68 68  
69 69 {
70   - double s = terminal->zoom.step;
71   - double selected = 0;
  70 + double s = terminal->font.step;
72 71  
73 72 do
74 73 {
75   - selected = s;
  74 + terminal->font.size = s;
76 75  
77   - s += terminal->zoom.step;
  76 + s += terminal->font.step;
78 77 cairo_set_font_size(cr,s);
79 78 cairo_font_extents(cr,&extents);
80 79  
81 80 } while( (VIEW_HEIGTH_FROM_FONT( (extents.height+extents.descent) ) < height) && (VIEW_WIDTH_FROM_FONT(extents.max_x_advance) < width) );
82 81  
83   - debug("Selected size=%lf",selected);
84   -
85   - cairo_set_font_size(cr,selected);
86   - cairo_font_extents(cr,&extents);
  82 + debug("Selected size=%lf",terminal->font.size);
87 83  
88 84 }
89 85  
90 86 // Save scaled font for use on next drawings
  87 + cairo_set_font_size(cr,terminal->font.size);
  88 +
91 89 if(terminal->font.scaled)
92 90 cairo_scaled_font_destroy(terminal->font.scaled);
93 91  
... ...
src/terminal/font/info.c 0 → 100644
... ... @@ -0,0 +1,63 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como - e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 + #include <config.h>
  31 + #include "private.h"
  32 +
  33 +/*--[ Implement ]------------------------------------------------------------------------------------*/
  34 +
  35 +void v3270_font_info_init(v3270FontInfo *info)
  36 +{
  37 + memset(info,0,sizeof(v3270FontInfo));
  38 +
  39 + info->family = g_strdup(v3270_get_default_font_name());
  40 + info->step = 0.1;
  41 + info->size = 0.1;
  42 +}
  43 +
  44 +void v3270_font_info_unset(v3270FontInfo *info)
  45 +{
  46 + if(info->family)
  47 + {
  48 + g_free(info->family);
  49 + info->family = NULL;
  50 + }
  51 +
  52 + if(info->scaled)
  53 + {
  54 + cairo_scaled_font_destroy(info->scaled);
  55 + info->scaled = NULL;
  56 + }
  57 +
  58 + if(info->face) {
  59 + cairo_font_face_destroy(info->face);
  60 + info->face = NULL;
  61 + }
  62 +
  63 +}
... ...
src/terminal/font/metrics.c
... ... @@ -67,12 +67,16 @@ void v3270_update_font_metrics(v3270 *terminal, unsigned int width, unsigned int
67 67 // Center image
68 68  
69 69 size = VIEW_WIDTH_FROM_FONT(terminal->font.width);
70   - terminal->font.left = ((width - size) / 2);
  70 + terminal->font.margin.left = (width/2) - (size/2);
  71 +
  72 + debug("%d",(width - size));
71 73  
72 74 size = VIEW_HEIGTH_FROM_FONT(terminal->font.spacing);
73   - terminal->font.top = ((height - size) /2);
  75 + terminal->font.margin.top = (height/2) - (size/2);
  76 +
  77 + debug("%d",(height - size));
74 78  
75   - debug("screen_height=%u content_height=%u top=%d",height, size, terminal->font.top);
  79 + debug("screen_height=%u content_height=%d top=%d left=%d size=%lf",height, size, terminal->font.margin.top, terminal->font.margin.left, terminal->font.size);
76 80  
77 81 }
78 82  
... ...
src/terminal/font/private.h
... ... @@ -29,6 +29,7 @@
29 29  
30 30 #include <config.h>
31 31 #include <terminal.h>
  32 + #include <internals.h>
32 33 #include <lib3270.h>
33 34 #include <lib3270/log.h>
34 35 #include <lib3270/toggle.h>
... ...
src/terminal/mouse.c
... ... @@ -55,8 +55,8 @@ gint v3270_get_offset_at_point(v3270 *widget, gint x, gint y)
55 55  
56 56 if(x > 0 && y > 0)
57 57 {
58   - point.x = ((x-widget->font.left)/widget->font.width);
59   - point.y = ((y-widget->font.top)/widget->font.spacing);
  58 + point.x = ((x-widget->font.margin.left)/widget->font.width);
  59 + point.y = ((y-widget->font.margin.top)/widget->font.spacing);
60 60  
61 61 lib3270_get_screen_size(widget->host,&r,&c);
62 62  
... ...
src/terminal/oia.c
... ... @@ -581,18 +581,18 @@ void v3270_draw_oia(v3270 *terminal, cairo_t *cr, int row, int cols)
581 581 };
582 582  
583 583 int f;
584   - int rCol = terminal->font.left+(cols*terminal->font.width);
585   - int lCol = terminal->font.left+1;
  584 + int rCol = terminal->font.margin.left+(cols*terminal->font.width);
  585 + int lCol = terminal->font.margin.left+1;
586 586  
587 587 row += OIA_TOP_MARGIN;
588 588 gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_SEPARATOR);
589   - cairo_rectangle(cr, terminal->font.left, row, cols*terminal->font.width, 1);
  589 + cairo_rectangle(cr, terminal->font.margin.left, row, cols*terminal->font.width, 1);
590 590 cairo_fill(cr);
591 591  
592 592 row += 2;
593 593  
594 594 gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_BACKGROUND);
595   - cairo_rectangle(cr, terminal->font.left, row, cols*terminal->font.width, terminal->font.spacing);
  595 + cairo_rectangle(cr, terminal->font.margin.left, row, cols*terminal->font.width, terminal->font.spacing);
596 596 cairo_fill(cr);
597 597  
598 598 for(f=0;f< (int) G_N_ELEMENTS(right);f++)
... ... @@ -770,8 +770,8 @@ void v3270_update_cursor(H3270 *session, unsigned short row, unsigned short col,
770 770 // Update cursor rectangle
771 771 saved = terminal->cursor.rect;
772 772  
773   - terminal->cursor.rect.x = terminal->font.left + (col * terminal->cursor.rect.width);
774   - terminal->cursor.rect.y = terminal->font.top + (row * terminal->font.spacing);
  773 + terminal->cursor.rect.x = terminal->font.margin.left + (col * terminal->cursor.rect.width);
  774 + terminal->cursor.rect.y = terminal->font.margin.top + (row * terminal->font.spacing);
775 775 terminal->cursor.rect.width = terminal->font.width;
776 776 terminal->cursor.rect.height = terminal->font.height+terminal->font.descent;
777 777 terminal->cursor.show |= 1;
... ...
src/terminal/surface.c 0 → 100644
... ... @@ -0,0 +1,86 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como - e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 + #include <config.h>
  31 + #include <terminal.h>
  32 +
  33 +/*--[ Implement ]------------------------------------------------------------------------------------*/
  34 +
  35 +/**
  36 + * @brief Reconfigure widget surface.
  37 + *
  38 + * Called when the widget is resized or moved to regenerate the cairo surface:
  39 + *
  40 + * * Recreate the surface.
  41 + * * Compute the new font size & metrics.
  42 + * * Redraw contents.
  43 + * * Emite "GDK_CONFIGURE" event.
  44 + *
  45 + */
  46 +void v3270_reconfigure(v3270 * terminal)
  47 +{
  48 + GtkAllocation allocation;
  49 + GtkWidget *widget;
  50 + GdkEvent *event = gdk_event_new(GDK_CONFIGURE);
  51 +
  52 + widget = GTK_WIDGET(terminal);
  53 +
  54 + gtk_widget_get_allocation(widget, &allocation);
  55 +
  56 + event->configure.window = g_object_ref(gtk_widget_get_window(widget));
  57 + event->configure.send_event = TRUE;
  58 + event->configure.x = allocation.x;
  59 + event->configure.y = allocation.y;
  60 + event->configure.width = allocation.width;
  61 + event->configure.height = allocation.height;
  62 +
  63 + if(terminal->surface)
  64 + cairo_surface_destroy(terminal->surface);
  65 +
  66 + terminal->surface = (cairo_surface_t *) gdk_window_create_similar_surface(gtk_widget_get_window(widget),CAIRO_CONTENT_COLOR,allocation.width,allocation.height);
  67 +
  68 + // Update the created image
  69 + cairo_t * cr = cairo_create(terminal->surface);
  70 + v3270_compute_font_size(terminal, cr, allocation.width, allocation.height);
  71 + v3270_update_font_metrics(terminal, allocation.width, allocation.height);
  72 +
  73 + v3270_redraw(terminal, cr, allocation.width, allocation.height);
  74 +
  75 + cairo_destroy(cr);
  76 +
  77 +#if( !GTK_CHECK_VERSION(3,0,0))
  78 + terminal->width = allocation.width;
  79 + terminal->height = allocation.height;
  80 +#endif
  81 +
  82 + gtk_widget_event(widget, event);
  83 + gdk_event_free(event);
  84 +}
  85 +
  86 +
... ...
src/terminal/widget.c
... ... @@ -71,8 +71,6 @@
71 71 static void v3270_realize ( GtkWidget * widget) ;
72 72 static void v3270_size_allocate ( GtkWidget * widget,
73 73 GtkAllocation * allocation );
74   -static void v3270_send_configure ( v3270 * terminal );
75   -
76 74 // Signals
77 75 static void v3270_activate (GtkWidget *widget);
78 76  
... ... @@ -503,9 +501,6 @@ static void v3270_init(v3270 *widget)
503 501 // Setup clipboard.
504 502 widget->selection.target = GDK_SELECTION_CLIPBOARD;
505 503  
506   - // Setup zoom
507   - widget->zoom.step = 0.1;
508   -
509 504 // Reset timer
510 505 widget->activity.timestamp = time(0);
511 506 widget->activity.disconnect = 0;
... ... @@ -532,7 +527,7 @@ static void v3270_init(v3270 *widget)
532 527 widget->drawing = 1;
533 528  
534 529 // Set defaults
535   - widget->font.family = g_strdup(v3270_get_default_font_name());
  530 + v3270_font_info_init(&widget->font);
536 531 v3270_set_color_table(widget->color,v3270_default_colors);
537 532  
538 533 }
... ... @@ -562,22 +557,7 @@ static void v3270_destroy(GtkWidget *widget)
562 557 terminal->accessible = NULL;
563 558 }
564 559  
565   - if(terminal->font.family)
566   - {
567   - g_free(terminal->font.family);
568   - terminal->font.family = 0;
569   - }
570   -
571   - if(terminal->font.scaled)
572   - {
573   - cairo_scaled_font_destroy(terminal->font.scaled);
574   - terminal->font.scaled = NULL;
575   - }
576   -
577   - if(terminal->font.face) {
578   - cairo_font_face_destroy(terminal->font.face);
579   - terminal->font.face = NULL;
580   - }
  560 + v3270_font_info_unset(&terminal->font);
581 561  
582 562 if(terminal->surface)
583 563 {
... ... @@ -736,9 +716,7 @@ static void v3270_realize(GtkWidget * widget)
736 716 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
737 717 #endif // !GTK3
738 718  
739   - v3270_reload(widget);
740   -
741   - v3270_send_configure(GTK_V3270(widget));
  719 + v3270_reconfigure(GTK_V3270(widget));
742 720  
743 721 if(!GTK_V3270(widget)->cursor.timer)
744 722 {
... ... @@ -776,8 +754,8 @@ static void v3270_size_allocate(GtkWidget * widget, GtkAllocation * allocation)
776 754 if(gtk_widget_get_has_window(widget))
777 755 gdk_window_move_resize(gtk_widget_get_window (widget),allocation->x, allocation->y,allocation->width, allocation->height);
778 756  
779   - v3270_reload(widget);
780   - v3270_send_configure(GTK_V3270(widget));
  757 + v3270_reconfigure(GTK_V3270(widget));
  758 +
781 759 }
782 760 }
783 761  
... ... @@ -789,32 +767,6 @@ G_GNUC_INTERNAL void gtk_widget_get_allocation(GtkWidget *widget, GtkAllocation
789 767 #endif // !GTK(2,18)
790 768  
791 769  
792   -static void v3270_send_configure(v3270 * terminal)
793   -{
794   - GtkAllocation allocation;
795   - GtkWidget *widget;
796   - GdkEvent *event = gdk_event_new(GDK_CONFIGURE);
797   -
798   - widget = GTK_WIDGET(terminal);
799   -
800   - gtk_widget_get_allocation(widget, &allocation);
801   -
802   - event->configure.window = g_object_ref(gtk_widget_get_window(widget));
803   - event->configure.send_event = TRUE;
804   - event->configure.x = allocation.x;
805   - event->configure.y = allocation.y;
806   - event->configure.width = allocation.width;
807   - event->configure.height = allocation.height;
808   -
809   -#if( !GTK_CHECK_VERSION(3,0,0))
810   - terminal->width = allocation.width;
811   - terminal->height = allocation.height;
812   -#endif
813   -
814   - gtk_widget_event(widget, event);
815   - gdk_event_free(event);
816   -}
817   -
818 770 LIB3270_EXPORT void v3270_disconnect(GtkWidget *widget)
819 771 {
820 772 g_return_if_fail(GTK_IS_V3270(widget));
... ...
src/testprogram/toolbar.c
... ... @@ -178,6 +178,21 @@
178 178  
179 179 }
180 180  
  181 + static void zoom_in_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal)
  182 + {
  183 + v3270_zoom_in(terminal);
  184 + }
  185 +
  186 + static void zoom_out_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal)
  187 + {
  188 + v3270_zoom_out(terminal);
  189 + }
  190 +
  191 + static void zoom_best_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal)
  192 + {
  193 + v3270_zoom_best(terminal);
  194 + }
  195 +
181 196 GtkWidget * create_toolbar(GtkWidget *terminal) {
182 197  
183 198 size_t f;
... ... @@ -199,6 +214,9 @@
199 214 { "document-save", G_CALLBACK(save_all_clicked), "Save screen" },
200 215 { "document-open", G_CALLBACK(load_clicked), "Paste file" },
201 216  
  217 + { "zoom-in", G_CALLBACK(zoom_in_clicked), "Zoom in" },
  218 + { "zoom-out", G_CALLBACK(zoom_out_clicked), "Zoom out" },
  219 + { "zoom-fit-best", G_CALLBACK(zoom_best_clicked), "Zoom best" },
202 220 };
203 221  
204 222 GtkWidget * toolbar = gtk_toolbar_new();
... ...
v3270.cbp
... ... @@ -217,9 +217,15 @@
217 217 <Unit filename="src/terminal/draw.c">
218 218 <Option compilerVar="CC" />
219 219 </Unit>
  220 + <Unit filename="src/terminal/font/actions.c">
  221 + <Option compilerVar="CC" />
  222 + </Unit>
220 223 <Unit filename="src/terminal/font/compute.c">
221 224 <Option compilerVar="CC" />
222 225 </Unit>
  226 + <Unit filename="src/terminal/font/info.c">
  227 + <Option compilerVar="CC" />
  228 + </Unit>
223 229 <Unit filename="src/terminal/font/metrics.c">
224 230 <Option compilerVar="CC" />
225 231 </Unit>
... ... @@ -262,6 +268,9 @@
262 268 <Unit filename="src/terminal/security.c">
263 269 <Option compilerVar="CC" />
264 270 </Unit>
  271 + <Unit filename="src/terminal/surface.c">
  272 + <Option compilerVar="CC" />
  273 + </Unit>
265 274 <Unit filename="src/terminal/widget.c">
266 275 <Option compilerVar="CC" />
267 276 </Unit>
... ...