diff --git a/src/gtk/print.c b/src/gtk/print.c index fd3b4e7..050e7e9 100644 --- a/src/gtk/print.c +++ b/src/gtk/print.c @@ -115,38 +115,70 @@ trace("Font set to \"%s\"",info->font); } + static void color_scheme_changed(GtkComboBox *widget,PRINT_INFO *info) + { + gchar *new_colors = NULL; + +#if GTK_CHECK_VERSION(3,0,0) + + new_colors = g_strdup(gtk_combo_box_get_active_id(GTK_COMBO_BOX(widget))); + +#else + + GValue value = { 0, }; + GtkTreeIter iter; + + if(!gtk_combo_box_get_active_iter(widget,&iter)) + return; + + gtk_tree_model_get_value(gtk_combo_box_get_model(widget),&iter,1,&value); + new_colors = g_strdup(g_value_get_string(&value)); + +#endif + + if(!info->colorname) + return; + + trace("%s: %s->%s",__FUNCTION__,info->colorname,new_colors); + + if(*info->colorname) + g_free(info->colorname); + + info->colorname = new_colors; + } + static GObject * create_custom_widget(GtkPrintOperation *prt, PRINT_INFO *info) { - static const gchar *def_colors = "white," - "black," - "black," - "black," - "black," - "black," - "black," - "black," - "black," - "black," - "black," - "black," - "black," - "black," - "black," - "black," - "black," - "black," - "black," - "black," - "black," - "white," - "black," - "black," - "black," - "white," - "black," - "black," - "black," - "black"; + static const gchar *def_colors = "white," // V3270_COLOR_BACKGROUND + "black," // V3270_COLOR_BLUE + "black," // V3270_COLOR_RED + "black," // V3270_COLOR_PINK + "black," // V3270_COLOR_GREEN + "black," // V3270_COLOR_TURQUOISE + "black," // V3270_COLOR_YELLOW + "black," // V3270_COLOR_WHITE + "black," // V3270_COLOR_BLACK + "black," // V3270_COLOR_DARK_BLUE + "black," // V3270_COLOR_ORANGE + "black," // V3270_COLOR_PURPLE + "black," // V3270_COLOR_DARK_GREEN + "black," // V3270_COLOR_DARK_TURQUOISE + "black," // V3270_COLOR_MUSTARD + "black," // V3270_COLOR_GRAY + "black," // V3270_COLOR_FIELD_DEFAULT + "black," // V3270_COLOR_FIELD_INTENSIFIED + "black," // V3270_COLOR_FIELD_PROTECTED + "black," // V3270_COLOR_FIELD_PROTECTED_INTENSIFIED + "black," // V3270_COLOR_SELECTED_BG + "white," // V3270_COLOR_SELECTED_FG + "black," // V3270_COLOR_SELECTED_BORDER + "black," // V3270_COLOR_CURSOR + "black," // V3270_COLOR_CROSS_HAIR + "white," // V3270_COLOR_OIA_BACKGROUND + "black," // V3270_COLOR_OIA + "black," // V3270_COLOR_OIA_SEPARATOR + "black," // V3270_COLOR_OIA_STATUS_OK + "black"; // V3270_COLOR_OIA_STATUS_INVALID static const gchar * label[] = { N_( "Font:" ), N_( "Color scheme:" ) }; GtkWidget * container = gtk_table_new(2,2,FALSE); @@ -180,6 +212,9 @@ info->colorname = get_string_from_config("print","colors",def_colors); load_color_schemes(widget,info->colorname); + + g_signal_connect(G_OBJECT(widget),"changed",G_CALLBACK(color_scheme_changed),info); + gtk_table_attach(GTK_TABLE(container),widget,1,2,1,2,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0); // Show and return diff --git a/src/gtk/v3270/v3270.h b/src/gtk/v3270/v3270.h index 73e54eb..cac1a3f 100644 --- a/src/gtk/v3270/v3270.h +++ b/src/gtk/v3270/v3270.h @@ -191,9 +191,6 @@ void v3270_reload(GtkWidget * widget); - void v3270_set_colors(GtkWidget *widget, const gchar *); - void v3270_set_color(GtkWidget *widget, enum V3270_COLOR id, const gchar *name); - void v3270_set_font_family(GtkWidget *widget, const gchar *name); const gchar * v3270_get_font_family(GtkWidget *widget); @@ -212,6 +209,12 @@ void v3270_paste(GtkWidget *widget); void v3270_paste_string(GtkWidget *widget, const gchar *text, const gchar *encoding); + // Colors + void v3270_set_colors(GtkWidget *widget, const gchar *); + void v3270_set_color(GtkWidget *widget, enum V3270_COLOR id, const gchar *name); + int v3270_set_color_entry(GdkColor *clr, enum V3270_COLOR id, const gchar *name); + void v3270_set_color_table(GdkColor *table, const gchar *colors); + G_END_DECLS #endif // V3270_H_INCLUDED diff --git a/src/gtk/v3270/widget.c b/src/gtk/v3270/widget.c index aaeb752..730c09e 100644 --- a/src/gtk/v3270/widget.c +++ b/src/gtk/v3270/widget.c @@ -721,9 +721,7 @@ static void v3270_send_configure(v3270 * terminal) void v3270_set_colors(GtkWidget *widget, const gchar *colors) { - gchar **clr; - guint cnt; - int f; + g_return_if_fail(GTK_IS_V3270(widget)); if(!colors) { @@ -764,6 +762,19 @@ void v3270_set_colors(GtkWidget *widget, const gchar *colors) } + v3270_set_color_table(GTK_V3270(widget)->color,colors); + + g_signal_emit(widget,v3270_widget_signal[SIGNAL_UPDATE_CONFIG], 0, "colors", colors); + v3270_reload(widget); + +} + +void v3270_set_color_table(GdkColor *table, const gchar *colors) +{ + gchar **clr; + guint cnt; + int f; + clr = g_strsplit(colors,",",V3270_COLOR_COUNT+1); cnt = g_strv_length(clr); switch(cnt) @@ -774,53 +785,59 @@ void v3270_set_colors(GtkWidget *widget, const gchar *colors) case 29: for(f=0;f < V3270_COLOR_SELECTED_BORDER;f++) - v3270_set_color(widget,f,clr[f]); + v3270_set_color_entry(table,f,clr[f]); - v3270_set_color(widget,V3270_COLOR_SELECTED_BORDER,clr[V3270_COLOR_SELECTED_BG]); + v3270_set_color_entry(table,V3270_COLOR_SELECTED_BORDER,clr[V3270_COLOR_SELECTED_BG]); for(f=V3270_COLOR_SELECTED_BORDER+1;f < V3270_COLOR_COUNT;f++) - v3270_set_color(widget,f,clr[f-1]); + v3270_set_color_entry(table,f,clr[f-1]); break; case V3270_COLOR_COUNT: // Complete string for(f=0;f < V3270_COLOR_COUNT;f++) - v3270_set_color(widget,f,clr[f]); + v3270_set_color_entry(table,f,clr[f]); break; default: for(f=0;f < cnt;f++) - v3270_set_color(widget,f,clr[f]); + v3270_set_color_entry(table,f,clr[f]); for(f=cnt; f < V3270_COLOR_COUNT;f++) - v3270_set_color(widget,f,clr[cnt-1]); + v3270_set_color_entry(table,f,clr[cnt-1]); - v3270_set_color(widget,V3270_COLOR_OIA_BACKGROUND,clr[0]); - v3270_set_color(widget,V3270_COLOR_SELECTED_BG,clr[0]); + v3270_set_color_entry(table,V3270_COLOR_OIA_BACKGROUND,clr[0]); + v3270_set_color_entry(table,V3270_COLOR_SELECTED_BG,clr[0]); } g_strfreev(clr); - g_signal_emit(widget,v3270_widget_signal[SIGNAL_UPDATE_CONFIG], 0, "colors", colors); +} - v3270_reload(widget); +int v3270_set_color_entry(GdkColor *clr, enum V3270_COLOR id, const gchar *name) +{ + if(id >= V3270_COLOR_COUNT) + return -1; + + gdk_color_parse(name,clr+id); + + return 0; } void v3270_set_color(GtkWidget *widget, enum V3270_COLOR id, const gchar *name) { v3270 * terminal = GTK_V3270(widget); - if(id >= V3270_COLOR_COUNT) + if(v3270_set_color_entry(terminal->color,id,name)) return; - gdk_color_parse(name,terminal->color+id); - #if(GTK_CHECK_VERSION(3,0,0)) #else gdk_colormap_alloc_color(gtk_widget_get_default_colormap(),terminal->color+id,TRUE,TRUE); #endif + } void v3270_set_font_family(GtkWidget *widget, const gchar *name) -- libgit2 0.21.2