Commit ec7b14ef70163fbafa4a839d5ba824cbd839e672

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

Working on the new v3270 print dialog component.

@@ -34,7 +34,8 @@ SOURCES= \ @@ -34,7 +34,8 @@ SOURCES= \
34 $(wildcard src/v3270/@OSNAME@/*.c) \ 34 $(wildcard src/v3270/@OSNAME@/*.c) \
35 $(wildcard src/v3270ft/*.c) \ 35 $(wildcard src/v3270ft/*.c) \
36 $(wildcard src/trace/*.c) \ 36 $(wildcard src/trace/*.c) \
37 - $(wildcard src/dialogs/*.c) 37 + $(wildcard src/dialogs/*.c) \
  38 + $(wildcard src/dialogs/print/*.c)
38 39
39 TEST_SOURCES= \ 40 TEST_SOURCES= \
40 $(wildcard src/testprogram/*.c) 41 $(wildcard src/testprogram/*.c)
src/dialogs/print/begin.c 0 → 100644
@@ -0,0 +1,144 @@ @@ -0,0 +1,144 @@
  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 "private.h"
  31 +
  32 +/*--[ Implement ]------------------------------------------------------------------------------------*/
  33 +
  34 + void V3270PrintOperation_begin_print(GtkPrintOperation *prt, GtkPrintContext *context)
  35 + {
  36 + cairo_t * cr = gtk_print_context_get_cairo_context(context);
  37 + V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(prt);
  38 +
  39 + trace("%s",__FUNCTION__);
  40 +
  41 + // Setup FONT
  42 + PangoFontDescription * fontDescription = pango_font_description_from_string(operation->font.name);
  43 +
  44 + cairo_select_font_face(
  45 + cr,
  46 + pango_font_description_get_family(fontDescription),
  47 + CAIRO_FONT_SLANT_NORMAL,
  48 + pango_font_description_get_weight(fontDescription) == PANGO_WEIGHT_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL
  49 + );
  50 +
  51 + // Set font size based on text and context.
  52 +
  53 + cairo_font_extents_t extents;
  54 + double width = gtk_print_context_get_width(context);
  55 + double cols = (double) operation->text.width;
  56 + double current = width / cols;
  57 + double valid = current;
  58 +
  59 + do
  60 + {
  61 + valid = current;
  62 + current = valid +1.0;
  63 + cairo_set_font_size(cr,current);
  64 + cairo_font_extents(cr,&extents);
  65 + }
  66 + while( (cols * extents.max_x_advance) < width );
  67 +
  68 + trace("Font size: %d",(int) valid);
  69 + cairo_set_font_size(cr,valid);
  70 +
  71 +
  72 + /*
  73 +
  74 + gchar * font = get_string_from_config("print",FONT_CONFIG,DEFAULT_FONT);
  75 +
  76 + trace("%s: operation=%p context=%p font=\"%s\"",__FUNCTION__,prt,context,font);
  77 +
  78 + // Setup font
  79 + if(*font)
  80 + {
  81 + PangoFontDescription * descr = pango_font_description_from_string(font);
  82 + if(descr)
  83 + {
  84 + cairo_select_font_face(cr, pango_font_description_get_family(descr),
  85 + CAIRO_FONT_SLANT_NORMAL,
  86 + pango_font_description_get_weight(descr) == PANGO_WEIGHT_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL);
  87 +
  88 +#ifdef AUTO_FONT_SIZE
  89 + {
  90 + double width = gtk_print_context_get_width(context);
  91 +#if GTK_CHECK_VERSION(3,0,0)
  92 + double cols = (double) info->cols;
  93 +#else
  94 + double cols = (double) (info->cols+5);
  95 +#endif // GTK(3,0,0)
  96 + double current = width / cols;
  97 + double valid = current;
  98 +
  99 + do
  100 + {
  101 + valid = current;
  102 + current = valid +1.0;
  103 + cairo_set_font_size(cr,current);
  104 + cairo_font_extents(cr,&extents);
  105 + }
  106 + while( (cols * extents.max_x_advance) < width );
  107 +
  108 + trace("Font size: %d",(int) valid);
  109 + cairo_set_font_size(cr,valid);
  110 +
  111 + }
  112 +#endif // AUTO_FONT_SIZE
  113 +
  114 + pango_font_description_free(descr);
  115 + }
  116 + }
  117 + g_free(font);
  118 +
  119 + info->font.scaled = cairo_get_scaled_font(cr);
  120 + cairo_scaled_font_reference(info->font.scaled);
  121 + cairo_scaled_font_extents(info->font.scaled,&extents);
  122 +
  123 + info->font.height = extents.height;
  124 + info->font.descent = extents.descent;
  125 + info->font.width = extents.max_x_advance;
  126 +
  127 + info->width = ((double) info->cols) * extents.max_x_advance;
  128 + info->height = ((double) info->rows) * (extents.height + extents.descent);
  129 +
  130 + // Center image
  131 + info->left = (gtk_print_context_get_width(context)-info->width)/2;
  132 + if(info->left < 2)
  133 + info->left = 2;
  134 +
  135 + // Setup page size
  136 + info->lpp = (gtk_print_context_get_height(context) / (extents.height + extents.descent));
  137 + info->pages = (info->rows / info->lpp)+1;
  138 +
  139 + trace("%d lines per page, %d pages to print",info->lpp,info->pages);
  140 +
  141 + gtk_print_operation_set_n_pages(prt,info->pages);
  142 + */
  143 + }
  144 +
src/dialogs/print/print.c 0 → 100644
@@ -0,0 +1,215 @@ @@ -0,0 +1,215 @@
  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 "private.h"
  31 + #include "../../v3270/private.h" // Required for v3270 signal.
  32 + #include <v3270/colorscheme.h>
  33 + #include <lib3270/selection.h>
  34 +
  35 + G_DEFINE_TYPE(V3270PrintOperation, V3270PrintOperation, GTK_TYPE_PRINT_OPERATION);
  36 +
  37 +/*--[ Implement ]------------------------------------------------------------------------------------*/
  38 +
  39 + static void done(GtkPrintOperation *prt, GtkPrintOperationResult result)
  40 + {
  41 + V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(prt);
  42 +
  43 + debug("%s",__FUNCTION__);
  44 +
  45 + if(operation->widget)
  46 + g_signal_emit(GTK_WIDGET(operation->widget), v3270_widget_signal[SIGNAL_PRINT_DONE], 0, prt, (guint) result);
  47 +
  48 + }
  49 +
  50 +#ifndef _WIN32
  51 + static void color_scheme_changed(GtkWidget G_GNUC_UNUSED(*widget), const GdkRGBA *colors, V3270PrintOperation *operation) {
  52 +
  53 + debug("%s=%p",__FUNCTION__,colors);
  54 +
  55 + int f;
  56 + for(f=0;f<V3270_COLOR_COUNT;f++)
  57 + operation->colors[f] = colors[f];
  58 +
  59 + }
  60 +
  61 + void font_name_changed(GtkComboBox *widget, V3270PrintOperation *operation)
  62 + {
  63 + GValue value = { 0, };
  64 + GtkTreeIter iter;
  65 +
  66 + if(!gtk_combo_box_get_active_iter(widget,&iter))
  67 + return;
  68 +
  69 + gtk_tree_model_get_value(gtk_combo_box_get_model(widget),&iter,0,&value);
  70 +
  71 + g_free(operation->font.name);
  72 + operation->font.name = g_value_dup_string(&value);
  73 +
  74 + debug("%s=%s",__FUNCTION__,operation->font.name);
  75 + }
  76 +
  77 + static GtkWidget * create_custom_widget(GtkPrintOperation *prt)
  78 + {
  79 + static const gchar * text[] =
  80 + {
  81 + N_( "_Font:" ),
  82 + N_( "C_olor scheme:" )
  83 + };
  84 +
  85 + size_t f;
  86 +
  87 + V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(prt);
  88 +
  89 + if(operation->widget)
  90 + g_signal_emit(operation->widget, v3270_widget_signal[SIGNAL_PRINT_SETUP], 0, prt);
  91 +
  92 + // Create dialog
  93 +
  94 + GtkGrid * grid = GTK_GRID(gtk_grid_new());
  95 + GtkWidget * font = v3270_font_selection_new(operation->font.name);
  96 + GtkWidget * color = v3270_color_scheme_new();
  97 +
  98 + gtk_container_set_border_width(GTK_CONTAINER(grid),10);
  99 + gtk_grid_set_row_spacing(grid,5);
  100 + gtk_grid_set_column_spacing(grid,5);
  101 +
  102 + v3270_color_scheme_set_rgba(color,operation->colors);
  103 + g_signal_connect(G_OBJECT(color),"update-colors",G_CALLBACK(color_scheme_changed),operation);
  104 + g_signal_connect(G_OBJECT(font),"changed",G_CALLBACK(font_name_changed),operation);
  105 +
  106 + for(f=0;f<G_N_ELEMENTS(text);f++)
  107 + {
  108 + GtkWidget *label = gtk_label_new_with_mnemonic(gettext(text[f]));
  109 + gtk_label_set_xalign(GTK_LABEL(label),0);
  110 + gtk_grid_attach(grid,label,0,f,1,1);
  111 + }
  112 +
  113 + gtk_grid_attach(grid,font,1,0,1,1);
  114 + gtk_grid_attach(grid,color,1,1,1,1);
  115 +
  116 + gtk_widget_show_all(GTK_WIDGET(grid));
  117 + return GTK_WIDGET(grid);
  118 + }
  119 +
  120 + static void custom_widget_apply(GtkPrintOperation *prt, GtkWidget *widget)
  121 + {
  122 + V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(prt);
  123 +
  124 + debug("%s",__FUNCTION__);
  125 +
  126 + if(operation->widget)
  127 + g_signal_emit(operation->widget, v3270_widget_signal[SIGNAL_PRINT_APPLY], 0, prt);
  128 +
  129 + }
  130 +#endif // _WIN32
  131 +
  132 + static void dispose(GObject *object)
  133 + {
  134 + debug("%s",__FUNCTION__);
  135 +
  136 + V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(object);
  137 +
  138 + g_free(operation->font.name);
  139 +
  140 + }
  141 +
  142 + static void V3270PrintOperation_class_init(V3270PrintOperationClass *klass)
  143 + {
  144 + GtkPrintOperationClass * operation = GTK_PRINT_OPERATION_CLASS(klass);
  145 +
  146 + G_OBJECT_CLASS(klass)->dispose = dispose;
  147 + operation->done = done;
  148 + operation->begin_print = V3270PrintOperation_begin_print;
  149 +
  150 +#ifndef _WIN32
  151 + operation->create_custom_widget = create_custom_widget;
  152 + operation->custom_widget_apply = custom_widget_apply;
  153 +#endif // _WIN32
  154 +
  155 + }
  156 +
  157 + static void V3270PrintOperation_init(V3270PrintOperation *widget)
  158 + {
  159 + // Setup print operation.
  160 + gtk_print_operation_set_custom_tab_label(GTK_PRINT_OPERATION(widget), _( "Options" ) );
  161 + gtk_print_operation_set_show_progress(GTK_PRINT_OPERATION(widget),TRUE);
  162 + gtk_print_operation_set_print_settings(GTK_PRINT_OPERATION(widget),gtk_print_settings_new());
  163 + gtk_print_operation_set_default_page_setup(GTK_PRINT_OPERATION(widget),gtk_page_setup_new());
  164 +
  165 +
  166 + // Setup defaults
  167 + widget->mode = LIB3270_PRINT_ALL;
  168 + widget->show_selection = FALSE;
  169 + widget->font.name = g_strdup(v3270_default_font);
  170 +
  171 + widget->text.width = 80;
  172 +
  173 + v3270_set_mono_color_table(widget->colors,"#000000","#FFFFFF");
  174 +
  175 + }
  176 +
  177 +V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_PRINT_MODE mode)
  178 +{
  179 + g_return_val_if_fail(GTK_IS_V3270(widget),NULL);
  180 +
  181 + V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(g_object_new(GTK_TYPE_V3270_PRINT_OPERATION, NULL));
  182 +
  183 + operation->mode = mode;
  184 + operation->widget = GTK_V3270(widget);
  185 + operation->session = v3270_get_session(widget);
  186 +
  187 + return operation;
  188 +}
  189 +
  190 +/*--[ Convenience ]----------------------------------------------------------------------------------*/
  191 +
  192 + void v3270_print(GtkWidget *widget, LIB3270_PRINT_MODE mode)
  193 + {
  194 + g_autoptr(GError) err = NULL;
  195 +
  196 + V3270PrintOperation * operation = v3270_print_operation_new(widget, mode);
  197 + gtk_print_operation_run(GTK_PRINT_OPERATION(operation),GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,GTK_WINDOW(gtk_widget_get_toplevel(widget)),&err);
  198 + g_object_unref(operation);
  199 +
  200 + }
  201 +
  202 + void v3270_print_all(GtkWidget *widget)
  203 + {
  204 + v3270_print(widget,LIB3270_PRINT_ALL);
  205 + }
  206 +
  207 + void v3270_print_selected(GtkWidget *widget)
  208 + {
  209 + v3270_print(widget,LIB3270_PRINT_SELECTED);
  210 + }
  211 +
  212 + void v3270_print_copy(GtkWidget *widget)
  213 + {
  214 + v3270_print(widget,LIB3270_PRINT_COPY);
  215 + }
