Commit 6904622ddbabbf24771b19e1873715f25e3d5128

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

Implementing selection as pixbuf

src/dialogs/save/save.c
... ... @@ -446,7 +446,46 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_
446 446 {
447 447 debug("%s",__FUNCTION__);
448 448  
449   - GdkPixbuf * pixbuf = v3270_get_as_pixbuf(dialog->terminal);
  449 + GdkPixbuf * pixbuf = NULL;
  450 +
  451 + switch(dialog->mode)
  452 + {
  453 + case LIB3270_CONTENT_ALL:
  454 + debug("%s","LIB3270_CONTENT_ALL");
  455 +#ifdef DEBUG
  456 + {
  457 + debug("%s","LIB3270_CONTENT_SELECTED");
  458 + GList * selection = g_list_append_lib3270_selection(NULL, v3270_get_session(dialog->terminal),TRUE);
  459 + pixbuf = v3270_get_selection_as_pixbuf(GTK_V3270(dialog->terminal), selection, TRUE);
  460 + g_list_free_full(selection,(GDestroyNotify) lib3270_free);
  461 + }
  462 +#else
  463 + pixbuf = v3270_get_as_pixbuf(dialog->terminal);
  464 +#endif // DEBUG
  465 +
  466 + break;
  467 +
  468 + case LIB3270_CONTENT_COPY:
  469 + {
  470 + debug("%s","LIB3270_CONTENT_COPY");
  471 + const GList * selection = v3270_get_selection_blocks(dialog->terminal);
  472 + pixbuf = v3270_get_selection_as_pixbuf(GTK_V3270(dialog->terminal), selection, FALSE);
  473 + }
  474 + break;
  475 +
  476 + case LIB3270_CONTENT_SELECTED:
  477 + {
  478 + debug("%s","LIB3270_CONTENT_SELECTED");
  479 + GList * selection = g_list_append_lib3270_selection(NULL, v3270_get_session(dialog->terminal),FALSE);
  480 + pixbuf = v3270_get_selection_as_pixbuf(GTK_V3270(dialog->terminal), selection, FALSE);
  481 + g_list_free_full(selection,(GDestroyNotify) lib3270_free);
  482 + }
  483 + break;
  484 +
  485 + default:
  486 + *error = g_error_new(g_quark_from_static_string(PACKAGE_NAME),ENOTCONN,_( "Unexpected mode %d" ),(int) dialog->mode);
  487 + return;
  488 + }
450 489  
451 490 if(pixbuf)
452 491 {
... ...
src/include/clipboard.h
... ... @@ -91,6 +91,7 @@
91 91  
92 92 /// @brief Get contents.
93 93 G_GNUC_INTERNAL gchar * v3270_get_selection_as_text(v3270 * terminal, const GList *selection, const gchar *encoding, gboolean all);
  94 + G_GNUC_INTERNAL GdkPixbuf * v3270_get_selection_as_pixbuf(v3270 * terminal, const GList *selection, gboolean all);
94 95 G_GNUC_INTERNAL gchar * v3270_get_selection_as_table(v3270 * terminal, const GList *selection, const gchar *delimiter, const gchar *encoding, gboolean all);
95 96 G_GNUC_INTERNAL gchar * v3270_get_selection_as_html_div(v3270 * terminal, const GList *selection, const gchar *encoding, gboolean all, const V3270SelectionOption options);
96 97 G_GNUC_INTERNAL gchar * v3270_get_selection_as_html_table(v3270 * terminal, const GList *selection, const gchar *encoding, gboolean all, const V3270SelectionOption options);
... ...
src/selection/pixbuf.c 0 → 100644
... ... @@ -0,0 +1,141 @@
  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 <clipboard.h>
  31 + #include <lib3270/selection.h>
  32 + #include <v3270/dialogs.h>
  33 +
  34 +/*--[ Implement ]------------------------------------------------------------------------------------*/
  35 +
  36 +GdkPixbuf * v3270_get_selection_as_pixbuf(v3270 * terminal, const GList *selections, gboolean all)
  37 +{
  38 + const GList *selection;
  39 +
  40 + // Get image size
  41 + size_t rows = 0, cols = 0;
  42 +
  43 + for(selection = selections; selection; selection = g_list_next(selection))
  44 + {
  45 + lib3270_selection * block = ((lib3270_selection *) selection->data);
  46 + unsigned int row, col, src = 0;
  47 +
  48 + for(row=0; row < block->bounds.height; row++)
  49 + {
  50 + size_t hasSelection = FALSE;
  51 +
  52 + for(col=0; col<block->bounds.width; col++)
  53 + {
  54 + if( (block->contents[src].attribute.visual & LIB3270_ATTR_SELECTED) || all )
  55 + {
  56 + hasSelection = TRUE;
  57 + if(col > cols)
  58 + cols = col;
  59 + }
  60 + }
  61 +
  62 + if(hasSelection)
  63 + {
  64 + rows++;
  65 + }
  66 +
  67 + }
  68 +
  69 + }
  70 +
  71 + if(!rows)
  72 + return NULL;
  73 +
  74 + debug("Selection rows=%u cols=%u",(unsigned int) rows, (unsigned int) cols);
  75 +
  76 + gint width = (cols+1) * terminal->font.width;
  77 + gint height = (rows+1) * terminal->font.spacing.value;
  78 +
  79 + cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
  80 +
  81 + cairo_t *cr = cairo_create(surface);
  82 + gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_BACKGROUND);
  83 + cairo_rectangle(cr, 0, 0, width, height);
  84 + cairo_fill(cr);
  85 + cairo_stroke(cr);
  86 +
  87 + // Draw contents
  88 + GdkRectangle rect;
  89 + memset(&rect,0,sizeof(rect));
  90 + rect.width = terminal->font.width;
  91 + rect.height = terminal->font.spacing.value;
  92 +
  93 + cairo_set_scaled_font(cr,terminal->font.scaled);
  94 +
  95 + for(selection = selections; selection; selection = g_list_next(selection))
  96 + {
  97 + lib3270_selection * block = ((lib3270_selection *) selection->data);
  98 + unsigned int row, col, src = 0;
  99 +
  100 + for(row=0; row < block->bounds.height; row++)
  101 + {
  102 + size_t hasSelection = FALSE;
  103 + rect.x = 0;
  104 +
  105 + for(col=0; col<block->bounds.width; col++)
  106 + {
  107 + if( (block->contents[src].attribute.visual & LIB3270_ATTR_SELECTED) || all )
  108 + {
  109 + hasSelection = TRUE;
  110 +
  111 + v3270_draw_element(
  112 + cr,
  113 + block->contents[src].chr,
  114 + block->contents[src].attribute.visual,
  115 + terminal->host,
  116 + &terminal->font,
  117 + &rect,
  118 + terminal->color
  119 + );
  120 +
  121 + }
  122 + rect.x += rect.width;
  123 + }
  124 +
  125 + if(hasSelection)
  126 + {
  127 + rect.y += terminal->font.spacing.value;
  128 + }
  129 +
  130 + }
  131 + }
  132 +
  133 + cairo_destroy (cr);
  134 +
  135 + GdkPixbuf * pixbuf = gdk_pixbuf_get_from_surface(surface,0,0,width,height);
  136 +
  137 + cairo_surface_destroy (surface);
  138 +
  139 + return pixbuf;
  140 +
  141 +}
... ...
v3270.cbp
... ... @@ -219,6 +219,9 @@
219 219 <Unit filename="src/selection/linux/paste.c">
220 220 <Option compilerVar="CC" />
221 221 </Unit>
  222 + <Unit filename="src/selection/pixbuf.c">
  223 + <Option compilerVar="CC" />
  224 + </Unit>
222 225 <Unit filename="src/selection/selection.c">
223 226 <Option compilerVar="CC" />
224 227 </Unit>
... ...