Commit 7ec37943e5259d81662137b4f6dbb590c99e0939

Authored by Perry Werneck
1 parent 16917bea

Updating print settings dialog.

Showing 1 changed file with 47 additions and 192 deletions   Show diff stats
src/pw3270/print.c
@@ -31,18 +31,12 @@ @@ -31,18 +31,12 @@
31 31
32 #include "private.h" 32 #include "private.h"
33 #include <v3270.h> 33 #include <v3270.h>
  34 + #include <v3270/print.h>
34 #include <lib3270/selection.h> 35 #include <lib3270/selection.h>
35 #include <lib3270/trace.h> 36 #include <lib3270/trace.h>
36 37
37 - #define AUTO_FONT_SIZE 1  
38 -  
39 -#ifdef AUTO_FONT_SIZE  
40 - #define FONT_CONFIG "font-family"  
41 - #define DEFAULT_FONT "Courier New"  
42 -#else  
43 - #define FONT_CONFIG "font"  
44 - #define DEFAULT_FONT "Courier New 10"  
45 -#endif // AUTO_FONT_SIZE 38 + #define FONT_CONFIG "font-family"
  39 + #define DEFAULT_FONT "Courier New"
46 40
47 /*--[ Structs ]--------------------------------------------------------------------------------------*/ 41 /*--[ Structs ]--------------------------------------------------------------------------------------*/
48 42
@@ -63,10 +57,6 @@ @@ -63,10 +57,6 @@
63 57
64 v3270FontInfo font; 58 v3270FontInfo font;
65 59
66 -// cairo_font_extents_t extents;  
67 -// cairo_scaled_font_t * font_scaled;  
68 -// gchar * font; /**< Font name */  
69 -  
70 double left; 60 double left;
71 double width; /**< Report width */ 61 double width; /**< Report width */
72 double height; /**< Report height (all pages) */ 62 double height; /**< Report height (all pages) */
@@ -97,14 +87,9 @@ @@ -97,14 +87,9 @@
97 CAIRO_FONT_SLANT_NORMAL, 87 CAIRO_FONT_SLANT_NORMAL,
98 pango_font_description_get_weight(descr) == PANGO_WEIGHT_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL); 88 pango_font_description_get_weight(descr) == PANGO_WEIGHT_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL);
99 89
100 -#ifdef AUTO_FONT_SIZE  
101 { 90 {
102 double width = gtk_print_context_get_width(context); 91 double width = gtk_print_context_get_width(context);
103 -#if GTK_CHECK_VERSION(3,0,0)  
104 double cols = (double) info->cols; 92 double cols = (double) info->cols;
105 -#else  
106 - double cols = (double) (info->cols+5);  
107 -#endif // GTK(3,0,0)  
108 double current = width / cols; 93 double current = width / cols;
109 double valid = current; 94 double valid = current;
110 95
@@ -121,7 +106,6 @@ @@ -121,7 +106,6 @@
121 cairo_set_font_size(cr,valid); 106 cairo_set_font_size(cr,valid);
122 107
123 } 108 }
124 -#endif // AUTO_FONT_SIZE  
125 109
126 pango_font_description_free(descr); 110 pango_font_description_free(descr);
127 } 111 }
@@ -355,44 +339,6 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -355,44 +339,6 @@ static gchar * enum_to_string(GType type, guint enum_value)
355 g_free(info); 339 g_free(info);
356 } 340 }
357 341
358 -#ifndef AUTO_FONT_SIZE  
359 -  
360 -#if GTK_CHECK_VERSION(3,2,0)  
361 - static gboolean filter_monospaced(const PangoFontFamily *family,const PangoFontFace *face,gpointer data)  
362 - {  
363 - return pango_font_family_is_monospace((PangoFontFamily *) family);  
364 - }  
365 -#endif // GTK(3,2,0)  
366 -  
367 - static void font_set(GtkFontButton *widget, PRINT_INFO *info)  
368 - {  
369 - trace("%s font=%p",__FUNCTION__,info->font);  
370 - if(info->font)  
371 - g_free(info->font);  
372 - info->font = g_strdup(gtk_font_button_get_font_name(widget));  
373 - }  
374 -  
375 -#else  
376 -  
377 - static void font_name_changed(GtkComboBox *combo, PRINT_INFO *info)  
378 - {  
379 - GValue value = { 0, };  
380 - GtkTreeIter iter;  
381 -  
382 - if(!gtk_combo_box_get_active_iter(combo,&iter))  
383 - return;  
384 -  
385 - gtk_tree_model_get_value(gtk_combo_box_get_model(combo),&iter,0,&value);  
386 -  
387 - if(info->font.family)  
388 - g_free(info->font.family);  
389 -  
390 - info->font.family = g_value_dup_string(&value);  
391 -  
392 - }  
393 -  
394 -#endif // !AUTO_FONT_SIZE  
395 -  
396 static void toggle_show_selection(GtkToggleButton *togglebutton,PRINT_INFO *info) 342 static void toggle_show_selection(GtkToggleButton *togglebutton,PRINT_INFO *info)
397 { 343 {
398 gboolean active = gtk_toggle_button_get_active(togglebutton); 344 gboolean active = gtk_toggle_button_get_active(togglebutton);
@@ -400,158 +346,56 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -400,158 +346,56 @@ static gchar * enum_to_string(GType type, guint enum_value)
400 set_boolean_to_config("print","selection",active); 346 set_boolean_to_config("print","selection",active);
401 } 347 }
402 348
403 - static void load_settings(PRINT_INFO *info)  
404 - {  
405 - gchar *ptr = get_string_from_config("print","colors","");  
406 -  
407 - trace("info->color=%p",info->color);  
408 - trace("colorlist=%p",ptr);  
409 -  
410 - if(*ptr)  
411 - v3270_set_color_table(info->color,ptr);  
412 - else  
413 - v3270_set_mono_color_table(info->color,"black","white");  
414 -  
415 - g_free(ptr);  
416 - }  
417 -  
418 - static GObject * create_custom_widget(GtkPrintOperation *prt, PRINT_INFO *info) 349 + static GtkWidget * create_custom_widget(GtkPrintOperation *prt, PRINT_INFO *info)
419 { 350 {
420 - GtkWidget * container = gtk_table_new(3,2,FALSE);  
421 - static const gchar * text[] = { N_( "_Font:" ), N_( "C_olor scheme:" ) };  
422 - GtkWidget * label[G_N_ELEMENTS(text)];  
423 - GtkWidget * widget;  
424 - int f; 351 + GtkWidget * widget = gtk_frame_new("");
  352 + GtkWidget * settings = V3270_print_settings_new(info->widget);
425 353
426 - trace("%s starts",__FUNCTION__); 354 + // Load values from configuration
  355 + g_autofree gchar * font_family = get_string_from_config("print",FONT_CONFIG,DEFAULT_FONT);
  356 + if(font_family && *font_family)
  357 + v3270_print_settings_set_font_family(settings,font_family);
427 358
428 - for(f=0;f<G_N_ELEMENTS(label);f++)  
429 - {  
430 - label[f] = gtk_label_new_with_mnemonic(gettext(text[f]));  
431 - gtk_misc_set_alignment(GTK_MISC(label[f]),0,0.5);  
432 - gtk_table_attach(GTK_TABLE(container),label[f],0,1,f,f+1,GTK_FILL,GTK_FILL,0,0);  
433 - }  
434 -  
435 - if(info->font.family)  
436 - g_free(info->font.family); 359 + g_autofree gchar * color_scheme = get_string_from_config("print","colors","");
  360 + if(color_scheme && *color_scheme)
  361 + v3270_print_settings_set_color_scheme(settings,color_scheme);
437 362
438 - info->font.family = get_string_from_config("print",FONT_CONFIG,DEFAULT_FONT);  
439 - if(!*info->font.family)  
440 - {  
441 - g_free(info->font.family);  
442 - info->font.family = g_strdup(DEFAULT_FONT);  
443 - } 363 + // Create frame
  364 + GtkWidget *label = gtk_label_new(NULL);
  365 + gtk_label_set_markup(GTK_LABEL(label),_("<b>Text options</b>"));
  366 + gtk_frame_set_label_widget(GTK_FRAME(widget),label);
444 367
445 - // Font selection button  
446 -#ifdef AUTO_FONT_SIZE  
447 - {  
448 - GtkTreeModel * model = (GtkTreeModel *) gtk_list_store_new(1,G_TYPE_STRING);  
449 - GtkCellRenderer * renderer = gtk_cell_renderer_text_new();  
450 - PangoFontFamily **families;  
451 - gint n_families, i;  
452 - GtkTreeIter iter; 368 + gtk_container_set_border_width(GTK_CONTAINER(widget),12);
453 369
454 - widget = gtk_combo_box_new_with_model(model); 370 + // The print dialog doesn't follow the guidelines from https://developer.gnome.org/hig/stable/visual-layout.html.en )-:
  371 + gtk_frame_set_shadow_type(GTK_FRAME(widget),GTK_SHADOW_NONE);
455 372
456 - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), renderer, TRUE);  
457 - gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget), renderer, "text", 0, NULL); 373 + gtk_container_set_border_width(GTK_CONTAINER(settings),6);
  374 + g_object_set(G_OBJECT(settings),"margin-start",8,NULL);