src/dialogs/print/private.h 0 → 100644
@@ -0,0 +1,71 @@ @@ -0,0 +1,71 @@
  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 <v3270.h>
  31 + #include <v3270/print.h>
  32 + #include <lib3270/log.h>
  33 + #include <lib3270/trace.h>
  34 +
  35 +/*--[ Widget definition ]----------------------------------------------------------------------------*/
  36 +
  37 + struct _V3270PrintOperationClass
  38 + {
  39 + GtkPrintOperationClass parent_class;
  40 +
  41 + };
  42 +
  43 + struct _V3270PrintOperation
  44 + {
  45 + GtkPrintOperation parent;
  46 + GdkRGBA colors[V3270_COLOR_COUNT];
  47 + LIB3270_PRINT_MODE mode;
  48 + v3270 * widget;
  49 + H3270 * session;
  50 +
  51 + struct
  52 + {
  53 + size_t width; ///< @brief Maximun text width (in characters)
  54 +
  55 + } text;
  56 +
  57 + struct {
  58 + gchar * name;
  59 + v3270FontInfo info;
  60 + } font;
  61 +
  62 + gboolean show_selection;
  63 +
  64 +
  65 + };
  66 +
  67 +/*--[ Prototypes ]-----------------------------------------------------------------------------------*/
  68 +
  69 + G_GNUC_INTERNAL void V3270PrintOperation_begin_print(GtkPrintOperation *prt, GtkPrintContext *context);
  70 +
  71 +
