Commit 0b7b696bd0e19818a87c4adbd94bd5bdef4192ca

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

Updating print dialog.

src/dialogs/fontselect.c 0 → 100644
@@ -0,0 +1,72 @@ @@ -0,0 +1,72 @@
  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 +
  34 +/*--[ Widget definition ]----------------------------------------------------------------------------*/
  35 +
  36 + LIB3270_EXPORT GtkWidget * v3270_font_selection_new(const gchar *fontname)
  37 + {
  38 + GtkTreeModel * model = (GtkTreeModel *) gtk_list_store_new(1,G_TYPE_STRING);
  39 + GtkWidget * widget = gtk_combo_box_new_with_model(model);
  40 +
  41 + GtkCellRenderer * renderer = gtk_cell_renderer_text_new();
  42 + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), renderer, TRUE);
  43 + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget), renderer, "text", 0, NULL);
  44 +
  45 + if(!(fontname && *fontname))
  46 + fontname = v3270_get_default_font_name();
  47 +
  48 + gint n_families, i;
  49 + PangoFontFamily **families;
  50 + pango_context_list_families(gtk_widget_get_pango_context(widget),&families, &n_families);
  51 +
  52 + for(i=0; i < n_families; i++)
  53 + {
  54 + if(!pango_font_family_is_monospace(families[i]))
  55 + continue;
  56 +
  57 + const gchar *name = pango_font_family_get_name (families[i]);
  58 + GtkTreeIter iter;
  59 +
  60 + gtk_list_store_append((GtkListStore *) model,&iter);
  61 + gtk_list_store_set((GtkListStore *) model, &iter,0, name, -1);
  62 +
  63 + if(!g_ascii_strcasecmp(name,fontname))
  64 + gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget),&iter);
  65 +
  66 + }
  67 +
  68 + g_free(families);
  69 +
  70 + return widget;
  71 + }
  72 +
src/include/v3270.h
@@ -220,6 +220,7 @@ @@ -220,6 +220,7 @@
220 220
221 // Misc 221 // Misc
222 LIB3270_EXPORT GtkIMContext * v3270_get_im_context(GtkWidget *widget); 222 LIB3270_EXPORT GtkIMContext * v3270_get_im_context(GtkWidget *widget);
  223 + LIB3270_EXPORT const gchar * v3270_get_default_font_name();
223 224
224 LIB3270_EXPORT gboolean v3270_get_toggle(GtkWidget *widget, LIB3270_TOGGLE ix); 225 LIB3270_EXPORT gboolean v3270_get_toggle(GtkWidget *widget, LIB3270_TOGGLE ix);
225 LIB3270_EXPORT gboolean v3270_set_toggle(GtkWidget *widget, LIB3270_TOGGLE ix, gboolean state); 226 LIB3270_EXPORT gboolean v3270_set_toggle(GtkWidget *widget, LIB3270_TOGGLE ix, gboolean state);
src/include/v3270/print.h
@@ -40,18 +40,20 @@ @@ -40,18 +40,20 @@
40 40
41 #define GTK_TYPE_V3270_PRINT_OPERATION (V3270PrintOperation_get_type()) 41 #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)) 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_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_V3270_PRINT_OPERATION, V3270PrintOperationClass)) 43 + #define GTK_V3270_PRINT_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_V3270_PRINT_OPERATION, V3270PrintOperationClass))
44 #define GTK_IS_V3270_PRINT_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_V3270_PRINT_OPERATION)) 44 #define GTK_IS_V3270_PRINT_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_V3270_PRINT_OPERATION))
45 - #define GTK_IS_V3270_PRINT_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_V3270_PRINT_OPERATION))  
46 - #define GTK_V3270_PRINT_OPERATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_V3270_PRINT_OPERATION, V3270V3270PrintOperationClass)) 45 + #define GTK_IS_V3270_PRINT_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_V3270_PRINT_OPERATION))
  46 + #define GTK_V3270_PRINT_OPERATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_V3270_PRINT_OPERATION, V3270V3270PrintOperationClass))
47 47
48 - typedef struct _V3270PrintOperation V3270PrintOperation;  
49 - typedef struct _V3270PrintPrintOperation V3270PrintOperationClass; 48 + typedef struct _V3270PrintOperation V3270PrintOperation;
  49 + typedef struct _V3270PrintOperationClass V3270PrintOperationClass;
50 50
51 /*--[ Prototipes ]-----------------------------------------------------------------------------------*/ 51 /*--[ Prototipes ]-----------------------------------------------------------------------------------*/
52 52
53 LIB3270_EXPORT V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_PRINT_MODE mode); 53 LIB3270_EXPORT V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_PRINT_MODE mode);
54 54
  55 + LIB3270_EXPORT GtkWidget * v3270_font_selection_new(const gchar *fontname);
  56 +
