From 1053cc4165d3383138bb597bdc31a34cec67fcf4 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Thu, 12 Sep 2019 16:19:13 -0300 Subject: [PATCH] Adding "zoom" methods. --- src/dialogs/colorscheme.c | 4 ++-- src/dialogs/print/begin.c | 9 ++++----- src/dialogs/print/draw.c | 5 +++-- src/dialogs/print/private.h | 1 + src/include/internals.h | 38 ++++++++++++++++++++++++++++++++++++++ src/include/terminal.h | 6 ++---- src/include/v3270.h | 23 +++-------------------- src/terminal/accessible.c | 4 ++-- src/terminal/draw.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------- src/terminal/font/actions.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/terminal/font/compute.c | 14 ++++++-------- src/terminal/font/info.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/terminal/font/metrics.c | 10 +++++++--- src/terminal/font/private.h | 1 + src/terminal/mouse.c | 4 ++-- src/terminal/oia.c | 12 ++++++------ src/terminal/surface.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/terminal/widget.c | 58 +++++----------------------------------------------------- src/testprogram/toolbar.c | 18 ++++++++++++++++++ v3270.cbp | 9 +++++++++ 20 files changed, 448 insertions(+), 139 deletions(-) create mode 100644 src/terminal/font/actions.c create mode 100644 src/terminal/font/info.c create mode 100644 src/terminal/surface.c diff --git a/src/dialogs/colorscheme.c b/src/dialogs/colorscheme.c index 3c25967..9ae7d8a 100644 --- a/src/dialogs/colorscheme.c +++ b/src/dialogs/colorscheme.c @@ -268,9 +268,9 @@ GtkTreeModel * model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget)); #ifdef DEBUG - lib3270_autoptr(char) filename = lib3270_strdup_printf("%s/%s",".","colors.conf"); + g_autofree gchar * filename = g_build_filename("conf","colors.conf",NULL); #else - lib3270_autoptr(char) filename = lib3270_build_data_filename("colors.conf"); + lib3270_autoptr(char) filename = lib3270_build_data_filename("colors.conf",NULL); #endif // DEBUG if(!g_file_test(filename,G_FILE_TEST_IS_REGULAR)) diff --git a/src/dialogs/print/begin.c b/src/dialogs/print/begin.c index 95d00a9..2cd5636 100644 --- a/src/dialogs/print/begin.c +++ b/src/dialogs/print/begin.c @@ -41,8 +41,7 @@ // Setup FONT if(!operation->font.name) { - operation->font.name = g_strdup("monospace"); - debug("No font, assuming %s !!!!!!!!!!!!!!!!!!!!!!!!!!",operation->font.name); + operation->font.name = g_strdup(v3270_get_default_font_name()); g_warning("No font, assuming %s",operation->font.name); } @@ -85,9 +84,9 @@ operation->font.info.width++; - operation->font.info.left = (gtk_print_context_get_width(context)- (operation->font.info.width * operation->contents.width))/2; - if(operation->font.info.left < 2) - operation->font.info.left = 2; + operation->font.info.margin.left = (gtk_print_context_get_width(context)- (operation->font.info.width * operation->contents.width))/2; + if(operation->font.info.margin.left < 2) + operation->font.info.margin.left = 2; // Setup page size operation->lpp = (gtk_print_context_get_height(context) / (extents.height + extents.descent)); diff --git a/src/dialogs/print/draw.c b/src/dialogs/print/draw.c index 3c59fd7..d42aeba 100644 --- a/src/dialogs/print/draw.c +++ b/src/dialogs/print/draw.c @@ -29,6 +29,7 @@ #include "private.h" #include + #include #include /*--[ Implement ]------------------------------------------------------------------------------------*/ @@ -86,7 +87,7 @@ gdk_cairo_set_source_rgba(cr,operation->settings.colors + V3270_COLOR_BACKGROUND); cairo_rectangle( cr, - operation->font.info.left-1,0, + operation->font.info.margin.left-1,0, (rect.width * operation->contents.width) + 4, (rect.height * operation->contents.height) + 4 ); @@ -111,7 +112,7 @@ // Draw columns size_t pos = (row * selection->bounds.width); size_t col; - rect.x = operation->font.info.left; + rect.x = operation->font.info.margin.left; debug("Drawing: %u row=%u selection=%p pos=%u", (unsigned int) drawing, row, selection, (unsigned int) pos); diff --git a/src/dialogs/print/private.h b/src/dialogs/print/private.h index 841f649..21525c7 100644 --- a/src/dialogs/print/private.h +++ b/src/dialogs/print/private.h @@ -31,6 +31,7 @@ #include #include #include + #include /*--[ Widget definition ]----------------------------------------------------------------------------*/ diff --git a/src/include/internals.h b/src/include/internals.h index 31568fd..2419550 100644 --- a/src/include/internals.h +++ b/src/include/internals.h @@ -157,11 +157,47 @@ G_GNUC_INTERNAL GtkWidget * v3270_charset_combo_box_new(); + +/*--[ Font Info ]------------------------------------------------------------------------------------*/ + + typedef struct _v3270FontInfo { + + double size; ///< @brief Current font size. + double step; ///< @brief Steps for zoom in/out. + + guint width; + guint height; + guint ascent; + guint descent; + + guint spacing; + + struct + { + gint left; + gint top; + + } margin; + + gchar * family; + cairo_font_face_t * face; + cairo_font_weight_t weight; + cairo_scaled_font_t * scaled; + + } v3270FontInfo; + +G_GNUC_INTERNAL void v3270_font_info_init(v3270FontInfo *info); +G_GNUC_INTERNAL void v3270_font_info_unset(v3270FontInfo *info); + +G_GNUC_INTERNAL void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, v3270FontInfo *font, GdkRectangle *rect, GdkRGBA *color); + /*--[ Internal Methods ]-----------------------------------------------------------------------------*/ const GtkWidgetClass * v3270_get_parent_class(void); + G_GNUC_INTERNAL void v3270_reconfigure(v3270 * terminal); + 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); @@ -209,6 +245,8 @@ G_GNUC_INTERNAL void v3270_start_timer(GtkWidget *terminal); G_GNUC_INTERNAL void v3270_stop_timer(GtkWidget *terminal); + G_GNUC_INTERNAL void v3270_redraw(v3270 *terminal, cairo_t * cr, gint width, gint height); + G_GNUC_INTERNAL void v3270_draw_connection(cairo_t *cr, H3270 *host, v3270FontInfo *metrics, GdkRGBA *color, const GdkRectangle *rect); G_GNUC_INTERNAL void v3270_draw_ssl_status(v3270 *widget, cairo_t *cr, GdkRectangle *rect); diff --git a/src/include/terminal.h b/src/include/terminal.h index fbfb32e..60360ec 100644 --- a/src/include/terminal.h +++ b/src/include/terminal.h @@ -108,12 +108,14 @@ G_BEGIN_DECLS int scaled_fonts : 1; /**< Use scaled fonts */ int drawing : 1; /**< Draw widget? */ + /* #if GTK_CHECK_VERSION(3,0,0) #else gint width; gint height; #endif // GTK_CHECK_VERSION(3,0,0) + */ GSource * timer; GtkIMContext * input_method; @@ -135,10 +137,6 @@ G_BEGIN_DECLS cairo_surface_t * surface; v3270FontInfo font; - struct { - double step; ///< @brief Steps for zoom in/out. - } zoom; - gint minimum_width; gint minimum_height; diff --git a/src/include/v3270.h b/src/include/v3270.h index 67cf735..60266d3 100644 --- a/src/include/v3270.h +++ b/src/include/v3270.h @@ -63,25 +63,6 @@ typedef struct _v3270 v3270; typedef struct _v3270Class v3270Class; - typedef struct _v3270FontInfo { - - guint width; - guint height; - guint ascent; - guint descent; - - guint spacing; - - guint left; - guint top; - - gchar * family; - cairo_font_face_t * face; - cairo_font_weight_t weight; - cairo_scaled_font_t * scaled; - - } v3270FontInfo; - enum V3270_COLOR { V3270_COLOR_BACKGROUND, @@ -218,7 +199,6 @@ LIB3270_EXPORT void v3270_set_color_table(GdkRGBA *table, const gchar *colors); LIB3270_EXPORT const GdkRGBA * v3270_get_color_table(GtkWidget *widget); LIB3270_EXPORT void v3270_set_mono_color_table(GdkRGBA *table, const gchar *fg, const gchar *bg); - LIB3270_EXPORT void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, v3270FontInfo *font, GdkRectangle *rect, GdkRGBA *color); LIB3270_EXPORT void v3270_set_color(GtkWidget *widget, enum V3270_COLOR id, const GdkRGBA *color); LIB3270_EXPORT GdkRGBA * v3270_get_color(GtkWidget *widget, enum V3270_COLOR id); @@ -277,6 +257,9 @@ // Misc LIB3270_EXPORT int v3270_exec_command(GtkWidget *widget, const gchar *cmdline); + LIB3270_EXPORT void v3270_zoom_best(GtkWidget *widget); + LIB3270_EXPORT void v3270_zoom_in(GtkWidget *widget); + LIB3270_EXPORT void v3270_zoom_out(GtkWidget *widget); // Convenience LIB3270_EXPORT void gtk_entry_set_printf(GtkEntry *entry, const gchar *fmt, ...) G_GNUC_PRINTF(2,3); diff --git a/src/terminal/accessible.c b/src/terminal/accessible.c index b738261..fc092a0 100644 --- a/src/terminal/accessible.c +++ b/src/terminal/accessible.c @@ -325,8 +325,8 @@ static void v3270_accessible_get_character_extents( AtkText *text, gdk_window_get_origin(window, x, y); // Get screen position - *x += widget->font.left + ((offset%cols) * widget->font.width); - *y += widget->font.top + ((offset/cols) * widget->font.spacing); + *x += widget->font.margin.left + ((offset%cols) * widget->font.width); + *y += widget->font.margin.top + ((offset/cols) * widget->font.spacing); *width = widget->font.width; *height = widget->font.spacing; diff --git a/src/terminal/draw.c b/src/terminal/draw.c index 27ff578..c3160cf 100644 --- a/src/terminal/draw.c +++ b/src/terminal/draw.c @@ -122,7 +122,7 @@ static void get_element_colors(unsigned short attr, GdkRGBA **fg, GdkRGBA **bg, } } -LIB3270_EXPORT void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, v3270FontInfo *fontInfo, GdkRectangle *rect, GdkRGBA *color) +void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, v3270FontInfo *fontInfo, GdkRectangle *rect, GdkRGBA *color) { GdkRGBA *fg; GdkRGBA *bg; @@ -341,55 +341,40 @@ cairo_surface_t *gdk_window_create_similar_surface(GdkWindow *window, cairo_cont } #endif // GTK_CHECK_VERSION(2, 22, 0) -LIB3270_EXPORT void v3270_reload(GtkWidget *widget) +/// @brief Draw terminal contents. +/// +/// @param terminal Terminal widget. +/// @param cr a cairo context. +/// @param width the width of the rectangle. +/// @param height the height of the rectangle. +/// +void v3270_redraw(v3270 *terminal, cairo_t * cr, gint width, gint height) { - v3270 * terminal = GTK_V3270(widget); - - gint width = gtk_widget_get_allocated_width(widget); - gint height = gtk_widget_get_allocated_height(widget); - + unsigned int rows, cols, r; GdkRectangle rect; int addr, cursor; - unsigned int rows, cols, r; - - cairo_t * cr; - - if(!(gtk_widget_get_realized(widget) && terminal->drawing)) - { - return; - } - - // Create new terminal image - if(terminal->surface) - cairo_surface_destroy(terminal->surface); - - terminal->surface = (cairo_surface_t *) gdk_window_create_similar_surface(gtk_widget_get_window(widget),CAIRO_CONTENT_COLOR,width,height); - - // Update the created image - cr = cairo_create(terminal->surface); - v3270_compute_font_size(terminal, cr, width, height); - v3270_update_font_metrics(terminal, width, height); gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_BACKGROUND); cairo_rectangle(cr, 0, 0, width, height); cairo_fill(cr); cairo_stroke(cr); - // Draw terminal contents lib3270_get_screen_size(terminal->host,&rows,&cols); memset(&rect,0,sizeof(rect)); - rect.y = terminal->font.top; + rect.y = terminal->font.margin.top; rect.width = terminal->font.width; rect.height = terminal->font.spacing; addr = 0; cursor = lib3270_get_cursor_address(terminal->host); + cairo_set_scaled_font(cr,terminal->font.scaled); + for(r = 0; r < rows; r++) { unsigned int c; - rect.x = terminal->font.left; + rect.x = terminal->font.margin.left; for(c=0;c < cols;c++) { @@ -410,11 +395,47 @@ LIB3270_EXPORT void v3270_reload(GtkWidget *widget) } - cairo_set_scaled_font(cr,terminal->font.scaled); v3270_draw_oia(terminal, cr, rect.y, cols); +} + +LIB3270_EXPORT void v3270_reload(GtkWidget *widget) +{ + v3270 * terminal = GTK_V3270(widget); + + if(!(gtk_widget_get_realized(widget) && terminal->drawing)) + return; + + gint width = gtk_widget_get_allocated_width(widget); + gint height = gtk_widget_get_allocated_height(widget); + + cairo_t * cr = cairo_create(terminal->surface); + + v3270_redraw(terminal, cr, width, height); + cairo_destroy(cr); + /* + v3270 * terminal = GTK_V3270(widget); + cairo_t * cr; + + + + // Create new terminal image + if(terminal->surface) + cairo_surface_destroy(terminal->surface); + + terminal->surface = (cairo_surface_t *) gdk_window_create_similar_surface(gtk_widget_get_window(widget),CAIRO_CONTENT_COLOR,width,height); + + // Update the created image + cr = cairo_create(terminal->surface); + v3270_compute_font_size(terminal, cr, width, height); + v3270_update_font_metrics(terminal, width, height); + + v3270_redraw(terminal, cr, width, height); + + cairo_destroy(cr); + */ } 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 lib3270_get_screen_size(terminal->host,&rows,&cols); memset(&rect,0,sizeof(rect)); - rect.x = terminal->font.left + ((addr % cols) * terminal->font.width); - rect.y = terminal->font.top + ((addr / cols) * terminal->font.spacing); + rect.x = terminal->font.margin.left + ((addr % cols) * terminal->font.width); + rect.y = terminal->font.margin.top + ((addr / cols) * terminal->font.spacing); rect.width = terminal->font.width; rect.height = terminal->font.spacing; diff --git a/src/terminal/font/actions.c b/src/terminal/font/actions.c new file mode 100644 index 0000000..c8b861f --- /dev/null +++ b/src/terminal/font/actions.c @@ -0,0 +1,137 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include + #include "private.h" + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + +/* +static void update_font_size(v3270 * terminal, cairo_t *cr, gint width, gint height, int step) +{ + + + cairo_set_font_face(cr,terminal->font.face); + + cairo_set_font_size(cr,terminal->font.size); + + v3270_update_font_metrics(terminal, width, height); + + if(terminal->font.scaled) + cairo_scaled_font_destroy(terminal->font.scaled); + + terminal->font.scaled = cairo_get_scaled_font(cr); + cairo_scaled_font_reference(terminal->font.scaled); + + v3270_redraw(terminal, cr, width, height); + + gtk_widget_queue_draw(GTK_WIDGET(terminal)); + +} +*/ + +void v3270_zoom_best(GtkWidget *widget) +{ + debug("%s",__FUNCTION__); + + g_return_if_fail(GTK_IS_V3270(widget)); + v3270 * terminal = GTK_V3270(widget); + if(!(gtk_widget_get_realized(widget) && terminal->drawing && lib3270_is_connected(terminal->host))) + { + gdk_display_beep(gdk_display_get_default()); + return; + } + + gint width = gtk_widget_get_allocated_width(widget); + gint height = gtk_widget_get_allocated_height(widget); + + cairo_t *cr = cairo_create(terminal->surface); + + v3270_compute_font_size(terminal, cr, width, height); + v3270_update_font_metrics(terminal, width, height); + + v3270_redraw(terminal, cr, width, height); + + cairo_destroy(cr); + + gtk_widget_queue_draw(widget); + +} + +static void zoom(GtkWidget *widget, double step) +{ + debug("%s",__FUNCTION__); + + g_return_if_fail(GTK_IS_V3270(widget)); + v3270 * terminal = GTK_V3270(widget); + if(!(gtk_widget_get_realized(widget) && terminal->drawing && lib3270_is_connected(terminal->host))) + { + gtk_widget_error_bell(widget); + return; + } + + terminal->font.size += step; + + // Redraw window + + gint width = gtk_widget_get_allocated_width(widget); + gint height = gtk_widget_get_allocated_height(widget); + + cairo_t *cr = cairo_create(terminal->surface); + + cairo_set_font_face(cr,terminal->font.face); + cairo_set_font_size(cr,terminal->font.size); + + v3270_update_font_metrics(terminal, width, height); + + if(terminal->font.scaled) + cairo_scaled_font_destroy(terminal->font.scaled); + + terminal->font.scaled = cairo_get_scaled_font(cr); + cairo_scaled_font_reference(terminal->font.scaled); + + v3270_redraw(terminal, cr, width, height); + + cairo_destroy(cr); + + gtk_widget_queue_draw(GTK_WIDGET(terminal)); + +} + +void v3270_zoom_in(GtkWidget *widget) +{ + zoom(widget,1); +} + +void v3270_zoom_out(GtkWidget *widget) +{ + debug("%s",__FUNCTION__); + zoom(widget,-1); +} + diff --git a/src/terminal/font/compute.c b/src/terminal/font/compute.c index 0bdeaa0..5c53076 100644 --- a/src/terminal/font/compute.c +++ b/src/terminal/font/compute.c @@ -67,27 +67,25 @@ cairo_set_font_face(cr,terminal->font.face); { - double s = terminal->zoom.step; - double selected = 0; + double s = terminal->font.step; do { - selected = s; + terminal->font.size = s; - s += terminal->zoom.step; + s += terminal->font.step; cairo_set_font_size(cr,s); cairo_font_extents(cr,&extents); } while( (VIEW_HEIGTH_FROM_FONT( (extents.height+extents.descent) ) < height) && (VIEW_WIDTH_FROM_FONT(extents.max_x_advance) < width) ); - debug("Selected size=%lf",selected); - - cairo_set_font_size(cr,selected); - cairo_font_extents(cr,&extents); + debug("Selected size=%lf",terminal->font.size); } // Save scaled font for use on next drawings + cairo_set_font_size(cr,terminal->font.size); + if(terminal->font.scaled) cairo_scaled_font_destroy(terminal->font.scaled); diff --git a/src/terminal/font/info.c b/src/terminal/font/info.c new file mode 100644 index 0000000..141908c --- /dev/null +++ b/src/terminal/font/info.c @@ -0,0 +1,63 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include + #include "private.h" + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + +void v3270_font_info_init(v3270FontInfo *info) +{ + memset(info,0,sizeof(v3270FontInfo)); + + info->family = g_strdup(v3270_get_default_font_name()); + info->step = 0.1; + info->size = 0.1; +} + +void v3270_font_info_unset(v3270FontInfo *info) +{ + if(info->family) + { + g_free(info->family); + info->family = NULL; + } + + if(info->scaled) + { + cairo_scaled_font_destroy(info->scaled); + info->scaled = NULL; + } + + if(info->face) { + cairo_font_face_destroy(info->face); + info->face = NULL; + } + +} diff --git a/src/terminal/font/metrics.c b/src/terminal/font/metrics.c index 60b44c8..9e5667c 100644 --- a/src/terminal/font/metrics.c +++ b/src/terminal/font/metrics.c @@ -67,12 +67,16 @@ void v3270_update_font_metrics(v3270 *terminal, unsigned int width, unsigned int // Center image size = VIEW_WIDTH_FROM_FONT(terminal->font.width); - terminal->font.left = ((width - size) / 2); + terminal->font.margin.left = (width/2) - (size/2); + + debug("%d",(width - size)); size = VIEW_HEIGTH_FROM_FONT(terminal->font.spacing); - terminal->font.top = ((height - size) /2); + terminal->font.margin.top = (height/2) - (size/2); + + debug("%d",(height - size)); - debug("screen_height=%u content_height=%u top=%d",height, size, terminal->font.top); + 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); } diff --git a/src/terminal/font/private.h b/src/terminal/font/private.h index 1627302..870a845 100644 --- a/src/terminal/font/private.h +++ b/src/terminal/font/private.h @@ -29,6 +29,7 @@ #include #include + #include #include #include #include diff --git a/src/terminal/mouse.c b/src/terminal/mouse.c index 533dc9d..3ec409a 100644 --- a/src/terminal/mouse.c +++ b/src/terminal/mouse.c @@ -55,8 +55,8 @@ gint v3270_get_offset_at_point(v3270 *widget, gint x, gint y) if(x > 0 && y > 0) { - point.x = ((x-widget->font.left)/widget->font.width); - point.y = ((y-widget->font.top)/widget->font.spacing); + point.x = ((x-widget->font.margin.left)/widget->font.width); + point.y = ((y-widget->font.margin.top)/widget->font.spacing); lib3270_get_screen_size(widget->host,&r,&c); diff --git a/src/terminal/oia.c b/src/terminal/oia.c index 2f360e1..b634a3d 100644 --- a/src/terminal/oia.c +++ b/src/terminal/oia.c @@ -581,18 +581,18 @@ void v3270_draw_oia(v3270 *terminal, cairo_t *cr, int row, int cols) }; int f; - int rCol = terminal->font.left+(cols*terminal->font.width); - int lCol = terminal->font.left+1; + int rCol = terminal->font.margin.left+(cols*terminal->font.width); + int lCol = terminal->font.margin.left+1; row += OIA_TOP_MARGIN; gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_SEPARATOR); - cairo_rectangle(cr, terminal->font.left, row, cols*terminal->font.width, 1); + cairo_rectangle(cr, terminal->font.margin.left, row, cols*terminal->font.width, 1); cairo_fill(cr); row += 2; gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_OIA_BACKGROUND); - cairo_rectangle(cr, terminal->font.left, row, cols*terminal->font.width, terminal->font.spacing); + cairo_rectangle(cr, terminal->font.margin.left, row, cols*terminal->font.width, terminal->font.spacing); cairo_fill(cr); 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, // Update cursor rectangle saved = terminal->cursor.rect; - terminal->cursor.rect.x = terminal->font.left + (col * terminal->cursor.rect.width); - terminal->cursor.rect.y = terminal->font.top + (row * terminal->font.spacing); + terminal->cursor.rect.x = terminal->font.margin.left + (col * terminal->cursor.rect.width); + terminal->cursor.rect.y = terminal->font.margin.top + (row * terminal->font.spacing); terminal->cursor.rect.width = terminal->font.width; terminal->cursor.rect.height = terminal->font.height+terminal->font.descent; terminal->cursor.show |= 1; diff --git a/src/terminal/surface.c b/src/terminal/surface.c new file mode 100644 index 0000000..8d40649 --- /dev/null +++ b/src/terminal/surface.c @@ -0,0 +1,86 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include + #include + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + +/** + * @brief Reconfigure widget surface. + * + * Called when the widget is resized or moved to regenerate the cairo surface: + * + * * Recreate the surface. + * * Compute the new font size & metrics. + * * Redraw contents. + * * Emite "GDK_CONFIGURE" event. + * + */ +void v3270_reconfigure(v3270 * terminal) +{ + GtkAllocation allocation; + GtkWidget *widget; + GdkEvent *event = gdk_event_new(GDK_CONFIGURE); + + widget = GTK_WIDGET(terminal); + + gtk_widget_get_allocation(widget, &allocation); + + event->configure.window = g_object_ref(gtk_widget_get_window(widget)); + event->configure.send_event = TRUE; + event->configure.x = allocation.x; + event->configure.y = allocation.y; + event->configure.width = allocation.width; + event->configure.height = allocation.height; + + if(terminal->surface) + cairo_surface_destroy(terminal->surface); + + terminal->surface = (cairo_surface_t *) gdk_window_create_similar_surface(gtk_widget_get_window(widget),CAIRO_CONTENT_COLOR,allocation.width,allocation.height); + + // Update the created image + cairo_t * cr = cairo_create(terminal->surface); + v3270_compute_font_size(terminal, cr, allocation.width, allocation.height); + v3270_update_font_metrics(terminal, allocation.width, allocation.height); + + v3270_redraw(terminal, cr, allocation.width, allocation.height); + + cairo_destroy(cr); + +#if( !GTK_CHECK_VERSION(3,0,0)) + terminal->width = allocation.width; + terminal->height = allocation.height; +#endif + + gtk_widget_event(widget, event); + gdk_event_free(event); +} + + diff --git a/src/terminal/widget.c b/src/terminal/widget.c index 6ad690c..de5fee8 100644 --- a/src/terminal/widget.c +++ b/src/terminal/widget.c @@ -71,8 +71,6 @@ static void v3270_realize ( GtkWidget * widget) ; static void v3270_size_allocate ( GtkWidget * widget, GtkAllocation * allocation ); -static void v3270_send_configure ( v3270 * terminal ); - // Signals static void v3270_activate (GtkWidget *widget); @@ -503,9 +501,6 @@ static void v3270_init(v3270 *widget) // Setup clipboard. widget->selection.target = GDK_SELECTION_CLIPBOARD; - // Setup zoom - widget->zoom.step = 0.1; - // Reset timer widget->activity.timestamp = time(0); widget->activity.disconnect = 0; @@ -532,7 +527,7 @@ static void v3270_init(v3270 *widget) widget->drawing = 1; // Set defaults - widget->font.family = g_strdup(v3270_get_default_font_name()); + v3270_font_info_init(&widget->font); v3270_set_color_table(widget->color,v3270_default_colors); } @@ -562,22 +557,7 @@ static void v3270_destroy(GtkWidget *widget) terminal->accessible = NULL; } - if(terminal->font.family) - { - g_free(terminal->font.family); - terminal->font.family = 0; - } - - if(terminal->font.scaled) - { - cairo_scaled_font_destroy(terminal->font.scaled); - terminal->font.scaled = NULL; - } - - if(terminal->font.face) { - cairo_font_face_destroy(terminal->font.face); - terminal->font.face = NULL; - } + v3270_font_info_unset(&terminal->font); if(terminal->surface) { @@ -736,9 +716,7 @@ static void v3270_realize(GtkWidget * widget) gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); #endif // !GTK3 - v3270_reload(widget); - - v3270_send_configure(GTK_V3270(widget)); + v3270_reconfigure(GTK_V3270(widget)); if(!GTK_V3270(widget)->cursor.timer) { @@ -776,8 +754,8 @@ static void v3270_size_allocate(GtkWidget * widget, GtkAllocation * allocation) if(gtk_widget_get_has_window(widget)) gdk_window_move_resize(gtk_widget_get_window (widget),allocation->x, allocation->y,allocation->width, allocation->height); - v3270_reload(widget); - v3270_send_configure(GTK_V3270(widget)); + v3270_reconfigure(GTK_V3270(widget)); + } } @@ -789,32 +767,6 @@ G_GNUC_INTERNAL void gtk_widget_get_allocation(GtkWidget *widget, GtkAllocation #endif // !GTK(2,18) -static void v3270_send_configure(v3270 * terminal) -{ - GtkAllocation allocation; - GtkWidget *widget; - GdkEvent *event = gdk_event_new(GDK_CONFIGURE); - - widget = GTK_WIDGET(terminal); - - gtk_widget_get_allocation(widget, &allocation); - - event->configure.window = g_object_ref(gtk_widget_get_window(widget)); - event->configure.send_event = TRUE; - event->configure.x = allocation.x; - event->configure.y = allocation.y; - event->configure.width = allocation.width; - event->configure.height = allocation.height; - -#if( !GTK_CHECK_VERSION(3,0,0)) - terminal->width = allocation.width; - terminal->height = allocation.height; -#endif - - gtk_widget_event(widget, event); - gdk_event_free(event); -} - LIB3270_EXPORT void v3270_disconnect(GtkWidget *widget) { g_return_if_fail(GTK_IS_V3270(widget)); diff --git a/src/testprogram/toolbar.c b/src/testprogram/toolbar.c index 6fa6bc3..1bc5944 100644 --- a/src/testprogram/toolbar.c +++ b/src/testprogram/toolbar.c @@ -178,6 +178,21 @@ } + static void zoom_in_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal) + { + v3270_zoom_in(terminal); + } + + static void zoom_out_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal) + { + v3270_zoom_out(terminal); + } + + static void zoom_best_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal) + { + v3270_zoom_best(terminal); + } + GtkWidget * create_toolbar(GtkWidget *terminal) { size_t f; @@ -199,6 +214,9 @@ { "document-save", G_CALLBACK(save_all_clicked), "Save screen" }, { "document-open", G_CALLBACK(load_clicked), "Paste file" }, + { "zoom-in", G_CALLBACK(zoom_in_clicked), "Zoom in" }, + { "zoom-out", G_CALLBACK(zoom_out_clicked), "Zoom out" }, + { "zoom-fit-best", G_CALLBACK(zoom_best_clicked), "Zoom best" }, }; GtkWidget * toolbar = gtk_toolbar_new(); diff --git a/v3270.cbp b/v3270.cbp index faac10a..f84864c 100644 --- a/v3270.cbp +++ b/v3270.cbp @@ -217,9 +217,15 @@ + + + + @@ -262,6 +268,9 @@ + + -- libgit2 0.21.2