From 4c0f1e7f4cd136ef515529df9330989f398ed6a1 Mon Sep 17 00:00:00 2001 From: Martin Kutlak Date: Thu, 8 Jun 2017 12:06:40 +0200 Subject: [PATCH] gui: replace gtk_widget_override functions gtk_widget_override_{font, color} functions were deprecated in version 3.16. Elements should be styled with CSS. https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-override-color Signed-off-by: Martin Kutlak --- src/gtk-helpers/event_config_dialog.c | 17 +++++---- src/gui-wizard-gtk/wizard.c | 55 +++++++++++++++------------ 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/src/gtk-helpers/event_config_dialog.c b/src/gtk-helpers/event_config_dialog.c index 421a156..029e459 100644 --- a/src/gtk-helpers/event_config_dialog.c +++ b/src/gtk-helpers/event_config_dialog.c @@ -292,13 +292,16 @@ config_dialog_t *create_event_config_dialog_content(event_config_t *event, GtkWi GtkWidget *keyring_warn_lbl = gtk_label_new( _("Secret Service is not available, your settings won't be saved!")); - static const GdkRGBA red = { - .red = 1.0, - .green = 0.0, - .blue = 0.0, - .alpha = 1.0, - }; - gtk_widget_override_color(keyring_warn_lbl, GTK_STATE_FLAG_NORMAL, &red); + gtk_widget_set_name(keyring_warn_lbl, "keyring_warn_lbl"); + + GtkCssProvider *g_provider = gtk_css_provider_new(); + gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), + GTK_STYLE_PROVIDER(g_provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + const gchar *data = "#keyring_warn_lbl {color: rgba(100%, 0%, 0%, 1);}"; + gtk_css_provider_load_from_data(g_provider, data, -1, NULL); + g_object_unref (g_provider); + gtk_box_pack_start(GTK_BOX(content), keyring_warn_lbl, false, false, 0); } diff --git a/src/gui-wizard-gtk/wizard.c b/src/gui-wizard-gtk/wizard.c index 634a508..e19f790 100644 --- a/src/gui-wizard-gtk/wizard.c +++ b/src/gui-wizard-gtk/wizard.c @@ -61,6 +61,8 @@ static guint g_event_source_id = 0; static bool g_expert_mode; +static GtkCssProvider *g_provider = NULL; + static GtkNotebook *g_assistant; static GtkWindow *g_wnd_assistant; static GtkBox *g_box_assistant; @@ -172,7 +174,6 @@ enum }; static GtkBuilder *g_builder; -static PangoFontDescription *g_monospace_font; /* THE PAGE FLOW * page_0: introduction/summary @@ -294,6 +295,20 @@ static GtkBuilder *make_builder() return builder; } +static void load_css_style() +{ + g_provider = gtk_css_provider_new(); + gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), + GTK_STYLE_PROVIDER(g_provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + const gchar *data = "#green_color {color: rgba(0%, 50%, 0%, 1);}\ + #red_color {color: rgba(100%, 0%, 0%, 1);}\ + #tev, #g_tv_event_log {font-family: monospace;}\ + #g_eb_comment {color: #CC3333;}"; + gtk_css_provider_load_from_data(g_provider, data, -1, NULL); + g_object_unref (g_provider); +} + static void label_wrapper(GtkWidget *widget, gpointer data_unused) { if (GTK_IS_CONTAINER(widget)) @@ -1061,6 +1076,9 @@ static event_gui_data_t *add_event_buttons(GtkBox *box, char *event_name, GCallback func) { + if (g_provider == NULL) + load_css_style(); + //log_info("removing all buttons from box %p", box); gtk_container_foreach(GTK_CONTAINER(box), &remove_child_widget, NULL); g_list_foreach(*p_event_list, (GFunc)free_event_gui_data_t, NULL); @@ -1155,21 +1173,8 @@ static event_gui_data_t *add_event_buttons(GtkBox *box, GtkWidget *child = gtk_bin_get_child(GTK_BIN(button)); if (child) { - static const GdkRGBA red = { - .red = 1.0, - .green = 0.0, - .blue = 0.0, - .alpha = 1.0, - }; - static const GdkRGBA green = { - .red = 0.0, - .green = 0.5, - .blue = 0.0, - .alpha = 1.0, - }; - const GdkRGBA *color = (green_choice ? &green : &red); - //gtk_widget_modify_text(button, GTK_STATE_NORMAL, color); - gtk_widget_override_color(child, GTK_STATE_FLAG_NORMAL, color); + const char *child_name = (green_choice ? "green_color" : "red_color"); + gtk_widget_set_name(child, child_name); } } @@ -1321,6 +1326,9 @@ static void remove_tabs_from_notebook(GtkNotebook *notebook) static void append_item_to_ls_details(gpointer name, gpointer value, gpointer data) { + if (g_provider == NULL) + load_css_style(); + problem_item *item = (problem_item*)value; struct cd_stats *stats = data; GtkTreeIter iter; @@ -1335,11 +1343,11 @@ static void append_item_to_ls_details(gpointer name, gpointer value, gpointer da { GtkWidget *tab_lbl = gtk_label_new((char *)name); GtkWidget *tev = gtk_text_view_new(); + gtk_widget_set_name(GTK_WIDGET(tev), "tev"); if (strcmp(name, FILENAME_COMMENT) == 0 || strcmp(name, FILENAME_REASON) == 0) gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(tev), GTK_WRAP_WORD); - gtk_widget_override_font(GTK_WIDGET(tev), g_monospace_font); load_text_to_text_view(GTK_TEXT_VIEW(tev), (char *)name); /* init searching */ GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(tev)); @@ -3503,6 +3511,9 @@ static void add_pages(void) { g_builder = make_builder(); + if (g_provider == NULL) + load_css_style(); + int i; int page_no = 0; for (i = 0; page_names[i] != NULL; i++) @@ -3549,7 +3560,9 @@ static void add_pages(void) gtk_widget_set_no_show_all(GTK_WIDGET(g_spinner_event_log), true); - gtk_widget_override_font(GTK_WIDGET(g_tv_event_log), g_monospace_font); + gtk_widget_set_name(GTK_WIDGET(g_tv_event_log), "g_tv_event_log"); + gtk_widget_set_name(GTK_WIDGET(g_eb_comment), "g_eb_comment"); + fix_all_wrapped_labels(GTK_WIDGET(g_assistant)); g_signal_connect(g_cb_no_comment, "toggled", G_CALLBACK(on_no_comment_toggled), NULL); @@ -3557,10 +3570,6 @@ static void add_pages(void) g_signal_connect(g_rb_forbidden_words, "toggled", G_CALLBACK(on_forbidden_words_toggled), NULL); g_signal_connect(g_rb_custom_search, "toggled", G_CALLBACK(on_custom_search_toggled), NULL); - /* Set color of the comment evenbox */ - GdkRGBA color; - gdk_rgba_parse(&color, "#CC3333"); - gtk_widget_override_color(GTK_WIDGET(g_eb_comment), GTK_STATE_FLAG_NORMAL, &color); g_signal_connect(g_tv_details, "key-press-event", G_CALLBACK(on_key_press_event_in_item_list), NULL); g_tv_sensitive_sel_hndlr = g_signal_connect(g_tv_sensitive_sel, "changed", G_CALLBACK(on_sensitive_word_selection_changed), NULL); @@ -3730,8 +3739,6 @@ void create_assistant(GtkApplication *app, bool expert_mode) g_expert_mode = expert_mode; - g_monospace_font = pango_font_description_from_string("monospace"); - g_assistant = GTK_NOTEBOOK(gtk_notebook_new()); /* Show tabs only in verbose expert mode -- 2.21.0