[network-manager-applet] editor: fix displaying background color when highlighting errors
- From: Jiří Klimeš <jklimes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet] editor: fix displaying background color when highlighting errors
- Date: Tue, 3 Mar 2015 13:50:02 +0000 (UTC)
commit f224c151ea399119b88250156e2d2b98219032e2
Author: Jiří Klimeš <jklimes redhat com>
Date: Tue Mar 3 08:51:40 2015 +0100
editor: fix displaying background color when highlighting errors
gtk_widget_override_background_color() stopped working at some point [1] for
some Gtk themes, including default Adwaita (due to usage of background-image).
So we need to use GtkCssProvider. Anyway gtk_widget_override_background_color()
has been deprecated recently [2].
[1] https://bugzilla.gnome.org/show_bug.cgi?id=656461
[2] https://mail.gnome.org/archives/gtk-list/2015-February/msg00053.html
[3] http://trac.wxwidgets.org/ticket/14759
src/connection-editor/ip4-routes-dialog.c | 2 +-
src/connection-editor/ip6-routes-dialog.c | 2 +-
src/connection-editor/page-dcb.c | 20 +++++++++-----
src/connection-editor/page-ip4.c | 2 +-
src/connection-editor/page-ip6.c | 2 +-
src/utils/utils.c | 42 ++++++++++++++++++++++++++++-
src/utils/utils.h | 4 ++-
7 files changed, 61 insertions(+), 13 deletions(-)
---
diff --git a/src/connection-editor/ip4-routes-dialog.c b/src/connection-editor/ip4-routes-dialog.c
index e399e4d..89e8424 100644
--- a/src/connection-editor/ip4-routes-dialog.c
+++ b/src/connection-editor/ip4-routes-dialog.c
@@ -455,7 +455,7 @@ cell_changed_cb (GtkEditable *editable,
colorname = value_valid ? "lightgreen" : "red";
gdk_rgba_parse (&rgba, colorname);
- gtk_widget_override_background_color (GTK_WIDGET (editable), GTK_STATE_FLAG_NORMAL, &rgba);
+ utils_override_bg_color (GTK_WIDGET (editable), &rgba);
g_free (cell_text);
return FALSE;
diff --git a/src/connection-editor/ip6-routes-dialog.c b/src/connection-editor/ip6-routes-dialog.c
index 67197a7..31421d6 100644
--- a/src/connection-editor/ip6-routes-dialog.c
+++ b/src/connection-editor/ip6-routes-dialog.c
@@ -403,7 +403,7 @@ cell_changed_cb (GtkEditable *editable,
colorname = value_valid ? "lightgreen" : "red";
gdk_rgba_parse (&rgba, colorname);
- gtk_widget_override_background_color (GTK_WIDGET (editable), GTK_STATE_FLAG_NORMAL, &rgba);
+ utils_override_bg_color (GTK_WIDGET (editable), &rgba);
g_free (cell_text);
return FALSE;
diff --git a/src/connection-editor/page-dcb.c b/src/connection-editor/page-dcb.c
index a8f64fe..2d18666 100644
--- a/src/connection-editor/page-dcb.c
+++ b/src/connection-editor/page-dcb.c
@@ -107,6 +107,8 @@ uint_entries_validate (GtkBuilder *builder, const char *fmt, gint max, gboolean
gboolean valid = TRUE;
GdkRGBA bgcolor;
+ gdk_rgba_parse (&bgcolor, "red3");
+
for (i = 0; i < 8; i++) {
tmp = g_strdup_printf (fmt, i);
entry = GTK_ENTRY (gtk_builder_get_object (builder, tmp));
@@ -119,17 +121,20 @@ uint_entries_validate (GtkBuilder *builder, const char *fmt, gint max, gboolean
num = strtol (text, NULL, 10);
if (errno || num < 0 || num > max) {
/* FIXME: only sets highlight color? */
- gdk_rgba_parse (&bgcolor, "red3");
- gtk_widget_override_background_color (GTK_WIDGET (entry),
GTK_STATE_FLAG_NORMAL, &bgcolor);
+ utils_override_bg_color (GTK_WIDGET (entry), &bgcolor);
valid = FALSE;
} else
- gtk_widget_override_background_color (GTK_WIDGET (entry),
GTK_STATE_FLAG_NORMAL, NULL);
+ utils_override_bg_color (GTK_WIDGET (entry), NULL);
total += (guint) num;
+ if (sum && total > 100)
+ utils_override_bg_color (GTK_WIDGET (entry), &bgcolor);
}
}
- if (sum && total != 100)
+ if (sum && total != 100) {
+ utils_override_bg_color (GTK_WIDGET (entry), &bgcolor);
valid = FALSE;
+ }
return valid;
}
@@ -138,10 +143,11 @@ static void
pg_dialog_valid_func (GtkBuilder *builder)
{
GtkDialog *dialog;
- gboolean valid = FALSE;
+ gboolean b1, b2, valid = FALSE;
- valid = uint_entries_validate (builder, "pg_pgpct%u_entry", 100, TRUE) &&
- uint_entries_validate (builder, "pg_uppct%u_entry", 100, FALSE);
+ b1 = uint_entries_validate (builder, "pg_pgpct%u_entry", 100, TRUE);
+ b2 = uint_entries_validate (builder, "pg_uppct%u_entry", 100, FALSE);
+ valid = b1 && b2;
dialog = GTK_DIALOG (gtk_builder_get_object (builder, "pg_dialog"));
gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_OK, valid);
diff --git a/src/connection-editor/page-ip4.c b/src/connection-editor/page-ip4.c
index 1b6d1d8..66e2085 100644
--- a/src/connection-editor/page-ip4.c
+++ b/src/connection-editor/page-ip4.c
@@ -711,7 +711,7 @@ cell_changed_cb (GtkEditable *editable,
colorname = value_valid ? "lightgreen" : "red";
gdk_rgba_parse (&rgba, colorname);
- gtk_widget_override_background_color (GTK_WIDGET (editable), GTK_STATE_FLAG_NORMAL, &rgba);
+ utils_override_bg_color (GTK_WIDGET (editable), &rgba);
g_free (cell_text);
return FALSE;
diff --git a/src/connection-editor/page-ip6.c b/src/connection-editor/page-ip6.c
index 1e58b78..7c031a0 100644
--- a/src/connection-editor/page-ip6.c
+++ b/src/connection-editor/page-ip6.c
@@ -698,7 +698,7 @@ cell_changed_cb (GtkEditable *editable,
colorname = value_valid ? "lightgreen" : "red";
gdk_rgba_parse (&rgba, colorname);
- gtk_widget_override_background_color (GTK_WIDGET (editable), GTK_STATE_FLAG_NORMAL, &rgba);
+ utils_override_bg_color (GTK_WIDGET (editable), &rgba);
g_free (cell_text);
return FALSE;
diff --git a/src/utils/utils.c b/src/utils/utils.c
index 42db746..c9301fe 100644
--- a/src/utils/utils.c
+++ b/src/utils/utils.c
@@ -17,7 +17,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * Copyright 2007 - 2014 Red Hat, Inc.
+ * Copyright 2007 - 2015 Red Hat, Inc.
*/
#include <config.h>
@@ -477,3 +477,43 @@ utils_update_password_storage (NMSetting *setting,
}
}
+/**
+ * utils_override_bg_color:
+ *
+ * The function can be used to set background color for a widget.
+ * There are functions for that in Gtk2 [1] and Gtk3 [2]. Unfortunately, they
+ * have been deprecated, and moreover gtk_widget_override_background_color()
+ * stopped working at some point for some Gtk themes, including the default
+ * Adwaita theme.
+ * [1] gtk_widget_modify_bg() or gtk_widget_modify_base()
+ * [2] gtk_widget_override_background_color()
+ *
+ * Related links:
+ * https://bugzilla.gnome.org/show_bug.cgi?id=656461
+ * https://mail.gnome.org/archives/gtk-list/2015-February/msg00053.html
+ */
+void
+utils_override_bg_color (GtkWidget *widget, GdkRGBA *rgba)
+{
+ GtkCssProvider *provider;
+ char *css;
+
+ provider = (GtkCssProvider *) g_object_get_data (G_OBJECT (widget), "our-css-provider");
+ if (G_UNLIKELY (!provider)) {
+ provider = gtk_css_provider_new ();
+ gtk_style_context_add_provider (gtk_widget_get_style_context (widget),
+ GTK_STYLE_PROVIDER (provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ g_object_set_data_full (G_OBJECT (widget), "our-css-provider",
+ provider, (GDestroyNotify) g_object_unref);
+ }
+
+ if (rgba) {
+ css = g_strdup_printf ("* { background-color: %s; background-image: none; }",
+ gdk_rgba_to_string (rgba));
+ gtk_css_provider_load_from_data (provider, css, -1, NULL);
+ g_free (css);
+ } else
+ gtk_css_provider_load_from_data (provider, "", -1, NULL);
+}
+
diff --git a/src/utils/utils.h b/src/utils/utils.h
index 5adb20d..3e3d31b 100644
--- a/src/utils/utils.h
+++ b/src/utils/utils.h
@@ -17,7 +17,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * Copyright 2007 - 2014 Red Hat, Inc.
+ * Copyright 2007 - 2015 Red Hat, Inc.
*/
#ifndef UTILS_H
@@ -100,5 +100,7 @@ void utils_update_password_storage (NMSetting *setting,
GtkWidget *passwd_entry,
const char *password_flags_name);
+void utils_override_bg_color (GtkWidget *widget, GdkRGBA *rgba);
+
#endif /* UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]