From be7fa3e742d5a01c341ebe122bfde3b37fc9c55f Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 24 Sep 2023 02:42:11 +0300 Subject: [PATCH 21/21] gtk4: Avoid deprecated gtk_widget_get_style_context() See osdn #47924 Signed-off-by: Marko Lindqvist --- client/gui-gtk-4.0/citydlg.c | 38 ++++++++++++---------------------- client/gui-gtk-4.0/gui_main.c | 6 +++--- client/gui-gtk-4.0/gui_stuff.c | 26 +++++++++-------------- client/gui-gtk-4.0/mapview.c | 10 ++++----- 4 files changed, 31 insertions(+), 49 deletions(-) diff --git a/client/gui-gtk-4.0/citydlg.c b/client/gui-gtk-4.0/citydlg.c index 2a8c161c88..b0cfb87864 100644 --- a/client/gui-gtk-4.0/citydlg.c +++ b/client/gui-gtk-4.0/citydlg.c @@ -837,24 +837,12 @@ static GtkWidget *create_city_info_table(struct city_dialog *pdialog, " color: rgba(255, 0.0, 0.0, 255);\n" "}", -1); - } - /* GRANARY */ - gtk_style_context_add_provider(gtk_widget_get_style_context(info_label[INFO_GRANARY]), - GTK_STYLE_PROVIDER(emergency_provider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - /* GROWTH */ - gtk_style_context_add_provider(gtk_widget_get_style_context(info_label[INFO_GROWTH]), - GTK_STYLE_PROVIDER(emergency_provider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - /* POLLUTION */ - gtk_style_context_add_provider(gtk_widget_get_style_context(info_label[INFO_POLLUTION]), - GTK_STYLE_PROVIDER(emergency_provider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - /* ILLNESS */ - gtk_style_context_add_provider(gtk_widget_get_style_context(info_label[INFO_ILLNESS]), + gtk_style_context_add_provider_for_display( + gtk_widget_get_display(toplevel), GTK_STYLE_PROVIDER(emergency_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + } } gtk_widget_show(table); @@ -1926,29 +1914,29 @@ static void city_dialog_update_information(GtkWidget **info_label, /* For starvation, the "4" below is arbitrary. 3 turns should be enough * of a warning. */ if (granaryturns > -4 && granaryturns < 0) { - gtk_style_context_add_class(gtk_widget_get_style_context(info_label[INFO_GRANARY]), "emergency"); + gtk_widget_add_css_class(info_label[INFO_GRANARY], "emergency"); } else { - gtk_style_context_remove_class(gtk_widget_get_style_context(info_label[INFO_GRANARY]), "emergency"); + gtk_widget_remove_css_class(info_label[INFO_GRANARY], "emergency"); } if (granaryturns == 0 || pcity->surplus[O_FOOD] < 0) { - gtk_style_context_add_class(gtk_widget_get_style_context(info_label[INFO_GROWTH]), "emergency"); + gtk_widget_add_css_class(info_label[INFO_GROWTH], "emergency"); } else { - gtk_style_context_remove_class(gtk_widget_get_style_context(info_label[INFO_GROWTH]), "emergency"); + gtk_widget_remove_css_class(info_label[INFO_GROWTH], "emergency"); } - /* someone could add the color &orange for better granularity here */ + /* Someone could add the color &orange for better granularity here */ if (pcity->pollution >= 10) { - gtk_style_context_add_class(gtk_widget_get_style_context(info_label[INFO_POLLUTION]), "emergency"); + gtk_widget_add_css_class(info_label[INFO_POLLUTION], "emergency"); } else { - gtk_style_context_remove_class(gtk_widget_get_style_context(info_label[INFO_POLLUTION]), "emergency"); + gtk_widget_remove_css_class(info_label[INFO_POLLUTION], "emergency"); } - /* illness is in tenth of percent, i.e 100 == 10.0% */ + /* Illness is in tenth of percent, i.e 100 == 10.0% */ if (illness >= 100) { - gtk_style_context_add_class(gtk_widget_get_style_context(info_label[INFO_ILLNESS]), "emergency"); + gtk_widget_add_css_class(info_label[INFO_ILLNESS], "emergency"); } else { - gtk_style_context_remove_class(gtk_widget_get_style_context(info_label[INFO_ILLNESS]), "emergency"); + gtk_widget_remove_css_class(info_label[INFO_ILLNESS], "emergency"); } } diff --git a/client/gui-gtk-4.0/gui_main.c b/client/gui-gtk-4.0/gui_main.c index bd4f2f2cc2..9aceb95c64 100644 --- a/client/gui-gtk-4.0/gui_main.c +++ b/client/gui-gtk-4.0/gui_main.c @@ -804,11 +804,11 @@ static GtkWidget *detached_widget_fill(GtkWidget *tearbox) } b = gtk_toggle_button_new(); - gtk_style_context_add_provider(gtk_widget_get_style_context(b), + gtk_style_context_add_provider_for_display( + gtk_widget_get_display(toplevel), GTK_STYLE_PROVIDER(detach_button_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - gtk_style_context_add_class(gtk_widget_get_style_context(b), - "detach_button"); + gtk_widget_add_css_class(b, "detach_button"); gtk_box_append(GTK_BOX(tearbox), b); g_signal_connect(b, "toggled", G_CALLBACK(tearoff_callback), tearbox); diff --git a/client/gui-gtk-4.0/gui_stuff.c b/client/gui-gtk-4.0/gui_stuff.c index 2f7fff5eb3..ed493f41e5 100644 --- a/client/gui-gtk-4.0/gui_stuff.c +++ b/client/gui-gtk-4.0/gui_stuff.c @@ -407,10 +407,8 @@ static void gui_dialog_switch_page_handler(GtkNotebook *notebook, n = gtk_notebook_page_num(GTK_NOTEBOOK(dlg->v.tab.notebook), dlg->grid); if (n == num) { - GtkStyleContext *context = gtk_widget_get_style_context(dlg->v.tab.label); - - gtk_style_context_remove_class(context, "alert"); - gtk_style_context_remove_class(context, "notice"); + gtk_widget_remove_css_class(dlg->v.tab.label, "alert"); + gtk_widget_remove_css_class(dlg->v.tab.label, "notice"); } } @@ -594,9 +592,6 @@ void gui_dialog_new(struct gui_dialog **pdlg, GtkNotebook *notebook, G_CALLBACK(gui_dialog_switch_page_handler), dlg); dlg->v.tab.child = dlg->grid; - gtk_style_context_add_provider(gtk_widget_get_style_context(label), - GTK_STYLE_PROVIDER(dlg_tab_provider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); dlg->v.tab.label = label; dlg->v.tab.notebook = GTK_WIDGET(notebook); @@ -778,10 +773,7 @@ void gui_dialog_present(struct gui_dialog *dlg) n = gtk_notebook_page_num(notebook, dlg->grid); if (current != n) { - GtkWidget *label = dlg->v.tab.label; - - gtk_style_context_add_class(gtk_widget_get_style_context(label), - "notice"); + gtk_widget_add_css_class(dlg->v.tab.label, "notice"); } } break; @@ -830,12 +822,9 @@ void gui_dialog_alert(struct gui_dialog *dlg) n = gtk_notebook_page_num(notebook, dlg->grid); if (current != n) { - GtkWidget *label = dlg->v.tab.label; - GtkStyleContext *context = gtk_widget_get_style_context(label); - /* Have only alert - remove notice if it exist. */ - gtk_style_context_remove_class(context, "notice"); - gtk_style_context_add_class(context, "alert"); + gtk_widget_remove_css_class(dlg->v.tab.label, "notice"); + gtk_widget_add_css_class(dlg->v.tab.label, "alert"); } } break; @@ -1093,6 +1082,11 @@ void dlg_tab_provider_prepare(void) "color: rgba(0, 0, 255, 255);\n" "}\n", -1); + + gtk_style_context_add_provider_for_display( + gtk_widget_get_display(toplevel), + GTK_STYLE_PROVIDER(dlg_tab_provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } /**********************************************************************//** diff --git a/client/gui-gtk-4.0/mapview.c b/client/gui-gtk-4.0/mapview.c index 331be9ba15..e407ef6d0b 100644 --- a/client/gui-gtk-4.0/mapview.c +++ b/client/gui-gtk-4.0/mapview.c @@ -82,13 +82,12 @@ void update_turn_done_button(bool do_restore) if ((do_restore && flip) || !do_restore) { static GtkCssProvider *tdb_provider = NULL; - GtkStyleContext *scontext = gtk_widget_get_style_context(turn_done_button); if (tdb_provider == NULL) { tdb_provider = gtk_css_provider_new(); gtk_css_provider_load_from_data(tdb_provider, - ".lighted {\n" + ".td_lighted {\n" "color: rgba(235, 127, 235, 255);\n" "background-color: rgba(127, 127, 127, 255);\n" "}\n", @@ -96,15 +95,16 @@ void update_turn_done_button(bool do_restore) /* Turn Done button is persistent, so we only need to do this * once too. */ - gtk_style_context_add_provider(scontext, + gtk_style_context_add_provider_for_display( + gtk_widget_get_display(toplevel), GTK_STYLE_PROVIDER(tdb_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } if (flip) { - gtk_style_context_add_class(scontext, "lighted"); + gtk_widget_add_css_class(turn_done_button, "td_lighted"); } else { - gtk_style_context_remove_class(scontext, "lighted"); + gtk_widget_remove_css_class(turn_done_button, "td_lighted"); } flip = !flip; -- 2.40.1