[gtk+] Set infobar css classes permanently
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Set infobar css classes permanently
- Date: Fri, 24 Feb 2012 07:18:22 +0000 (UTC)
commit 4a6658b0faf1ece6183dad8578af880badee98ba
Author: Paolo Borelli <pborelli gnome org>
Date: Tue Feb 21 23:42:39 2012 +0100
Set infobar css classes permanently
The message-type css classes must be in the widget context all the time,
not only when drawing, otherwise they are not propagated to the
children, for instance a label in the InfoBar must inherit the
color. Add a corresponding reftest.
https://bugzilla.gnome.org/show_bug.cgi?id=670555
gtk/gtkinfobar.c | 34 ++--
tests/reftests/Makefile.am | 3 +
tests/reftests/info-bar-message-types.css | 54 ++++++
tests/reftests/info-bar-message-types.ref.ui | 84 ++++++++++
tests/reftests/info-bar-message-types.ui | 229 ++++++++++++++++++++++++++
5 files changed, 388 insertions(+), 16 deletions(-)
---
diff --git a/gtk/gtkinfobar.c b/gtk/gtkinfobar.c
index 88d6046..528625f 100644
--- a/gtk/gtkinfobar.c
+++ b/gtk/gtkinfobar.c
@@ -290,13 +290,6 @@ gtk_info_bar_draw (GtkWidget *widget,
cairo_t *cr)
{
GtkInfoBarPrivate *priv = GTK_INFO_BAR (widget)->priv;
- const char* type_class[] = {
- GTK_STYLE_CLASS_INFO,
- GTK_STYLE_CLASS_WARNING,
- GTK_STYLE_CLASS_QUESTION,
- GTK_STYLE_CLASS_ERROR,
- NULL
- };
if (priv->message_type != GTK_MESSAGE_OTHER)
{
@@ -304,20 +297,12 @@ gtk_info_bar_draw (GtkWidget *widget,
context = gtk_widget_get_style_context (widget);
- gtk_style_context_save (context);
-
- if (type_class[priv->message_type])
- gtk_style_context_add_class (context,
- type_class[priv->message_type]);
-
gtk_render_background (context, cr, 0, 0,
gtk_widget_get_allocated_width (widget),
gtk_widget_get_allocated_height (widget));
gtk_render_frame (context, cr, 0, 0,
gtk_widget_get_allocated_width (widget),
gtk_widget_get_allocated_height (widget));
-
- gtk_style_context_restore (context);
}
if (GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->draw)
@@ -1091,7 +1076,6 @@ gtk_info_bar_set_message_type (GtkInfoBar *info_bar,
GtkMessageType message_type)
{
GtkInfoBarPrivate *priv;
- AtkObject *atk_obj;
g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
@@ -1099,6 +1083,21 @@ gtk_info_bar_set_message_type (GtkInfoBar *info_bar,
if (priv->message_type != message_type)
{
+ GtkStyleContext *context;
+ AtkObject *atk_obj;
+ const char *type_class[] = {
+ GTK_STYLE_CLASS_INFO,
+ GTK_STYLE_CLASS_WARNING,
+ GTK_STYLE_CLASS_QUESTION,
+ GTK_STYLE_CLASS_ERROR,
+ NULL
+ };
+
+ context = gtk_widget_get_style_context (GTK_WIDGET (info_bar));
+
+ if (type_class[priv->message_type])
+ gtk_style_context_remove_class (context, type_class[priv->message_type]);
+
priv->message_type = message_type;
gtk_widget_queue_draw (GTK_WIDGET (info_bar));
@@ -1144,6 +1143,9 @@ gtk_info_bar_set_message_type (GtkInfoBar *info_bar,
}
}
+ if (type_class[priv->message_type])
+ gtk_style_context_add_class (context, type_class[priv->message_type]);
+
g_object_notify (G_OBJECT (info_bar), "message-type");
}
}
diff --git a/tests/reftests/Makefile.am b/tests/reftests/Makefile.am
index c592ed4..ec63260 100644
--- a/tests/reftests/Makefile.am
+++ b/tests/reftests/Makefile.am
@@ -144,6 +144,9 @@ EXTRA_DIST += \
grid-spacing3.css \
grid-spacing3.ref.ui \
grid-spacing3.ui \
+ info-bar-message-types.css \
+ info-bar-message-types.ref.ui \
+ info-bar-message-types.ui \
inherit-and-initial.css \
inherit-and-initial.ref.ui \
inherit-and-initial.ui \
diff --git a/tests/reftests/info-bar-message-types.css b/tests/reftests/info-bar-message-types.css
new file mode 100644
index 0000000..775601c
--- /dev/null
+++ b/tests/reftests/info-bar-message-types.css
@@ -0,0 +1,54 @@
+ import "reset-to-defaults.css";
+
+.info {
+/* FIXME: for now label does not support background */
+/* background-color: @info_bg_color;*/
+ color: @info_fg_color;
+}
+
+.warning {
+/* background-color: @warning_bg_color;*/
+ color: @warning_fg_color;
+}
+
+.question {
+/* background-color: @question_bg_color;*/
+ color: @question_fg_color;
+}
+
+.error {
+/* background-color: @error_bg_color;*/
+ color: @error_fg_color;
+}
+
+#reference-info {
+ padding: 8px;
+ color: @info_fg_color;
+ background-color: @info_bg_color;
+ background-image: none;
+}
+
+#reference-warning {
+ padding: 8px;
+ color: @warning_fg_color;
+ background-color: @warning_bg_color;
+ background-image: none;
+}
+
+#reference-question {
+ padding: 8px;
+ color: @question_fg_color;
+ background-color: @question_bg_color;
+ background-image: none;
+}
+
+#reference-error {
+ padding: 8px;
+ color: @error_fg_color;
+ background-color: @error_bg_color;
+ background-image: none;
+}
+
+#reference-other {
+ padding: 8px;
+}
diff --git a/tests/reftests/info-bar-message-types.ref.ui b/tests/reftests/info-bar-message-types.ref.ui
new file mode 100644
index 0000000..21dd796
--- /dev/null
+++ b/tests/reftests/info-bar-message-types.ref.ui
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <object class="GtkWindow" id="window1">
+ <property name="can_focus">False</property>
+ <property name="type">popup</property>
+ <child>
+ <object class="GtkGrid" id="grid1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Info</property>
+ <property name="name">reference-info</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Warning</property>
+ <property name="name">reference-warning</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Question</property>
+ <property name="name">reference-question</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label4">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Error</property>
+ <property name="name">reference-error</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label5">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Other</property>
+ <property name="name">reference-other</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">4</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/tests/reftests/info-bar-message-types.ui b/tests/reftests/info-bar-message-types.ui
new file mode 100644
index 0000000..1c38d80
--- /dev/null
+++ b/tests/reftests/info-bar-message-types.ui
@@ -0,0 +1,229 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <object class="GtkWindow" id="window1">
+ <property name="can_focus">False</property>
+ <property name="type">popup</property>
+ <child>
+ <object class="GtkGrid" id="grid1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkInfoBar" id="infobar1">
+ <property name="visible">True</property>
+ <property name="app_paintable">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">horizontal</property>
+ <property name="message_type">info</property>
+ <child internal-child="content_area">
+ <object class="GtkBox" id="infobar-content_area1">
+ <property name="can_focus">False</property>
+ <property name="border_width">8</property>
+ <property name="spacing">16</property>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Info</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox" id="infobar-action_area1">
+ <property name="can_focus">False</property>
+ <property name="border_width">0</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <property name="layout_style">end</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkInfoBar" id="infobar2">
+ <property name="visible">True</property>
+ <property name="app_paintable">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">horizontal</property>
+ <property name="message_type">warning</property>
+ <child internal-child="content_area">
+ <object class="GtkBox" id="infobar-content_area2">
+ <property name="can_focus">False</property>
+ <property name="border_width">8</property>
+ <property name="spacing">16</property>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Warning</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox" id="infobar-action_area2">
+ <property name="can_focus">False</property>
+ <property name="border_width">0</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <property name="layout_style">end</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkInfoBar" id="infobar3">
+ <property name="visible">True</property>
+ <property name="app_paintable">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">horizontal</property>
+ <property name="message_type">question</property>
+ <child internal-child="content_area">
+ <object class="GtkBox" id="infobar-content_area3">
+ <property name="can_focus">False</property>
+ <property name="border_width">8</property>
+ <property name="spacing">16</property>
+ <child>
+ <object class="GtkLabel" id="label3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Question</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox" id="infobar-action_area3">
+ <property name="can_focus">False</property>
+ <property name="border_width">0</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <property name="layout_style">end</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkInfoBar" id="infobar4">
+ <property name="visible">True</property>
+ <property name="app_paintable">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">horizontal</property>
+ <property name="message_type">error</property>
+ <child internal-child="content_area">
+ <object class="GtkBox" id="infobar-content_area4">
+ <property name="can_focus">False</property>
+ <property name="border_width">8</property>
+ <property name="spacing">16</property>
+ <child>
+ <object class="GtkLabel" id="label4">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Error</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox" id="infobar-action_area4">
+ <property name="can_focus">False</property>
+ <property name="border_width">0</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <property name="layout_style">end</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkInfoBar" id="infobar5">
+ <property name="visible">True</property>
+ <property name="app_paintable">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">horizontal</property>
+ <property name="message_type">other</property>
+ <child internal-child="content_area">
+ <object class="GtkBox" id="infobar-content_area5">
+ <property name="can_focus">False</property>
+ <property name="border_width">8</property>
+ <property name="spacing">16</property>
+ <child>
+ <object class="GtkLabel" id="label5">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Other</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox" id="infobar-action_area5">
+ <property name="can_focus">False</property>
+ <property name="border_width">0</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <property name="layout_style">end</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">4</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]