From 3897041f4a6707372da64bc9c6ef52449cb2d14c Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 7 Oct 2014 22:04:26 -0400 Subject: [PATCH] More removal of deprecated API --- tests/testadjustsize.c | 22 ++++++++++++------ tests/testbaseline.c | 51 +++++++++++++++++++++--------------------- tests/testcalendar.c | 16 +++++++++---- tests/testgrid.c | 13 ++++++++--- 4 files changed, 63 insertions(+), 39 deletions(-) diff --git a/tests/testadjustsize.c b/tests/testadjustsize.c index cf0040d4e8..69b251bdb3 100644 --- a/tests/testadjustsize.c +++ b/tests/testadjustsize.c @@ -230,23 +230,19 @@ create_widget_visible_border (const char *text) GtkWidget *inner_box; GtkWidget *test_widget; GtkWidget *label; - GdkRGBA color; outer_box = gtk_event_box_new (); - gdk_rgba_parse (&color, "black"); - gtk_widget_override_background_color (outer_box, 0, &color); + gtk_style_context_add_class (gtk_widget_get_style_context (outer_box), "black-bg"); inner_box = gtk_event_box_new (); gtk_container_set_border_width (GTK_CONTAINER (inner_box), 5); - gdk_rgba_parse (&color, "blue"); - gtk_widget_override_background_color (inner_box, 0, &color); + gtk_style_context_add_class (gtk_widget_get_style_context (inner_box), "blue-bg"); gtk_container_add (GTK_CONTAINER (outer_box), inner_box); test_widget = gtk_event_box_new (); - gdk_rgba_parse (&color, "red"); - gtk_widget_override_background_color (test_widget, 0, &color); + gtk_style_context_add_class (gtk_widget_get_style_context (test_widget), "red-bg"); gtk_container_add (GTK_CONTAINER (inner_box), test_widget); @@ -426,8 +422,20 @@ open_valigned_label_window (void) int main (int argc, char *argv[]) { + GtkCssProvider *provider; + gtk_init (&argc, &argv); + provider = gtk_css_provider_new (); + gtk_css_provider_load_from_data (provider, + ".black-bg { background-color: black; }" + ".red-bg { background-color: red; }" + ".blue-bg { background-color: blue; }", -1, NULL); + gtk_style_context_add_provider_for_screen (gdk_screen_get_default (), + GTK_STYLE_PROVIDER (provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + g_object_unref (provider); + if (g_getenv ("RTL")) gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL); diff --git a/tests/testbaseline.c b/tests/testbaseline.c index 94b4ee75cd..3e6965bfaa 100644 --- a/tests/testbaseline.c +++ b/tests/testbaseline.c @@ -58,18 +58,35 @@ image_size_value_changed (GtkSpinButton *spin_button, gtk_image_set_pixel_size (GTK_IMAGE (image), size); } +static void +set_font_size (GtkWidget *widget, gint size) +{ + const gchar *class[3] = { "small-font", "medium-font", "large-font" }; + + gtk_style_context_add_class (gtk_widget_get_style_context (widget), class[size]); +} + int main (int argc, char **argv) { GtkWidget *window, *label, *entry, *button, *grid, *notebook; GtkWidget *vbox, *hbox, *grid_hbox, *spin, *spin2, *toggle, *combo, *image, *ebox; - PangoFontDescription *font; GtkAdjustment *adjustment; int i, j; + GtkCssProvider *provider; gtk_init (&argc, &argv); + provider = gtk_css_provider_new (); + gtk_css_provider_load_from_data (provider, + ".small-font { font-size: 5px; }" + ".medium-font { font-size: 10px; }" + ".large-font { font-size: 15px; }", -1, NULL); + gtk_style_context_add_provider_for_screen (gdk_screen_get_default (), + GTK_STYLE_PROVIDER (provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + g_object_unref (provider); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (gtk_main_quit), NULL); @@ -94,9 +111,7 @@ main (int argc, for (i = 0; i < 3; i++) { label = gtk_label_new ("│XYyj,Ö..."); - font = pango_font_description_new (); - pango_font_description_set_size (font, 5*(i+1)* 1024); - gtk_widget_override_font (label, font); + set_font_size (label, i); gtk_widget_set_valign (label, aligns[j]); @@ -107,9 +122,7 @@ main (int argc, entry = gtk_entry_new (); gtk_entry_set_text (GTK_ENTRY (entry), "│XYyj,Ö..."); - font = pango_font_description_new (); - pango_font_description_set_size (font, 5*(i+1)* 1024); - gtk_widget_override_font (entry, font); + set_font_size (entry, i); gtk_widget_set_valign (entry, aligns[j]); @@ -150,9 +163,7 @@ main (int argc, { button = gtk_button_new_with_label ("│Xyj,Ö"); - font = pango_font_description_new (); - pango_font_description_set_size (font, 5*(i+1)* 1024); - gtk_widget_override_font (button, font); + set_font_size (button, i); if (j == 0) gtk_widget_set_valign (button, GTK_ALIGN_BASELINE); @@ -168,9 +179,7 @@ main (int argc, gtk_image_new_from_icon_name ("face-sad", GTK_ICON_SIZE_BUTTON)); gtk_button_set_always_show_image (GTK_BUTTON (button), TRUE); - font = pango_font_description_new (); - pango_font_description_set_size (font, 5*(i+1)* 1024); - gtk_widget_override_font (button, font); + set_font_size (button, i); if (j == 0) gtk_widget_set_valign (button, GTK_ALIGN_BASELINE); @@ -248,9 +257,7 @@ main (int argc, { label = gtk_label_new ("Xyjg,Ö."); - font = pango_font_description_new (); - pango_font_description_set_size (font, 5*(i+1)* 1024); - gtk_widget_override_font (label, font); + set_font_size (label, i); if (j != 0) gtk_widget_set_valign (label, GTK_ALIGN_BASELINE); @@ -269,9 +276,7 @@ main (int argc, gtk_image_new_from_icon_name ("face-sad", GTK_ICON_SIZE_BUTTON)); gtk_button_set_always_show_image (GTK_BUTTON (button), TRUE); - font = pango_font_description_new (); - pango_font_description_set_size (font, 5*(i+1)* 1024); - gtk_widget_override_font (button, font); + set_font_size (button, i); if (j != 0) gtk_widget_set_valign (button, GTK_ALIGN_BASELINE); @@ -343,9 +348,7 @@ main (int argc, { button = gtk_button_new_with_label ("│Xyj,Ö"); - font = pango_font_description_new (); - pango_font_description_set_size (font, 5*(i+1)* 1024); - gtk_widget_override_font (button, font); + set_font_size (button, i); if (i != 0) gtk_widget_set_valign (button, GTK_ALIGN_BASELINE); @@ -364,9 +367,7 @@ main (int argc, g_signal_connect (spin2, "value-changed", (GCallback)image_size_value_changed, image); gtk_button_set_always_show_image (GTK_BUTTON (button), TRUE); - font = pango_font_description_new (); - pango_font_description_set_size (font, 5*(i+1)* 1024); - gtk_widget_override_font (button, font); + set_font_size (button, i); gtk_widget_set_valign (button, GTK_ALIGN_BASELINE); diff --git a/tests/testcalendar.c b/tests/testcalendar.c index 2518804aa5..497901113d 100644 --- a/tests/testcalendar.c +++ b/tests/testcalendar.c @@ -242,14 +242,22 @@ void calendar_select_font (GtkWidget *button, CalendarData *calendar) { const char *font = NULL; - PangoFontDescription *font_desc; + GtkCssProvider *provider; + gchar *data; if (calendar->window) { + provider = g_object_get_data (G_OBJECT (calendar->window), "css-provider"); + if (!provider) + { + provider = gtk_css_provider_new (); + gtk_style_context_add_provider (gtk_widget_get_style_context (calendar->window), GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + g_object_set_data_full (G_OBJECT (calendar->window), "css-provider", provider, g_object_unref); + } font = gtk_font_button_get_font_name (GTK_FONT_BUTTON (button)); - font_desc = pango_font_description_from_string (font); - gtk_widget_override_font (calendar->window, font_desc); - pango_font_description_free (font_desc); + data = g_strdup_printf ("GtkCalendar { font: %s; }", font); + gtk_css_provider_load_from_data (provider, data, -1, NULL); + g_free (data); } } diff --git a/tests/testgrid.c b/tests/testgrid.c index 01a5c91538..aabb708a0a 100644 --- a/tests/testgrid.c +++ b/tests/testgrid.c @@ -5,13 +5,20 @@ oriented_test_widget (const gchar *label, const gchar *color, gdouble angle) { GtkWidget *box; GtkWidget *widget; - GdkRGBA c; + GtkCssProvider *provider; + gchar *data; widget = gtk_label_new (label); gtk_label_set_angle (GTK_LABEL (widget), angle); box = gtk_event_box_new (); - gdk_rgba_parse (&c, color); - gtk_widget_override_background_color (box, 0, &c); + provider = gtk_css_provider_new (); + data = g_strdup_printf ("GtkEventBox { background-color: %s; }", color); + gtk_css_provider_load_from_data (provider, data, -1, NULL); + gtk_style_context_add_provider (gtk_widget_get_style_context (box), + GTK_STYLE_PROVIDER (provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + g_free (data); + g_object_unref (provider); gtk_container_add (GTK_CONTAINER (box), widget); return box;