src/include/v3270/print.h
@@ -38,6 +38,7 @@ @@ -38,6 +38,7 @@
38 38
39 /*--[ Print Operation ]------------------------------------------------------------------------------*/ 39 /*--[ Print Operation ]------------------------------------------------------------------------------*/
40 40
  41 +
41 #define GTK_TYPE_V3270_PRINT_OPERATION (V3270PrintOperation_get_type()) 42 #define GTK_TYPE_V3270_PRINT_OPERATION (V3270PrintOperation_get_type())
42 #define GTK_V3270_PRINT_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_V3270_PRINT_OPERATION, V3270PrintOperation)) 43 #define GTK_V3270_PRINT_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_V3270_PRINT_OPERATION, V3270PrintOperation))
43 #define GTK_V3270_PRINT_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_V3270_PRINT_OPERATION, V3270PrintOperationClass)) 44 #define GTK_V3270_PRINT_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_V3270_PRINT_OPERATION, V3270PrintOperationClass))
@@ -51,9 +52,10 @@ @@ -51,9 +52,10 @@
51 /*--[ Prototipes ]-----------------------------------------------------------------------------------*/ 52 /*--[ Prototipes ]-----------------------------------------------------------------------------------*/
52 53
53 LIB3270_EXPORT V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_PRINT_MODE mode); 54 LIB3270_EXPORT V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_PRINT_MODE mode);
54 -  
55 LIB3270_EXPORT GtkWidget * v3270_font_selection_new(const gchar *fontname); 55 LIB3270_EXPORT GtkWidget * v3270_font_selection_new(const gchar *fontname);
56 56
  57 + LIB3270_EXPORT GType V3270PrintOperation_get_type(void);
  58 +
