comparison gtk3/dw.c @ 1915:98579be1198e

Experimental change to use CSS to change widget colors on GTK3. This should remove some build warnings.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 28 Sep 2016 20:50:20 +0000
parents 5d32be499016
children eafaab13d0db
comparison
equal deleted inserted replaced
1914:3872ab37297b 1915:98579be1198e
2584 name++; 2584 name++;
2585 sprintf(font, "%s %d", name, size); 2585 sprintf(font, "%s %d", name, size);
2586 } 2586 }
2587 } 2587 }
2588 2588
2589 /* Internal functions to convert to GTK3 style CSS */
2590 static void _dw_override_color(GtkWidget *widget, const char *element, GdkRGBA *color)
2591 {
2592 if(color)
2593 {
2594 GtkCssProvider *provider = gtk_css_provider_new();
2595 gchar *scolor = gdk_rgba_to_string(color);
2596 gchar *css = g_strdup_printf ("* { %s: %s; }", element, scolor);
2597
2598 g_free(scolor);
2599 gtk_css_provider_load_from_data(provider, css, -1, NULL);
2600 g_free(css);
2601 gtk_style_context_add_provider(gtk_widget_get_style_context(widget), GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
2602 g_object_unref(provider);
2603 }
2604 }
2605
2606 static void _dw_override_font(GtkWidget *widget, const char *font)
2607 {
2608 GtkCssProvider *provider = gtk_css_provider_new();
2609 gchar *css = g_strdup_printf ("* { font: %s; }", font);
2610
2611 gtk_css_provider_load_from_data(provider, css, -1, NULL);
2612 g_free(css);
2613 gtk_style_context_add_provider(gtk_widget_get_style_context(widget), GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
2614 g_object_unref(provider);
2615 }
2616
2589 /* 2617 /*
2590 * Sets the font used by a specified window (widget) handle. 2618 * Sets the font used by a specified window (widget) handle.
2591 * Parameters: 2619 * Parameters:
2592 * handle: The window (widget) handle. 2620 * handle: The window (widget) handle.
2593 * fontname: Name and size of the font in the form "size.fontname" 2621 * fontname: Name and size of the font in the form "size.fontname"
2594 */ 2622 */
2595 int dw_window_set_font(HWND handle, char *fontname) 2623 int dw_window_set_font(HWND handle, char *fontname)
2596 { 2624 {
2597 PangoFontDescription *pfont;
2598 GtkWidget *handle2 = handle; 2625 GtkWidget *handle2 = handle;
2599 char *font = strdup(fontname); 2626 char *font = strdup(fontname);
2600 int _locked_by_me = FALSE; 2627 int _locked_by_me = FALSE;
2601 gpointer data; 2628 gpointer data;
2602 2629
2627 data = g_object_get_data(G_OBJECT(handle2), "_dw_fontname"); 2654 data = g_object_get_data(G_OBJECT(handle2), "_dw_fontname");
2628 g_object_set_data(G_OBJECT(handle2), "_dw_fontname", (gpointer)font); 2655 g_object_set_data(G_OBJECT(handle2), "_dw_fontname", (gpointer)font);
2629 if(data) 2656 if(data)
2630 free(data); 2657 free(data);
2631 2658
2632 pfont = pango_font_description_from_string(fontname); 2659 _dw_override_font(handle2, font);
2633 2660
2634 if(pfont)
2635 {
2636 gtk_widget_override_font(handle2, pfont);
2637 pango_font_description_free(pfont);
2638 }
2639 DW_MUTEX_UNLOCK; 2661 DW_MUTEX_UNLOCK;
2640 return TRUE; 2662 return TRUE;
2641 } 2663 }
2642 2664
2643 /* Allows the user to choose a font using the system's font chooser dialog. 2665 /* Allows the user to choose a font using the system's font chooser dialog.
2821 forecolor.blue = (gdouble)DW_BLUE_VALUE(fore) / 255.0; 2843 forecolor.blue = (gdouble)DW_BLUE_VALUE(fore) / 255.0;
2822 } 2844 }
2823 else if(fore != DW_CLR_DEFAULT) 2845 else if(fore != DW_CLR_DEFAULT)
2824 forecolor = _colors[fore]; 2846 forecolor = _colors[fore];
2825 2847
2826 gtk_widget_override_color(handle, GTK_STATE_FLAG_NORMAL, fore != DW_CLR_DEFAULT ? &forecolor : NULL); 2848 _dw_override_color(handle, "color", fore != DW_CLR_DEFAULT ? &forecolor : NULL);
2827 gtk_widget_override_color(handle, GTK_STATE_FLAG_ACTIVE, fore != DW_CLR_DEFAULT ? &forecolor : NULL);
2828 2849
2829 if(back & DW_RGB_COLOR) 2850 if(back & DW_RGB_COLOR)
2830 { 2851 {
2831 backcolor.alpha = 1.0; 2852 backcolor.alpha = 1.0;
2832 backcolor.red = (gdouble)DW_RED_VALUE(back) / 255.0; 2853 backcolor.red = (gdouble)DW_RED_VALUE(back) / 255.0;
2834 backcolor.blue = (gdouble)DW_BLUE_VALUE(back) / 255.0; 2855 backcolor.blue = (gdouble)DW_BLUE_VALUE(back) / 255.0;
2835 } 2856 }
2836 else if(back != DW_CLR_DEFAULT) 2857 else if(back != DW_CLR_DEFAULT)
2837 backcolor = _colors[back]; 2858 backcolor = _colors[back];
2838 2859
2839 gtk_widget_override_background_color(handle, GTK_STATE_FLAG_NORMAL, back != DW_CLR_DEFAULT ? &backcolor : NULL); 2860 _dw_override_background_color(handle, "background-color", back != DW_CLR_DEFAULT ? &backcolor : NULL);
2840 gtk_widget_override_background_color(handle, GTK_STATE_FLAG_ACTIVE, back != DW_CLR_DEFAULT ? &backcolor : NULL);
2841 2861
2842 _save_gdk_colors(handle, forecolor, backcolor); 2862 _save_gdk_colors(handle, forecolor, backcolor);
2843 2863
2844 return TRUE; 2864 return TRUE;
2845 } 2865 }