458 375
459 - g_signal_connect(G_OBJECT(widget),"changed",G_CALLBACK(font_name_changed),info); 376 + gtk_container_add(GTK_CONTAINER(widget),settings);
460 377
461 - pango_context_list_families(gtk_widget_get_pango_context(container),&families, &n_families); 378 + gtk_widget_show_all(widget);
462 379
463 - for(i=0; i<n_families; i++)  
464 - {  
465 - if(pango_font_family_is_monospace(families[i]))  
466 - {  
467 - const gchar *name = pango_font_family_get_name (families[i]);  
468 - gtk_list_store_append((GtkListStore *) model,&iter);  
469 - gtk_list_store_set((GtkListStore *) model, &iter,0, name, -1);  
470 -  
471 - if(!g_ascii_strcasecmp(name,info->font.family))  
472 - gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget),&iter);  
473 - }  
474 - }  
475 -  
476 - g_free(families);  
477 - }  
478 -#else  
479 - {  
480 - trace("Font=%s",info->font);  
481 - widget = gtk_font_button_new_with_font(info->font);  
482 - gtk_font_button_set_show_size((GtkFontButton *) widget,TRUE);  
483 - gtk_font_button_set_use_font((GtkFontButton *) widget,TRUE);  
484 - gtk_label_set_mnemonic_widget(GTK_LABEL(label[0]),widget);  
485 - g_free(info->font);  
486 -  
487 -#if GTK_CHECK_VERSION(3,2,0)  
488 - gtk_font_chooser_set_filter_func((GtkFontChooser *) widget,filter_monospaced,NULL,NULL);  
489 -#endif // GTK(3,2,0)  
490 -  
491 - g_signal_connect(G_OBJECT(widget),"font-set",G_CALLBACK(font_set),info);  
492 -  
493 - }  
494 -#endif  
495 -  
496 - gtk_table_attach(GTK_TABLE(container),widget,1,2,0,1,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0);  
497 -  
498 - load_settings(info);  
499 -  
500 - widget = color_scheme_new(info->color);  
501 - gtk_label_set_mnemonic_widget(GTK_LABEL(label[1]),widget);  
502 -  
503 - g_object_set_data(G_OBJECT(container),"combo",widget);  
504 - gtk_table_attach(GTK_TABLE(container),widget,1,2,1,2,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0);  
505 -  
506 - // Selection checkbox  
507 - widget = gtk_check_button_new_with_label( _("Print selection box") );  
508 -  
509 - if(info->src == LIB3270_CONTENT_ALL)  
510 - {  
511 - info->show_selection = get_boolean_from_config("print","selection",FALSE);  
512 - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),info->show_selection);  
513 - g_signal_connect(G_OBJECT(widget),"toggled",G_CALLBACK(toggle_show_selection),info);  
514 - }  
515 - else  
516 - {  
517 - gtk_widget_set_sensitive(widget,FALSE);  
518 - }  
519 -  
520 - gtk_table_attach(GTK_TABLE(container),widget,1,2,2,3,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0);  
521 -  
522 - // Show and return  
523 - gtk_widget_show_all(container);  
524 -  
525 - trace("%s ends container=%p",__FUNCTION__,container);  
526 - return G_OBJECT(container); 380 + return widget;
527 } 381 }
528 382
529 static void custom_widget_apply(GtkPrintOperation *prt, GtkWidget *widget, PRINT_INFO *info) 383 static void custom_widget_apply(GtkPrintOperation *prt, GtkWidget *widget, PRINT_INFO *info)
530 { 384 {
531 - GtkWidget * combo = g_object_get_data(G_OBJECT(widget),"combo");  
532 - GdkRGBA * clr = g_object_get_data(G_OBJECT(combo),"selected"); 385 + GtkWidget * settings = gtk_bin_get_child(GTK_BIN(widget));
533 386
534 - trace("%s starts combo=%p clr=%p widget=%p",__FUNCTION__,combo,clr,widget); 387 + info->show_selection = v3270_print_settings_get_show_selection(settings) ? 1 : 0;
535 388
  389 + // Setup font family
536 if(info->font.family) 390 if(info->font.family)
537 - set_string_to_config("print",FONT_CONFIG,info->font.family);  
538 -  
539 - if(clr)  
540 - {  
541 - int f;  
542 - GString *str = g_string_new("");  
543 - for(f=0;f<V3270_COLOR_COUNT;f++)  
544 - {  
545 - info->color[f] = clr[f];  
546 - if(f)  
547 - g_string_append_c(str,';');  
548 - g_string_append_printf(str,"%s",gdk_rgba_to_string(clr+f));  
549 - }  
550 - set_string_to_config("print","colors","%s",str->str);  
551 - g_string_free(str,TRUE);  
552 - } 391 + g_free(info->font.family);
  392 + info->font.family = v3270_print_settings_get_font_family(settings);
  393 + set_string_to_config("print",FONT_CONFIG,info->font.family);
553 394
554 - trace("%s ends",__FUNCTION__); 395 + // Setup print settings
  396 + v3270_print_settings_get_rgba(settings, info->color, V3270_COLOR_COUNT);
  397 + g_autofree gchar * colors = v3270_print_settings_get_color_scheme(settings);
  398 + set_string_to_config("print","colors","%s",colors);
555 399
556 } 400 }
557 401
@@ -620,7 +464,18 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -620,7 +464,18 @@ static gchar * enum_to_string(GType type, guint enum_value)
620 g_signal_connect(print,"create-custom-widget",G_CALLBACK(create_custom_widget), *info); 464 g_signal_connect(print,"create-custom-widget",G_CALLBACK(create_custom_widget), *info);
621 g_signal_connect(print,"custom-widget-apply",G_CALLBACK(custom_widget_apply), *info); 465 g_signal_connect(print,"custom-widget-apply",G_CALLBACK(custom_widget_apply), *info);
622 #else 466 #else
623 - load_settings(*info); 467 + {
  468 + g_autofree gchar *color_scheme = get_string_from_config("print","colors","");
  469 +
  470 + trace("info->color=%p",info->color);
  471 + trace("colorlist=%p",ptr);
  472 +
  473 + if(color_scheme && *color_scheme)
  474 + v3270_set_color_table(info->color,color_scheme);
  475 + else
  476 + v3270_set_mono_color_table(info->color,"black","white");
  477 +
  478 + }
624 #endif // _WIN32 479 #endif // _WIN32
625 480
626 // Load page and print settings 481 // Load page and print settings