55 G_END_DECLS 57 G_END_DECLS
56 58
57 #endif // V3270_PRINT_OPERATION_H_INCLUDED 59 #endif // V3270_PRINT_OPERATION_H_INCLUDED
src/testprogram/testprogram.c
@@ -103,6 +103,12 @@ static void color_scheme_changed(GtkWidget G_GNUC_UNUSED(*widget), const GdkRGBA @@ -103,6 +103,12 @@ static void color_scheme_changed(GtkWidget G_GNUC_UNUSED(*widget), const GdkRGBA
103 103
104 } 104 }
105 105
  106 +static void print_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal)
  107 +{
  108 + debug("%s",__FUNCTION__);
  109 + v3270_print_all(terminal);
  110 +}
  111 +
106 static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { 112 static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) {
107 113
108 /* 114 /*
@@ -172,6 +178,9 @@ static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { @@ -172,6 +178,9 @@ static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) {
172 GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL,2); 178 GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL,2);
173 GtkWidget *grid = gtk_grid_new(); 179 GtkWidget *grid = gtk_grid_new();
174 GtkWidget *color = v3270_color_scheme_new(); 180 GtkWidget *color = v3270_color_scheme_new();
  181 + GtkWidget *print = gtk_button_new_with_label("Print");
  182 +
  183 + g_signal_connect(G_OBJECT(print),"clicked",G_CALLBACK(print_clicked),terminal);
175 184
176 gtk_widget_set_can_focus(color,FALSE); 185 gtk_widget_set_can_focus(color,FALSE);
177 gtk_widget_set_focus_on_click(color,FALSE); 186 gtk_widget_set_focus_on_click(color,FALSE);
@@ -179,6 +188,7 @@ static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { @@ -179,6 +188,7 @@ static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) {
179 g_signal_connect(G_OBJECT(color),"update-colors",G_CALLBACK(color_scheme_changed),terminal); 188 g_signal_connect(G_OBJECT(color),"update-colors",G_CALLBACK(color_scheme_changed),terminal);
180 189
181 gtk_grid_attach(GTK_GRID(grid),color,0,0,1,1); 190 gtk_grid_attach(GTK_GRID(grid),color,0,0,1,1);
  191 + gtk_grid_attach(GTK_GRID(grid),print,1,0,1,1);
182 192
183 gtk_box_pack_start(GTK_BOX(box),grid,FALSE,TRUE,0); 193 gtk_box_pack_start(GTK_BOX(box),grid,FALSE,TRUE,0);
184 gtk_box_pack_start(GTK_BOX(box),terminal,TRUE,TRUE,0); 194 gtk_box_pack_start(GTK_BOX(box),terminal,TRUE,TRUE,0);
src/trace/trace.c
@@ -357,7 +357,7 @@ static void destroy(GtkWidget *widget) @@ -357,7 +357,7 @@ static void destroy(GtkWidget *widget)
357 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(window->scroll),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC); 357 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(window->scroll),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
358 358
359 window->view = gtk_text_view_new(); 359 window->view = gtk_text_view_new();
360 - v3270_trace_set_font_from_string(GTK_WIDGET(window),"Monospaced"); 360 + v3270_trace_set_font_from_string(GTK_WIDGET(window),v3270_get_default_font_name());
361 361
362 window->text = gtk_text_view_get_buffer(GTK_TEXT_VIEW(window->view)); 362 window->text = gtk_text_view_get_buffer(GTK_TEXT_VIEW(window->view));
363 gtk_text_view_set_editable(GTK_TEXT_VIEW(window->view), TRUE); 363 gtk_text_view_set_editable(GTK_TEXT_VIEW(window->view), TRUE);
src/v3270/font.c
@@ -44,6 +44,11 @@ @@ -44,6 +44,11 @@
44 44
45 /*--[ Implement ]------------------------------------------------------------------------------------*/ 45 /*--[ Implement ]------------------------------------------------------------------------------------*/
46 46
  47 +const gchar * v3270_get_default_font_name()
  48 +{
  49 + return v3270_default_font;
  50 +}
  51 +
47 void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int height) 52 void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int height)
48 { 53 {
49 // update font metrics 54 // update font metrics
src/v3270/print.c
@@ -32,499 +32,180 @@ @@ -32,499 +32,180 @@
32 #include "private.h" 32 #include "private.h"
33 #include <v3270.h> 33 #include <v3270.h>
34 #include <v3270/colorscheme.h> 34 #include <v3270/colorscheme.h>
  35 + #include <v3270/print.h>
35 #include <lib3270/selection.h> 36 #include <lib3270/selection.h>
36 #include <lib3270/log.h> 37 #include <lib3270/log.h>
37 #include <lib3270/trace.h> 38 #include <lib3270/trace.h>
38 39
39 - #define AUTO_FONT_SIZE 1 40 +/*--[ Widget definition ]----------------------------------------------------------------------------*/
40 41
41 -#ifdef AUTO_FONT_SIZE  
42 - #define FONT_CONFIG "font-family"  
43 - #define DEFAULT_FONT "Courier New"  
44 -#else  
45 - #define FONT_CONFIG "font"  
46 - #define DEFAULT_FONT "Courier New 10"  
47 -#endif // AUTO_FONT_SIZE  
48 -  
49 -/*--[ Structs ]--------------------------------------------------------------------------------------*/  
50 -  
51 - typedef struct _print_info  
52 - {  
53 - GdkRGBA color[V3270_COLOR_COUNT];  
54 - int show_selection : 1;  
55 - LIB3270_PRINT_MODE src;  
56 -  
57 - v3270 * widget;  
58 -  
59 - int baddr;  
60 - int rows;  
61 - int cols; ///< @brief Max line width.  
62 - int pages;  
63 - int lpp; ///< @brief Lines per page.  
64 -  
65 - v3270FontInfo font;  
66 -  
67 - double left;  
68 - double width; ///< @brief Report width.  
69 - double height; ///< @brief Report height (all pages).  
70 -  
71 - gchar **text;  
72 -  
73 - } PRINT_INFO;  
74 -  
75 -  
76 -/*--[ Implement ]------------------------------------------------------------------------------------*/  
77 -  
78 - static void begin_print(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info) 42 + struct _V3270PrintOperationClass
79 { 43 {
80 - cairo_font_extents_t extents;  
81 - cairo_t * cr = gtk_print_context_get_cairo_context(context);  
82 -  
83 - // Setup font  
84 - if(info->font.family)  
85 - {  
86 - PangoFontDescription * descr = pango_font_description_from_string(info->font.family);  
87 - if(descr)  
88 - {  
89 - cairo_select_font_face(cr, pango_font_description_get_family(descr),  
90 - CAIRO_FONT_SLANT_NORMAL,  
91 - pango_font_description_get_weight(descr) == PANGO_WEIGHT_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL);  
92 -  
93 -#ifdef AUTO_FONT_SIZE  
94 - {  
95 - double width = gtk_print_context_get_width(context);  
96 -#if GTK_CHECK_VERSION(3,0,0)  
97 - double cols = (double) info->cols;  
98 -#else  
99 - double cols = (double) (info->cols+5);  
100 -#endif // GTK(3,0,0)  
101 - double current = width / cols;  
102 - double valid = current;  
103 -  
104 - do  
105 - {  
106 - valid = current;  
107 - current = valid +1.0;  
108 - cairo_set_font_size(cr,current);  
109 - cairo_font_extents(cr,&extents);  
110 - }  
111 - while( (cols * extents.max_x_advance) < width );  
112 -  
113 - cairo_set_font_size(cr,valid);  
114 -  
115 - }  
116 -#endif // AUTO_FONT_SIZE  
117 -  
118 - pango_font_description_free(descr);  
119 - }  
120 - }  
121 -  
122 - info->font.scaled = cairo_get_scaled_font(cr);  
123 - cairo_scaled_font_reference(info->font.scaled);  
124 - cairo_scaled_font_extents(info->font.scaled,&extents);  
125 -  
126 - info->font.height = extents.height;  
127 - info->font.descent = extents.descent;  
128 - info->font.width = extents.max_x_advance;  
129 -  
130 - info->width = ((double) info->cols) * extents.max_x_advance;  
131 - info->height = ((double) info->rows) * (extents.height + extents.descent);  
132 -  
133 - // Center image  
134 - info->left = (gtk_print_context_get_width(context)-info->width)/2;  
135 - if(info->left < 2)  
136 - info->left = 2;  
137 -  
138 - // Setup page size  
139 - info->lpp = (gtk_print_context_get_height(context) / (extents.height + extents.descent));  
140 - info->pages = (info->rows / info->lpp)+1; 44 + GtkPrintOperationClass parent_class;
141 45
142 - gtk_print_operation_set_n_pages(prt,info->pages);  
143 - } 46 + };
144 47
145 - static void draw_screen(GtkPrintOperation *prt, GtkPrintContext *context, gint pg, PRINT_INFO *info) 48 + struct _V3270PrintOperation
146 { 49 {
147 - int row;  
148 - int col;  
149 - cairo_t * cr = gtk_print_context_get_cairo_context(context);  
150 - int baddr = info->baddr;  
151 - GdkRectangle rect; 50 + GtkPrintOperation parent;
  51 + GdkRGBA color[V3270_COLOR_COUNT];
  52 + LIB3270_PRINT_MODE mode;
  53 + v3270 * widget;
  54 + H3270 * session;
152 55
153 - cairo_set_scaled_font(cr,info->font.scaled); 56 + struct {
  57 + gchar * name;
  58 + v3270FontInfo info;
  59 + } font;
154 60
155 - memset(&rect,0,sizeof(rect));  
156 - rect.y = 2;  
157 - rect.height = (info->font.height + info->font.descent);  
158 - rect.width = info->font.width; 61 + gboolean show_selection;
159 62
160 - // Clear page  
161 - gdk_cairo_set_source_rgba(cr,info->color+V3270_COLOR_BACKGROUND);  
162 - cairo_rectangle(cr, info->left-2, 0, (rect.width*info->cols)+4, (rect.height*info->rows)+4);  
163 - cairo_fill(cr);  
164 - cairo_stroke(cr);  
165 63
166 - rect.width++;  
167 - rect.height++; 64 + };
168 65
169 - for(row = 0; row < info->rows; row++)  
170 - {  
171 - rect.x = info->left;  
172 - for(col = 0; col < info->cols; col++)  
173 - {  
174 - unsigned char c;  
175 - unsigned short attr;  
176 -  
177 - if(!lib3270_get_element(info->widget->host,baddr++,&c,&attr) && (info->src == LIB3270_PRINT_ALL || (attr & LIB3270_ATTR_SELECTED)))  
178 - {  
179 - if(!info->show_selection)  
180 - attr &= ~LIB3270_ATTR_SELECTED;  
181 - v3270_draw_element(cr,c,attr,info->widget->host,&info->font,&rect,info->color);  
182 - }  
183 -  
184 - rect.x += (rect.width-1);  
185 - }  
186 - rect.y += (rect.height-1); 66 + G_DEFINE_TYPE(V3270PrintOperation, V3270PrintOperation, GTK_TYPE_PRINT_OPERATION);
187 67
188 - }  
189 - }  
190 -  
191 - /*  
192 - static void show_print_error(GtkWidget *widget, GError *err)  
193 - {  
194 - GtkWidget *dialog = gtk_message_dialog_new_with_markup( GTK_WINDOW(gtk_widget_get_toplevel(widget)),  
195 - GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,  
196 - GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE,  
197 - "%s",_( "Print operation failed" ));  
198 -  
199 - g_warning("%s",err->message);  
200 -  
201 - gtk_window_set_title(GTK_WINDOW(dialog),_("Error"));  
202 -  
203 - gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog),"%s",err->message);  
204 -  
205 - gtk_dialog_run(GTK_DIALOG(dialog));  
206 - gtk_widget_destroy(dialog);  
207 -}  
208 -*/ 68 +/*--[ Implement ]------------------------------------------------------------------------------------*/
209 69
210 - static void done(GtkPrintOperation *prt, GtkPrintOperationResult result, PRINT_INFO *info) 70 + static void done(GtkPrintOperation *prt, GtkPrintOperationResult result)
211 { 71 {
212 - debug("%s(%p)",__FUNCTION__,info->widget);  
213 - g_signal_emit(info->widget, v3270_widget_signal[SIGNAL_PRINT_DONE], 0, prt, (guint) result); 72 + V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(prt);
214 73
215 debug("%s",__FUNCTION__); 74 debug("%s",__FUNCTION__);
216 - if(info->font.scaled)  
217 - cairo_scaled_font_destroy(info->font.scaled);  
218 -  
219 - debug("%s",__FUNCTION__);  
220 - if(info->text)  
221 - g_strfreev(info->text);  
222 -  
223 - debug("%s",__FUNCTION__);  
224 - if(info->font.family)  
225 - g_free(info->font.family);  
226 -  
227 - debug("%s",__FUNCTION__);  
228 - g_free(info);  
229 - debug("%s",__FUNCTION__);  
230 - }  
231 -  
232 -#ifndef AUTO_FONT_SIZE  
233 -  
234 -#if GTK_CHECK_VERSION(3,2,0)  
235 - static gboolean filter_monospaced(const PangoFontFamily *family,const PangoFontFace *face,gpointer data)  
236 - {  
237 - return pango_font_family_is_monospace((PangoFontFamily *) family);  
238 - }  
239 -#endif // GTK(3,2,0)  
240 -  
241 - static void font_set(GtkFontButton *widget, PRINT_INFO *info)  
242 - {  
243 - if(info->font)  
244 - g_free(info->font);  
245 - info->font = g_strdup(gtk_font_button_get_font_name(widget));  
246 - }  
247 -  
248 -#else  
249 -  
250 - static void font_name_changed(GtkComboBox *combo, PRINT_INFO *info)  
251 - {  
252 - GValue value = { 0, };  
253 - GtkTreeIter iter;  
254 -  
255 - if(!gtk_combo_box_get_active_iter(combo,&iter))  
256 - return;  
257 -  
258 - gtk_tree_model_get_value(gtk_combo_box_get_model(combo),&iter,0,&value);  
259 75
260 - if(info->font.family)  
261 - g_free(info->font.family);  
262 -  
263 - info->font.family = g_value_dup_string(&value); 76 + if(operation->widget)
  77 + g_signal_emit(GTK_WIDGET(operation->widget), v3270_widget_signal[SIGNAL_PRINT_DONE], 0, prt, (guint) result);
264 78
265 } 79 }
266 80
267 -#endif // !AUTO_FONT_SIZE  
268 -  
269 - static void toggle_show_selection(GtkToggleButton *togglebutton,PRINT_INFO *info) 81 +#ifndef _WIN32
  82 + static GtkWidget * create_custom_widget(GtkPrintOperation *prt)
270 { 83 {
271 - gboolean active = gtk_toggle_button_get_active(togglebutton);  
272 - info->show_selection = active ? 1 : 0;  
273 - }  
274 -  
275 - static GObject * create_custom_widget(GtkPrintOperation *prt, PRINT_INFO *info)  
276 - {  
277 - GtkWidget * container = gtk_table_new(3,2,FALSE);  
278 - static const gchar * text[] = { N_( "_Font:" ), N_( "C_olor scheme:" ) };  
279 - GtkWidget * label[G_N_ELEMENTS(text)];  
280 - GtkWidget * widget;  
281 - size_t f;  
282 -  
283 - for(f=0;f<G_N_ELEMENTS(label);f++) 84 + static const gchar * text[] =
284 { 85 {
285 - label[f] = gtk_label_new_with_mnemonic(gettext(text[f]));  
286 - gtk_misc_set_alignment(GTK_MISC(label[f]),0,0.5);  
287 - gtk_table_attach(GTK_TABLE(container),label[f],0,1,f,f+1,GTK_FILL,GTK_FILL,0,0);  
288 - } 86 + N_( "_Font:" ),
  87 + N_( "C_olor scheme:" )
  88 + };
289 89
290 - // Font selection button  
291 -#ifdef AUTO_FONT_SIZE  
292 - {  
293 - GtkTreeModel * model = (GtkTreeModel *) gtk_list_store_new(1,G_TYPE_STRING);  
294 - GtkCellRenderer * renderer = gtk_cell_renderer_text_new();  
295 - PangoFontFamily **families;  
296 - gint n_families, i;  
297 - GtkTreeIter iter; 90 + size_t f;
298 91
299 - widget = gtk_combo_box_new_with_model(model); 92 + V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(prt);
300 93
301 - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), renderer, TRUE);  
302 - gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget), renderer, "text", 0, NULL); 94 + if(operation->widget)
  95 + g_signal_emit(operation->widget, v3270_widget_signal[SIGNAL_PRINT_SETUP], 0, prt);
303 96
304 - g_signal_connect(G_OBJECT(widget),"changed",G_CALLBACK(font_name_changed),info); 97 + // Create dialog
305 98
306 - pango_context_list_families(gtk_widget_get_pango_context(container),&families, &n_families); 99 + GtkGrid * grid = GTK_GRID(gtk_grid_new());
  100 + GtkWidget * font = v3270_font_selection_new(operation->font.name);
  101 + GtkWidget * color = v3270_color_scheme_new();
307 102
308 - for(i=0; i<n_families; i++)  
309 - {  
310 - if(pango_font_family_is_monospace(families[i]))  
311 - {  
312 - const gchar *name = pango_font_family_get_name (families[i]);  
313 - gtk_list_store_append((GtkListStore *) model,&iter);  
314 - gtk_list_store_set((GtkListStore *) model, &iter,0, name, -1); 103 + gtk_container_set_border_width(GTK_CONTAINER(grid),10);
  104 + gtk_grid_set_row_spacing(grid,5);
  105 + gtk_grid_set_column_spacing(grid,5);
315 106
316 - if(!g_ascii_strcasecmp(name,info->font.family))  
317 - gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget),&iter);  
318 - }  
319 - } 107 + v3270_color_scheme_set_rgba(color,operation->color);
320 108
321 - g_free(families);  
322 - }  
323 -#else 109 + for(f=0;f<G_N_ELEMENTS(text);f++)
324 { 110 {
325 - widget = gtk_font_button_new_with_font(info->font);  
326 - gtk_font_button_set_show_size((GtkFontButton *) widget,TRUE);  
327 - gtk_font_button_set_use_font((GtkFontButton *) widget,TRUE);  
328 - gtk_label_set_mnemonic_widget(GTK_LABEL(label[0]),widget);  
329 - g_free(info->font);  
330 -  
331 -#if GTK_CHECK_VERSION(3,2,0)  
332 - gtk_font_chooser_set_filter_func((GtkFontChooser *) widget,filter_monospaced,NULL,NULL);  
333 -#endif // GTK(3,2,0)  
334 -  
335 - g_signal_connect(G_OBJECT(widget),"font-set",G_CALLBACK(font_set),info);  
336 - 111 + GtkWidget *label = gtk_label_new_with_mnemonic(gettext(text[f]));
  112 + gtk_misc_set_alignment(GTK_MISC(label),0,0.5);
  113 + gtk_grid_attach(grid,label,0,f,1,1);
337 } 114 }
338 -#endif  
339 -  
340 - gtk_table_attach(GTK_TABLE(container),widget,1,2,0,1,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0);  
341 -  
342 - g_signal_emit(info->widget, v3270_widget_signal[SIGNAL_PRINT_BEGIN], 0, prt);  
343 115
  116 + gtk_grid_attach(grid,font,1,0,1,1);
  117 + gtk_grid_attach(grid,color,1,1,1,1);
