Commit 438f898aabf91509e231ed6b41886dfba9c0bb14
1 parent
baf5dd1b
Exists in
master
and in
1 other branch
Finishing print settings custom widget.
Showing
7 changed files
with
95 additions
and
50 deletions
Show diff stats
src/dialogs/colorscheme.c
| @@ -454,3 +454,31 @@ | @@ -454,3 +454,31 @@ | ||
| 454 | v3270_color_scheme_set_rgba(widget,clr); | 454 | v3270_color_scheme_set_rgba(widget,clr); |
| 455 | 455 | ||
| 456 | } | 456 | } |
| 457 | + | ||
| 458 | + int v3270_color_scheme_get_rgba(GtkWidget *widget, GdkRGBA *colors, size_t num_colors) | ||
| 459 | + { | ||
| 460 | + if(num_colors > V3270_COLOR_COUNT) | ||
| 461 | + num_colors = V3270_COLOR_COUNT; | ||
| 462 | + | ||
| 463 | + GdkRGBA * clr = NULL; | ||
| 464 | + GValue value = { 0, }; | ||
| 465 | + GtkTreeIter iter; | ||
| 466 | + size_t f; | ||
| 467 | + | ||
| 468 | + if(!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget),&iter)) | ||
| 469 | + return errno = ENODATA; | ||
| 470 | + | ||
| 471 | + gtk_tree_model_get_value(gtk_combo_box_get_model(GTK_COMBO_BOX(widget)),&iter,1,&value); | ||
| 472 | + clr = g_value_get_pointer(&value); | ||
| 473 | + | ||
| 474 | + if(!clr) | ||
| 475 | + return errno = ENODATA; | ||
| 476 | + | ||
| 477 | + for(f=0;f<num_colors;f++) | ||
| 478 | + { | ||
| 479 | + colors[f] = clr[f]; | ||
| 480 | + } | ||
| 481 | + | ||
| 482 | + return 0; | ||
| 483 | + } | ||
| 484 | + |
src/dialogs/print/begin.c
| @@ -38,11 +38,8 @@ | @@ -38,11 +38,8 @@ | ||
| 38 | 38 | ||
| 39 | trace("%s",__FUNCTION__); | 39 | trace("%s",__FUNCTION__); |
| 40 | 40 | ||
| 41 | - // Setup options. | ||
| 42 | - operation->show_selection = v3270_print_settings_get_show_selection(GTK_WIDGET(operation->settings)); | ||
| 43 | - | ||
| 44 | // Setup FONT | 41 | // Setup FONT |
| 45 | - PangoFontDescription * fontDescription = pango_font_description_from_string(v3270_font_selection_get_family(operation->settings->font)); | 42 | + PangoFontDescription * fontDescription = pango_font_description_from_string(operation->font.name); |
| 46 | 43 | ||
| 47 | cairo_select_font_face( | 44 | cairo_select_font_face( |
| 48 | cr, | 45 | cr, |
src/dialogs/print/draw.c
| @@ -83,7 +83,7 @@ | @@ -83,7 +83,7 @@ | ||
| 83 | rect.width = operation->font.info.width; | 83 | rect.width = operation->font.info.width; |
| 84 | 84 | ||
| 85 | // Clear drawing area. | 85 | // Clear drawing area. |
| 86 | - gdk_cairo_set_source_rgba(cr,operation->settings->colors + V3270_COLOR_BACKGROUND); | 86 | + gdk_cairo_set_source_rgba(cr,operation->settings.colors + V3270_COLOR_BACKGROUND); |
| 87 | cairo_rectangle( | 87 | cairo_rectangle( |
| 88 | cr, | 88 | cr, |
| 89 | operation->font.info.left-1,0, | 89 | operation->font.info.left-1,0, |
| @@ -132,7 +132,7 @@ | @@ -132,7 +132,7 @@ | ||
| 132 | operation->session, | 132 | operation->session, |
| 133 | &operation->font.info, | 133 | &operation->font.info, |
| 134 | &rect, | 134 | &rect, |
| 135 | - operation->settings->colors | 135 | + operation->settings.colors |
| 136 | ); | 136 | ); |
| 137 | 137 | ||
| 138 | } | 138 | } |
src/dialogs/print/print.c
| @@ -80,18 +80,11 @@ | @@ -80,18 +80,11 @@ | ||
| 80 | 80 | ||
| 81 | V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(object); | 81 | V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(object); |
| 82 | 82 | ||
| 83 | - /* | ||
| 84 | - if(operation->settings) | ||
| 85 | - { | ||
| 86 | - gtk_widget_destroy(GTK_WIDGET(operation->settings)); | ||
| 87 | - operation->settings = NULL; | ||
| 88 | - } | ||
| 89 | - */ | ||
| 90 | - | ||
| 91 | if(operation->font.info.scaled) | 83 | if(operation->font.info.scaled) |
| 92 | cairo_scaled_font_destroy(operation->font.info.scaled); | 84 | cairo_scaled_font_destroy(operation->font.info.scaled); |
| 93 | 85 | ||
| 94 | -// g_free(operation->font.name); | 86 | + if(operation->font.name) |
| 87 | + g_free(operation->font.name); | ||
| 95 | 88 | ||
| 96 | if(operation->contents.dynamic) | 89 | if(operation->contents.dynamic) |
| 97 | { | 90 | { |
| @@ -108,11 +101,38 @@ | @@ -108,11 +101,38 @@ | ||
| 108 | #ifndef _WIN32 | 101 | #ifndef _WIN32 |
| 109 | static GtkWidget * custom_widget_new(GtkPrintOperation *prt) | 102 | static GtkWidget * custom_widget_new(GtkPrintOperation *prt) |
| 110 | { | 103 | { |
| 111 | - return GTK_WIDGET(GTK_V3270_PRINT_OPERATION(prt)->settings); | 104 | + GtkWidget * widget = gtk_frame_new(""); |
| 105 | + GtkWidget * settings = V3270_print_settings_new(GTK_WIDGET(GTK_V3270_PRINT_OPERATION(prt)->widget)); | ||
| 106 | + | ||
| 107 | + GtkWidget *label = gtk_label_new(NULL); | ||
| 108 | + gtk_label_set_markup(GTK_LABEL(label),_("<b>Text options</b>")); | ||
| 109 | + gtk_frame_set_label_widget(GTK_FRAME(widget),label); | ||
| 110 | + | ||
| 111 | + gtk_container_set_border_width(GTK_CONTAINER(widget),12); | ||
| 112 | + | ||
| 113 | + // The print dialog doesn't follow the guidelines from https://developer.gnome.org/hig/stable/visual-layout.html.en )-: | ||
| 114 | + gtk_frame_set_shadow_type(GTK_FRAME(widget),GTK_SHADOW_NONE); | ||
| 115 | + | ||
| 116 | + gtk_container_set_border_width(GTK_CONTAINER(settings),6); | ||
| 117 | + g_object_set(G_OBJECT(settings),"margin-start",8,NULL); | ||
| 118 | + | ||
| 119 | + gtk_container_add(GTK_CONTAINER(widget),settings); | ||
| 120 | + | ||
| 121 | + gtk_widget_show_all(widget); | ||
| 122 | + | ||
| 123 | + return widget; | ||
| 112 | } | 124 | } |
| 113 | 125 | ||
| 114 | static void custom_widget_apply(GtkPrintOperation *prt, GtkWidget *widget) | 126 | static void custom_widget_apply(GtkPrintOperation *prt, GtkWidget *widget) |
| 115 | { | 127 | { |
| 128 | + V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(prt); | ||
| 129 | + GtkWidget * settings = gtk_bin_get_child(GTK_BIN(widget)); | ||
| 130 | + | ||
| 131 | + // Setup options. | ||
| 132 | + operation->show_selection = v3270_print_settings_get_show_selection(settings); | ||
| 133 | + operation->font.name = g_strdup(v3270_font_selection_get_family(settings)); | ||
| 134 | + | ||
| 135 | + v3270_print_settings_get_rgba(settings, operation->settings.colors, V3270_COLOR_COUNT); | ||
| 116 | 136 | ||
| 117 | } | 137 | } |
| 118 | #endif // _WIN32 | 138 | #endif // _WIN32 |
| @@ -157,7 +177,8 @@ V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_CONTE | @@ -157,7 +177,8 @@ V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_CONTE | ||
| 157 | operation->mode = mode; | 177 | operation->mode = mode; |
| 158 | operation->widget = GTK_V3270(widget); | 178 | operation->widget = GTK_V3270(widget); |
| 159 | operation->session = v3270_get_session(widget); | 179 | operation->session = v3270_get_session(widget); |
| 160 | - operation->settings = GTK_V3270_PRINT_SETTINGS(V3270_print_settings_new(widget)); | 180 | + |
| 181 | + v3270_set_mono_color_table(operation->settings.colors,"#000000","#FFFFFF"); | ||
| 161 | 182 | ||
| 162 | // Get contents. | 183 | // Get contents. |
| 163 | switch(operation->mode) | 184 | switch(operation->mode) |
src/dialogs/print/private.h
| @@ -54,13 +54,17 @@ | @@ -54,13 +54,17 @@ | ||
| 54 | H3270 * session; | 54 | H3270 * session; |
| 55 | gboolean show_selection; ///< @brief Print selection box? | 55 | gboolean show_selection; ///< @brief Print selection box? |
| 56 | 56 | ||
| 57 | - V3270PrintSettings * settings; ///< @brief Custom configuration. | ||
| 58 | - | ||
| 59 | size_t lpp; ///< @brief Lines per page (in rows). | 57 | size_t lpp; ///< @brief Lines per page (in rows). |
| 60 | size_t pages; ///< @brief Number of pages. | 58 | size_t pages; ///< @brief Number of pages. |
| 61 | 59 | ||
| 62 | struct | 60 | struct |
| 63 | { | 61 | { |
| 62 | + GdkRGBA colors[V3270_COLOR_COUNT]; ///< @brief Color scheme for printing. | ||
| 63 | + | ||
| 64 | + } settings; | ||
| 65 | + | ||
| 66 | + struct | ||
| 67 | + { | ||
| 64 | unsigned int width; ///< @brief Max line width. | 68 | unsigned int width; ///< @brief Max line width. |
| 65 | unsigned int height; ///< @brief Number of lines to print. | 69 | unsigned int height; ///< @brief Number of lines to print. |
| 66 | GList * dynamic; | 70 | GList * dynamic; |
| @@ -69,21 +73,21 @@ | @@ -69,21 +73,21 @@ | ||
| 69 | 73 | ||
| 70 | struct | 74 | struct |
| 71 | { | 75 | { |
| 72 | - v3270FontInfo info; | 76 | + gchar * name; |
| 77 | + v3270FontInfo info; | ||
| 73 | } font; | 78 | } font; |
| 74 | 79 | ||
| 75 | }; | 80 | }; |
| 76 | 81 | ||
| 77 | struct _V3270PrintSettingsClass | 82 | struct _V3270PrintSettingsClass |
| 78 | { | 83 | { |
| 79 | - GtkFrameClass parent_class; | 84 | + GtkGridClass parent_class; |
| 80 | 85 | ||
| 81 | }; | 86 | }; |
| 82 | 87 | ||
| 83 | struct _V3270PrintSettings | 88 | struct _V3270PrintSettings |
| 84 | { | 89 | { |
| 85 | - GtkFrame parent; | ||
| 86 | - GdkRGBA colors[V3270_COLOR_COUNT]; ///< @brief Color scheme for printing. | 90 | + GtkGrid parent; |
| 87 | 91 | ||
| 88 | GtkWidget * font; ///< @brief Font selection widget. | 92 | GtkWidget * font; ///< @brief Font selection widget. |
| 89 | GtkWidget * color; ///< @brief Color scheme selecting widget. | 93 | GtkWidget * color; ///< @brief Color scheme selecting widget. |
src/dialogs/print/settings.c
| @@ -35,7 +35,7 @@ | @@ -35,7 +35,7 @@ | ||
| 35 | 35 | ||
| 36 | /*--[ Widget definition ]----------------------------------------------------------------------------*/ | 36 | /*--[ Widget definition ]----------------------------------------------------------------------------*/ |
| 37 | 37 | ||
| 38 | - G_DEFINE_TYPE(V3270PrintSettings, V3270PrintSettings, GTK_TYPE_FRAME); | 38 | + G_DEFINE_TYPE(V3270PrintSettings, V3270PrintSettings, GTK_TYPE_GRID); |
| 39 | 39 | ||
| 40 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 40 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 41 | 41 | ||
| @@ -57,6 +57,7 @@ static void V3270PrintSettings_class_init(V3270PrintSettingsClass *klass) | @@ -57,6 +57,7 @@ static void V3270PrintSettings_class_init(V3270PrintSettingsClass *klass) | ||
| 57 | 57 | ||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | +/* | ||
| 60 | static void color_scheme_changed(GtkWidget G_GNUC_UNUSED(*widget), const GdkRGBA *colors, V3270PrintSettings *settings) | 61 | static void color_scheme_changed(GtkWidget G_GNUC_UNUSED(*widget), const GdkRGBA *colors, V3270PrintSettings *settings) |
| 61 | { | 62 | { |
| 62 | 63 | ||
| @@ -67,6 +68,7 @@ static void color_scheme_changed(GtkWidget G_GNUC_UNUSED(*widget), const GdkRGBA | @@ -67,6 +68,7 @@ static void color_scheme_changed(GtkWidget G_GNUC_UNUSED(*widget), const GdkRGBA | ||
| 67 | settings->colors[f] = colors[f]; | 68 | settings->colors[f] = colors[f]; |
| 68 | 69 | ||
| 69 | } | 70 | } |
| 71 | +*/ | ||
| 70 | 72 | ||
| 71 | static void V3270PrintSettings_init(V3270PrintSettings *widget) | 73 | static void V3270PrintSettings_init(V3270PrintSettings *widget) |
| 72 | { | 74 | { |
| @@ -77,46 +79,32 @@ static void V3270PrintSettings_init(V3270PrintSettings *widget) | @@ -77,46 +79,32 @@ static void V3270PrintSettings_init(V3270PrintSettings *widget) | ||
| 77 | }; | 79 | }; |
| 78 | 80 | ||
| 79 | size_t f; | 81 | size_t f; |
| 80 | - GtkGrid * grid = GTK_GRID(gtk_grid_new()); | ||
| 81 | - | ||
| 82 | widget->font = v3270_font_selection_new("monospace"); | 82 | widget->font = v3270_font_selection_new("monospace"); |
| 83 | widget->color = v3270_color_scheme_new(); | 83 | widget->color = v3270_color_scheme_new(); |
| 84 | widget->selected = gtk_check_button_new_with_label( _("Print selection box") ); | 84 | widget->selected = gtk_check_button_new_with_label( _("Print selection box") ); |
| 85 | 85 | ||
| 86 | - // The print dialog doesn't follow the guidelines from https://developer.gnome.org/hig/stable/visual-layout.html.en )-: | ||
| 87 | - gtk_frame_set_shadow_type(GTK_FRAME(widget),GTK_SHADOW_NONE); | ||
| 88 | - | ||
| 89 | - GtkWidget *label = gtk_label_new(NULL); | ||
| 90 | - | ||
| 91 | - gtk_label_set_markup(GTK_LABEL(label),_("<b>Text options</b>")); | ||
| 92 | - gtk_frame_set_label_widget(GTK_FRAME(widget),label); | ||
| 93 | - | ||
| 94 | - gtk_container_set_border_width(GTK_CONTAINER(widget),12); | ||
| 95 | - gtk_container_set_border_width(GTK_CONTAINER(grid),6); | ||
| 96 | - | ||
| 97 | - g_object_set(G_OBJECT(grid),"margin-start",8,NULL); | 86 | + // https://developer.gnome.org/hig/stable/visual-layout.html.en |
| 87 | + gtk_grid_set_row_spacing(GTK_GRID(widget),6); | ||
| 88 | + gtk_grid_set_column_spacing(GTK_GRID(widget),12); | ||
| 98 | 89 | ||
| 99 | - gtk_grid_set_row_spacing(grid,6); | ||
| 100 | - gtk_grid_set_column_spacing(grid,12); | ||
| 101 | - | ||
| 102 | - g_signal_connect(G_OBJECT(widget->color),"update-colors",G_CALLBACK(color_scheme_changed),widget); | 90 | + // g_signal_connect(G_OBJECT(widget->color),"update-colors",G_CALLBACK(color_scheme_changed),widget); |
| 103 | // g_signal_connect(G_OBJECT(widget->selected),"toggled",G_CALLBACK(toggle_show_selection),widget); | 91 | // g_signal_connect(G_OBJECT(widget->selected),"toggled",G_CALLBACK(toggle_show_selection),widget); |
| 104 | 92 | ||
| 105 | for(f=0;f<G_N_ELEMENTS(text);f++) | 93 | for(f=0;f<G_N_ELEMENTS(text);f++) |
| 106 | { | 94 | { |
| 107 | GtkWidget *label = gtk_label_new_with_mnemonic(gettext(text[f])); | 95 | GtkWidget *label = gtk_label_new_with_mnemonic(gettext(text[f])); |
| 108 | gtk_widget_set_halign(label,GTK_ALIGN_START); | 96 | gtk_widget_set_halign(label,GTK_ALIGN_START); |
| 109 | - gtk_grid_attach(grid,label,0,f,1,1); | 97 | + gtk_grid_attach(GTK_GRID(widget),label,0,f,1,1); |
| 110 | } | 98 | } |
| 111 | 99 | ||
| 112 | - gtk_grid_attach(grid,widget->font,1,0,1,1); | ||
| 113 | - gtk_grid_attach(grid,widget->color,1,1,1,1); | ||
| 114 | - gtk_grid_attach(grid,widget->selected,1,2,1,1); | ||
| 115 | - | ||
| 116 | - gtk_container_add(GTK_CONTAINER(widget),GTK_WIDGET(grid)); | 100 | + gtk_grid_attach(GTK_GRID(widget),widget->font,1,0,1,1); |
| 101 | + gtk_grid_attach(GTK_GRID(widget),widget->color,1,1,1,1); | ||
| 102 | + gtk_grid_attach(GTK_GRID(widget),widget->selected,1,2,1,1); | ||
| 117 | 103 | ||
| 118 | - v3270_set_mono_color_table(widget->colors,"#000000","#FFFFFF"); | ||
| 119 | - v3270_color_scheme_set_rgba(widget->color,widget->colors); | 104 | + // Set color scheme |
| 105 | + GdkRGBA colors[V3270_COLOR_COUNT]; | ||
| 106 | + v3270_set_mono_color_table(colors,"#000000","#FFFFFF"); | ||
| 107 | + v3270_color_scheme_set_rgba(widget->color,colors); | ||
| 120 | 108 | ||
| 121 | gtk_widget_show_all(GTK_WIDGET(widget)); | 109 | gtk_widget_show_all(GTK_WIDGET(widget)); |
| 122 | 110 | ||
| @@ -132,6 +120,12 @@ LIB3270_EXPORT GtkWidget * V3270_print_settings_new(GtkWidget *widget) | @@ -132,6 +120,12 @@ LIB3270_EXPORT GtkWidget * V3270_print_settings_new(GtkWidget *widget) | ||
| 132 | 120 | ||
| 133 | } | 121 | } |
| 134 | 122 | ||
| 123 | +LIB3270_EXPORT int v3270_print_settings_get_rgba(GtkWidget *widget, GdkRGBA *colors, size_t num_colors) | ||
| 124 | +{ | ||
| 125 | + V3270PrintSettings * settings = GTK_V3270_PRINT_SETTINGS(widget); | ||
| 126 | + return v3270_color_scheme_get_rgba(settings->color, colors, num_colors); | ||
| 127 | +} | ||
| 128 | + | ||
| 135 | LIB3270_EXPORT gboolean v3270_print_settings_get_show_selection(GtkWidget *widget) | 129 | LIB3270_EXPORT gboolean v3270_print_settings_get_show_selection(GtkWidget *widget) |
| 136 | { | 130 | { |
| 137 | return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(GTK_V3270_PRINT_SETTINGS(widget)->selected)); | 131 | return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(GTK_V3270_PRINT_SETTINGS(widget)->selected)); |
src/include/v3270/print.h
| @@ -79,6 +79,7 @@ | @@ -79,6 +79,7 @@ | ||
| 79 | LIB3270_EXPORT void v3270_print_settings_set_color_scheme(GtkWidget *widget, const gchar *colors); | 79 | LIB3270_EXPORT void v3270_print_settings_set_color_scheme(GtkWidget *widget, const gchar *colors); |
| 80 | LIB3270_EXPORT const gchar * v3270_print_settings_get_font_family(GtkWidget *widget); | 80 | LIB3270_EXPORT const gchar * v3270_print_settings_get_font_family(GtkWidget *widget); |
| 81 | LIB3270_EXPORT gboolean v3270_print_settings_set_font_family(GtkWidget *widget, const gchar *fontname); | 81 | LIB3270_EXPORT gboolean v3270_print_settings_set_font_family(GtkWidget *widget, const gchar *fontname); |
| 82 | + LIB3270_EXPORT int v3270_print_settings_get_rgba(GtkWidget *widget, GdkRGBA *colors, size_t num_colors); | ||
| 82 | 83 | ||
| 83 | G_END_DECLS | 84 | G_END_DECLS |
| 84 | 85 |