57 G_END_DECLS 59 G_END_DECLS
58 60
59 #endif // V3270_PRINT_OPERATION_H_INCLUDED 61 #endif // V3270_PRINT_OPERATION_H_INCLUDED
src/v3270/print.c
@@ -1,252 +0,0 @@ @@ -1,252 +0,0 @@
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 - #pragma GCC diagnostic ignored "-Wdeprecated-declarations"  
31 -  
32 - #include "private.h"  
33 - #include <v3270.h>  
34 - #include <v3270/colorscheme.h>  
35 - #include <v3270/print.h>  
36 - #include <lib3270/selection.h>  
37 - #include <lib3270/log.h>  
38 - #include <lib3270/trace.h>  
39 -  
40 -/*--[ Widget definition ]----------------------------------------------------------------------------*/  
41 -  
42 - struct _V3270PrintOperationClass  
43 - {  
44 - GtkPrintOperationClass parent_class;  
45 -  
46 - };  
47 -  
48 - struct _V3270PrintOperation  
49 - {  
50 - GtkPrintOperation parent;  
51 - GdkRGBA colors[V3270_COLOR_COUNT];  
52 - LIB3270_PRINT_MODE mode;  
53 - v3270 * widget;  
54 - H3270 * session;  
55 -  
56 - struct {  
57 - gchar * name;  
58 - v3270FontInfo info;  
59 - } font;  
60 -  
61 - gboolean show_selection;  
62 -  
63 -  
64 - };  
65 -  
66 - G_DEFINE_TYPE(V3270PrintOperation, V3270PrintOperation, GTK_TYPE_PRINT_OPERATION);  
67 -  
68 -/*--[ Implement ]------------------------------------------------------------------------------------*/  
69 -  
70 - static void done(GtkPrintOperation *prt, GtkPrintOperationResult result)  
71 - {  
72 - V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(prt);  
73 -  
74 - debug("%s",__FUNCTION__);  
75 -  
76 - if(operation->widget)  
77 - g_signal_emit(GTK_WIDGET(operation->widget), v3270_widget_signal[SIGNAL_PRINT_DONE], 0, prt, (guint) result);  
78 -  
79 - }  
80 -  
81 -#ifndef _WIN32  
82 - static void color_scheme_changed(GtkWidget G_GNUC_UNUSED(*widget), const GdkRGBA *colors, V3270PrintOperation *operation) {  
83 -  
84 - debug("%s=%p",__FUNCTION__,colors);  
85 -  
86 - int f;  
87 - for(f=0;f<V3270_COLOR_COUNT;f++)  
88 - operation->colors[f] = colors[f];  
89 -  
90 - }  
91 -  
92 - void font_name_changed(GtkComboBox *widget, V3270PrintOperation *operation)  
93 - {  
94 - GValue value = { 0, };  
95 - GtkTreeIter iter;  
96 -  
97 - if(!gtk_combo_box_get_active_iter(widget,&iter))  
98 - return;  
99 -  
100 - gtk_tree_model_get_value(gtk_combo_box_get_model(widget),&iter,0,&value);  
101 -  
102 - g_free(operation->font.name);  
103 - operation->font.name = g_value_dup_string(&value);  
104 -  
105 - debug("%s=%s",__FUNCTION__,operation->font.name);  
106 - }  
107 -  
108 - static GtkWidget * create_custom_widget(GtkPrintOperation *prt)  
109 - {  
110 - static const gchar * text[] =  
111 - {  
112 - N_( "_Font:" ),  
113 - N_( "C_olor scheme:" )  
114 - };  
115 -  
116 - size_t f;  
117 -  
118 - V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(prt);  
119 -  
120 - if(operation->widget)  
121 - g_signal_emit(operation->widget, v3270_widget_signal[SIGNAL_PRINT_SETUP], 0, prt);  
122 -  
123 - // Create dialog  
124 -  
125 - GtkGrid * grid = GTK_GRID(gtk_grid_new());  
126 - GtkWidget * font = v3270_font_selection_new(operation->font.name);  
127 - GtkWidget * color = v3270_color_scheme_new();  
128 -  
129 - gtk_container_set_border_width(GTK_CONTAINER(grid),10);  
130 - gtk_grid_set_row_spacing(grid,5);  
131 - gtk_grid_set_column_spacing(grid,5);  
132 -  
133 - v3270_color_scheme_set_rgba(color,operation->colors);  
134 - g_signal_connect(G_OBJECT(color),"update-colors",G_CALLBACK(color_scheme_changed),operation);  
135 - g_signal_connect(G_OBJECT(font),"changed",G_CALLBACK(font_name_changed),operation);  
136 -  
137 - for(f=0;f<G_N_ELEMENTS(text);f++)  
138 - {  
139 - GtkWidget *label = gtk_label_new_with_mnemonic(gettext(text[f]));  
140 - gtk_misc_set_alignment(GTK_MISC(label),0,0.5);  
141 - gtk_grid_attach(grid,label,0,f,1,1);  
142 - }  
143 -  
144 - gtk_grid_attach(grid,font,1,0,1,1);  
145 - gtk_grid_attach(grid,color,1,1,1,1);  
146 -  
147 - gtk_widget_show_all(GTK_WIDGET(grid));  
148 - return GTK_WIDGET(grid);  
149 - }  
150 -  
151 - static void custom_widget_apply(GtkPrintOperation *prt, GtkWidget *widget)  
152 - {  
153 - V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(prt);  
154 -  
155 - debug("%s",__FUNCTION__);  
156 -  
157 - if(operation->widget)  
158 - g_signal_emit(operation->widget, v3270_widget_signal[SIGNAL_PRINT_APPLY], 0, prt);  
159 -  
160 - }  
161 -#endif // _WIN32  
162 -  
163 - static void dispose(GObject *object)  
164 - {  
165 - debug("%s",__FUNCTION__);  
166 -  
167 - V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(object);  
168 -  
169 - g_free(operation->font.name);  
170 -  
171 - }  
172 -  
173 - static void V3270PrintOperation_class_init(V3270PrintOperationClass *klass)  
174 - {  
175 - GtkPrintOperationClass * operation = GTK_PRINT_OPERATION_CLASS(klass);  
176 -  
177 - G_OBJECT_CLASS(klass)->dispose = dispose;  
178 - operation->done = done;  
179 -  
180 -#ifndef _WIN32  
181 - operation->create_custom_widget = create_custom_widget;  
182 - operation->custom_widget_apply = custom_widget_apply;  
183 -#endif // _WIN32  
184 - /*  
185 - // Common signals  
186 - g_signal_connect(print,"done",G_CALLBACK(done),*info);  
187 -  
188 -#if GTK_CHECK_VERSION(3,0,0) && !defined(WIN32)  
189 - g_signal_connect(print,"create-custom-widget",G_CALLBACK(create_custom_widget), *info);  
190 - g_signal_connect(print,"custom-widget-apply",G_CALLBACK(custom_widget_apply), *info);  
191 -#endif // !WIN32  
192 -*/  
193 -  
194 - }  
195 -  
196 - static void V3270PrintOperation_init(V3270PrintOperation *widget)  
197 - {  
198 - // Setup print operation.  
199 - gtk_print_operation_set_custom_tab_label(GTK_PRINT_OPERATION(widget), _( "Options" ) );  
200 - gtk_print_operation_set_show_progress(GTK_PRINT_OPERATION(widget),TRUE);  
201 - gtk_print_operation_set_print_settings(GTK_PRINT_OPERATION(widget),gtk_print_settings_new());  
202 - gtk_print_operation_set_default_page_setup(GTK_PRINT_OPERATION(widget),gtk_page_setup_new());  
203 -  
204 -  
205 - // Setup defaults  
206 - widget->mode = LIB3270_PRINT_ALL;  
207 - widget->show_selection = FALSE;  
208 - widget->font.name = g_strdup(v3270_default_font);  
209 -  
210 - v3270_set_mono_color_table(widget->colors,"#000000","#FFFFFF");  
211 -  
212 - }  
213 -  
214 -V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_PRINT_MODE mode)  
215 -{  
216 - g_return_val_if_fail(GTK_IS_V3270(widget),NULL);  
217 -  
218 - V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(g_object_new(GTK_TYPE_V3270_PRINT_OPERATION, NULL));  
219 -  
220 - operation->mode = mode;  
221 - operation->widget = GTK_V3270(widget);  
222 - operation->session = v3270_get_session(widget);  
223 -  
224 - return operation;  
225 -}  
226 -  
227 -/*--[ Convenience ]----------------------------------------------------------------------------------*/  
228 -  
229 - void v3270_print(GtkWidget *widget, LIB3270_PRINT_MODE mode)  
230 - {  
231 - g_autoptr(GError) err = NULL;  
232 -  
233 - V3270PrintOperation * operation = v3270_print_operation_new(widget, mode);  
234 - gtk_print_operation_run(GTK_PRINT_OPERATION(operation),GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,GTK_WINDOW(gtk_widget_get_toplevel(widget)),&err);  
235 - g_object_unref(operation);  
236 -  
237 - }  
238 -  
239 - void v3270_print_all(GtkWidget *widget)  
240 - {  
241 - v3270_print(widget,LIB3270_PRINT_ALL);  
242 - }  
243 -  
244 - void v3270_print_selected(GtkWidget *widget)  
245 - {  
246 - v3270_print(widget,LIB3270_PRINT_SELECTED);  
247 - }  
248 -  
249 - void v3270_print_copy(GtkWidget *widget)  
250 - {  
251 - v3270_print(widget,LIB3270_PRINT_COPY);  
252 - }  
@@ -51,6 +51,13 @@ @@ -51,6 +51,13 @@
51 <Unit filename="src/dialogs/hostselect.c"> 51 <Unit filename="src/dialogs/hostselect.c">
52 <Option compilerVar="CC" /> 52 <Option compilerVar="CC" />
53 </Unit> 53 </Unit>
  54 + <Unit filename="src/dialogs/print/begin.c">
  55 + <Option compilerVar="CC" />
  56 + </Unit>
  57 + <Unit filename="src/dialogs/print/print.c">
  58 + <Option compilerVar="CC" />
  59 + </Unit>
  60 + <Unit filename="src/dialogs/print/private.h" />
54 <Unit filename="src/dialogs/private.h" /> 61 <Unit filename="src/dialogs/private.h" />
55 <Unit filename="src/dialogs/security.c"> 62 <Unit filename="src/dialogs/security.c">
56 <Option compilerVar="CC" /> 63 <Option compilerVar="CC" />
@@ -109,9 +116,6 @@ @@ -109,9 +116,6 @@
109 <Unit filename="src/v3270/oia.c"> 116 <Unit filename="src/v3270/oia.c">
110 <Option compilerVar="CC" /> 117 <Option compilerVar="CC" />
111 </Unit> 118 </Unit>
112 - <Unit filename="src/v3270/print.c">  
113 - <Option compilerVar="CC" />  
114 - </Unit>  
115 <Unit filename="src/v3270/private.h" /> 119 <Unit filename="src/v3270/private.h" />
116 <Unit filename="src/v3270/properties.c"> 120 <Unit filename="src/v3270/properties.c">
117 <Option compilerVar="CC" /> 121 <Option compilerVar="CC" />