From 9df51ef52b7c6e29dd02a1c44d488074893d0c28 Mon Sep 17 00:00:00 2001 From: zhuyaliang <15132211195@163.com> Date: Mon, 9 Oct 2023 09:52:30 +0800 Subject: font-viewer: Fix compilation warnings and replace deprecated functions --- font-viewer/font-view.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'font-viewer') diff --git a/font-viewer/font-view.c b/font-viewer/font-view.c index 826369d9..918d0087 100644 --- a/font-viewer/font-view.c +++ b/font-viewer/font-view.c @@ -548,6 +548,46 @@ font_view_ensure_model (FontViewApplication *self) font_visible_func, self, NULL); } +static void +set_override_background_color (GtkWidget *widget, + GdkRGBA *rgba) +{ + gchar *css; + GtkCssProvider *provider; + + provider = gtk_css_provider_new (); + + css = g_strdup_printf ("* { background-color: %s;}", + gdk_rgba_to_string (rgba)); + gtk_css_provider_load_from_data (provider, css, -1, NULL); + g_free (css); + + gtk_style_context_add_provider (gtk_widget_get_style_context (widget), + GTK_STYLE_PROVIDER (provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + g_object_unref (provider); +} + +static void +set_override_color (GtkWidget *widget, + GdkRGBA *rgba) +{ + gchar *css; + GtkCssProvider *provider; + + provider = gtk_css_provider_new (); + + css = g_strdup_printf ("* { color: %s;}", + gdk_rgba_to_string (rgba)); + gtk_css_provider_load_from_data (provider, css, -1, NULL); + g_free (css); + + gtk_style_context_add_provider (gtk_widget_get_style_context (widget), + GTK_STYLE_PROVIDER (provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + g_object_unref (provider); +} + static void font_view_application_do_open (FontViewApplication *self, GFile *file, @@ -587,8 +627,8 @@ font_view_application_do_open (FontViewApplication *self, self->font_widget = GTK_WIDGET (sushi_font_widget_new (uri, face_index)); - gtk_widget_override_color (self->font_widget, GTK_STATE_NORMAL, &black); - gtk_widget_override_background_color (self->font_widget, GTK_STATE_FLAG_NORMAL, &white); + set_override_color (self->font_widget, &black); + set_override_background_color (self->font_widget, &white); w = gtk_viewport_new (NULL, NULL); gtk_viewport_set_shadow_type (GTK_VIEWPORT (w), GTK_SHADOW_NONE); -- cgit v1.2.1