344 118
345 - widget = v3270_color_scheme_new();  
346 - v3270_color_scheme_set_rgba(widget,info->color);  
347 - gtk_label_set_mnemonic_widget(GTK_LABEL(label[1]),widget);  
348 -  
349 - g_object_set_data(G_OBJECT(container),"combo",widget);  
350 - gtk_table_attach(GTK_TABLE(container),widget,1,2,1,2,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0);  
351 -  
352 - // Selection checkbox  
353 - widget = gtk_check_button_new_with_label( _("Print selection box") ); 119 + gtk_widget_show_all(GTK_WIDGET(grid));
  120 + return GTK_WIDGET(grid);
  121 + }
354 122
355 - if(info->src == LIB3270_PRINT_ALL)  
356 - {  
357 - info->show_selection = FALSE;  
358 - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),info->show_selection);  
359 - g_signal_connect(G_OBJECT(widget),"toggled",G_CALLBACK(toggle_show_selection),info);  
360 - }  
361 - else  
362 - {  
363 - gtk_widget_set_sensitive(widget,FALSE);  
364 - } 123 + static void custom_widget_apply(GtkPrintOperation *prt, GtkWidget *widget)
  124 + {
  125 + V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(prt);
365 126
366 - gtk_table_attach(GTK_TABLE(container),widget,1,2,2,3,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0); 127 + debug("%s",__FUNCTION__);
367 128
368 - // Show and return  
369 - gtk_widget_show_all(container); 129 + if(operation->widget)
  130 + g_signal_emit(operation->widget, v3270_widget_signal[SIGNAL_PRINT_APPLY], 0, prt);
370 131
371 - return G_OBJECT(container);  
372 } 132 }
  133 +#endif // _WIN32
373 134
374 - static void custom_widget_apply(GtkPrintOperation *prt, GtkWidget *widget, PRINT_INFO *info) 135 + static void dispose(GObject *object)
375 { 136 {
376 - g_signal_emit(info->widget, v3270_widget_signal[SIGNAL_PRINT_APPLY], 0, prt);  
377 -  
378 - /*  
379 - GtkWidget * combo = g_object_get_data(G_OBJECT(widget),"combo");  
380 - GdkRGBA * clr = g_object_get_data(G_OBJECT(combo),"selected");  
381 -  
382 - trace("%s starts combo=%p clr=%p widget=%p",__FUNCTION__,combo,clr,widget); 137 + debug("%s",__FUNCTION__);
383 138
384 - if(info->font.family)  
385 - set_string_to_config("print",FONT_CONFIG,info->font.family); 139 + V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(object);
386 140
387 - if(clr)  
388 - {  
389 - int f;  
390 - GString *str = g_string_new("");  
391 - for(f=0;f<V3270_COLOR_COUNT;f++)  
392 - {  
393 - info->color[f] = clr[f];  
394 - if(f)  
395 - g_string_append_c(str,';');  
396 - g_string_append_printf(str,"%s",gdk_rgba_to_string(clr+f));  
397 - }  
398 - set_string_to_config("print","colors","%s",str->str);  
399 - g_string_free(str,TRUE);  
400 - }  
401 -  
402 - trace("%s ends",__FUNCTION__);  
403 - */ 141 + g_free(operation->font.name);
404 142
405 } 143 }
406 144
407 - static GtkPrintOperation * begin_print_operation(GtkWidget *widget, PRINT_INFO **info) 145 + static void V3270PrintOperation_class_init(V3270PrintOperationClass *klass)
408 { 146 {
409 - GtkPrintOperation * print = gtk_print_operation_new();  
410 - GtkPrintSettings * settings = gtk_print_settings_new();  
411 - GtkPageSetup * setup = gtk_page_setup_new();  
412 - // GtkPaperSize * papersize = NULL;  
413 -  
414 - *info = g_new0(PRINT_INFO,1);  
415 - (*info)->cols = 80;  
416 - (*info)->widget = widget;  
417 - (*info)->font.family = g_strdup(DEFAULT_FONT); 147 + GtkPrintOperationClass * operation = GTK_PRINT_OPERATION_CLASS(klass);
418 148
419 - debug("%s",__FUNCTION__);  
420 - gtk_print_operation_set_custom_tab_label(print, _( "Options" ) );  
421 - gtk_print_operation_set_show_progress(print,TRUE); 149 + G_OBJECT_CLASS(klass)->dispose = dispose;
  150 + operation->done = done;
422 151
423 - // Common signals 152 +#ifndef _WIN32
  153 + operation->create_custom_widget = create_custom_widget;
  154 + operation->custom_widget_apply = custom_widget_apply;
  155 +#endif // _WIN32
  156 + /*
  157 + // Common signals
424 g_signal_connect(print,"done",G_CALLBACK(done),*info); 158 g_signal_connect(print,"done",G_CALLBACK(done),*info);
425 159
426 #if GTK_CHECK_VERSION(3,0,0) && !defined(WIN32) 160 #if GTK_CHECK_VERSION(3,0,0) && !defined(WIN32)
427 - g_signal_connect(print,"create-custom-widget",G_CALLBACK(create_custom_widget), *info);  
428 - g_signal_connect(print,"custom-widget-apply",G_CALLBACK(custom_widget_apply), *info); 161 + g_signal_connect(print,"create-custom-widget",G_CALLBACK(create_custom_widget), *info);
  162 + g_signal_connect(print,"custom-widget-apply",G_CALLBACK(custom_widget_apply), *info);
429 #endif // !WIN32 163 #endif // !WIN32
  164 +*/
430 165
431 - // Finish settings  
432 - gtk_print_operation_set_print_settings(print,settings);  
433 - //gtk_page_setup_set_paper_size_and_default_margins(setup,papersize);  
434 - gtk_print_operation_set_default_page_setup(print,setup);  
435 -  
436 - return print;  
437 } 166 }
438 167
439 - static void draw_text(GtkPrintOperation *prt, GtkPrintContext *context, gint pg, PRINT_INFO *info) 168 + static void V3270PrintOperation_init(V3270PrintOperation *widget)
440 { 169 {
441 - cairo_t * cr = gtk_print_context_get_cairo_context(context);  
442 - GdkRectangle rect;  
443 - int row = pg*info->lpp;  
444 - int l; 170 + // Setup print operation.
  171 + gtk_print_operation_set_custom_tab_label(GTK_PRINT_OPERATION(widget), _( "Options" ) );
  172 + gtk_print_operation_set_show_progress(GTK_PRINT_OPERATION(widget),TRUE);
  173 + gtk_print_operation_set_print_settings(GTK_PRINT_OPERATION(widget),gtk_print_settings_new());
  174 + gtk_print_operation_set_default_page_setup(GTK_PRINT_OPERATION(widget),gtk_page_setup_new());
445 175
446 - cairo_set_scaled_font(cr,info->font.scaled);  
447 176
448 - memset(&rect,0,sizeof(rect));  
449 - rect.y = 2;  
450 - rect.height = (info->font.height + info->font.descent)+1;  
451 - rect.width = info->font.width+1; 177 + // Setup defaults
  178 + widget->mode = LIB3270_PRINT_ALL;
  179 + widget->show_selection = FALSE;
  180 + widget->font.name = g_strdup(v3270_default_font);
452 181
453 - for(l=0;l<info->lpp && row < info->rows;l++)  
454 - {  
455 - cairo_move_to(cr,2,rect.y+rect.height);  
456 - cairo_show_text(cr, info->text[row]);  
457 - cairo_stroke(cr);  
458 - row++;  
459 - rect.y += (rect.height-1);  
460 - } 182 + v3270_set_mono_color_table(widget->color,"#000000","#FFFFFF");
461 183
462 } 184 }
463 185
464 - static void print_operation(GtkWidget *widget, GtkPrintOperationAction oper, LIB3270_PRINT_MODE mode)  
465 - {  
466 - PRINT_INFO * info = NULL;  
467 - GtkPrintOperation * print;  
468 - gchar * text;  
469 - GError * err = NULL;  
470 -  
471 - g_return_if_fail(GTK_IS_V3270(widget));  
472 -  
473 - print = begin_print_operation(widget,&info);  
474 - if(!print)  
475 - return;  
476 -  
477 - lib3270_get_screen_size(info->widget->host,&info->rows,&info->cols); 186 +V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_PRINT_MODE mode)
  187 +{
  188 + g_return_val_if_fail(GTK_IS_V3270(widget),NULL);
478 189
479 - info->src = mode;  
480 -  
481 - g_signal_connect(print,"begin_print",G_CALLBACK(begin_print),info);  
482 -  
483 - switch(mode)  
484 - {  
485 - case LIB3270_PRINT_ALL:  
486 - case LIB3270_PRINT_SELECTED:  
487 - g_signal_connect(print,"draw_page",G_CALLBACK(draw_screen),info);  
488 - break; 190 + V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(g_object_new(GTK_TYPE_V3270_PRINT_OPERATION, NULL));
489 191
490 - case LIB3270_PRINT_COPY: 192 + operation->mode = mode;
  193 + operation->widget = GTK_V3270(widget);
  194 + operation->session = v3270_get_session(widget);
491 195
492 - text = v3270_get_copy(widget);  
493 -  
494 - if(text)  
495 - {  
496 - int r;  
497 -  
498 - info->text = g_strsplit(text,"\n",-1);  
499 - info->rows = g_strv_length(info->text);  
500 -  
501 - for(r=0;r < info->rows;r++)  
502 - {  
503 - size_t sz = strlen(info->text[r]);  
504 - if(sz > info->cols)  
505 - info->cols = sz;  
506 - }  
507 - g_free(text);  
508 - }  
509 - g_signal_connect(print,"draw_page",G_CALLBACK(draw_text),info);  
510 - break;  
511 -  
512 -  
513 - }  
514 -  
515 - // Run Print dialog  
516 - gtk_print_operation_run(print,oper,GTK_WINDOW(gtk_widget_get_toplevel(widget)),&err);  
517 -  
518 - if(err)  
519 - g_error_free(err);  
520 -  
521 - g_object_unref(print); 196 + return operation;
  197 +}
522 198
523 - } 199 +/*--[ Convenience ]----------------------------------------------------------------------------------*/
524 200
525 void v3270_print(GtkWidget *widget, LIB3270_PRINT_MODE mode) 201 void v3270_print(GtkWidget *widget, LIB3270_PRINT_MODE mode)
526 { 202 {
527 - print_operation(widget,GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, mode); 203 + g_autoptr(GError) err = NULL;
  204 +
  205 + V3270PrintOperation * operation = v3270_print_operation_new(widget, mode);
  206 + gtk_print_operation_run(GTK_PRINT_OPERATION(operation),GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,GTK_WINDOW(gtk_widget_get_toplevel(widget)),&err);
  207 + g_object_unref(operation);
  208 +
528 } 209 }
529 210
530 void v3270_print_all(GtkWidget *widget) 211 void v3270_print_all(GtkWidget *widget)
src/v3270/private.h
@@ -79,7 +79,7 @@ G_BEGIN_DECLS @@ -79,7 +79,7 @@ G_BEGIN_DECLS
79 SIGNAL_CHANGED, 79 SIGNAL_CHANGED,
80 SIGNAL_MESSAGE, 80 SIGNAL_MESSAGE,
81 SIGNAL_FIELD, 81 SIGNAL_FIELD,
82 - SIGNAL_PRINT_BEGIN, 82 + SIGNAL_PRINT_SETUP,
83 SIGNAL_PRINT_APPLY, 83 SIGNAL_PRINT_APPLY,
84 SIGNAL_PRINT_DONE, 84 SIGNAL_PRINT_DONE,
85 85
src/v3270/widget.c
@@ -497,18 +497,7 @@ static void v3270_class_init(v3270Class *klass) @@ -497,18 +497,7 @@ static void v3270_class_init(v3270Class *klass)
497 G_TYPE_BOOLEAN, 3, G_TYPE_BOOLEAN, G_TYPE_UINT, G_TYPE_POINTER); 497 G_TYPE_BOOLEAN, 3, G_TYPE_BOOLEAN, G_TYPE_UINT, G_TYPE_POINTER);
498 498
499 499
500 - /*  
501 - v3270_widget_signal[SIGNAL_PRINT] =  
502 - g_signal_new( "print",  
503 - G_OBJECT_CLASS_TYPE (gobject_class),  
504 - G_SIGNAL_RUN_FIRST,  
505 - 0,  
506 - NULL, NULL,  
507 - v3270_VOID__VOID,  
508 - G_TYPE_NONE, 0);  
509 - */  
510 -  
511 - v3270_widget_signal[SIGNAL_PRINT_BEGIN] = 500 + v3270_widget_signal[SIGNAL_PRINT_SETUP] =
512 g_signal_new( "print-begin", 501 g_signal_new( "print-begin",
513 G_OBJECT_CLASS_TYPE (gobject_class), 502 G_OBJECT_CLASS_TYPE (gobject_class),
514 G_SIGNAL_RUN_FIRST, 503 G_SIGNAL_RUN_FIRST,