[gtksourceview] Support underline-color



commit 0f1ca2fc07d63971d3760662b6fad783c45c3839
Author: Paolo Borelli <pborelli gnome org>
Date:   Tue May 12 22:06:34 2015 +0200

    Support underline-color

 docs/reference/style-reference.xml     |    6 +++
 gtksourceview/gtksourcestyle-private.h |    4 ++-
 gtksourceview/gtksourcestyle.c         |   61 +++++++++++++++++++++++++++++++-
 gtksourceview/gtksourcestylescheme.c   |   30 +++++++++++++---
 4 files changed, 94 insertions(+), 7 deletions(-)
---
diff --git a/docs/reference/style-reference.xml b/docs/reference/style-reference.xml
index c15b8f8..35c5b95 100644
--- a/docs/reference/style-reference.xml
+++ b/docs/reference/style-reference.xml
@@ -151,6 +151,12 @@ for backward compatibility.
 </para></listitem>
 </varlistentry>
 <varlistentry>
+<term><code>underline-color</code></term>
+<listitem><para>
+Underline color.
+</para></listitem>
+</varlistentry>
+<varlistentry>
 <term><code>strikethrough</code></term>
 <listitem><para>"true" or "false"</para></listitem>
 </varlistentry>
diff --git a/gtksourceview/gtksourcestyle-private.h b/gtksourceview/gtksourcestyle-private.h
index c0d9a31..8334081 100644
--- a/gtksourceview/gtksourcestyle-private.h
+++ b/gtksourceview/gtksourcestyle-private.h
@@ -36,7 +36,8 @@ enum
        GTK_SOURCE_STYLE_USE_BOLD            = 1 << 4,  /*< nick=use_bold >*/
        GTK_SOURCE_STYLE_USE_UNDERLINE       = 1 << 5,  /*< nick=use_underline >*/
        GTK_SOURCE_STYLE_USE_STRIKETHROUGH   = 1 << 6,  /*< nick=use_strikethrough >*/
-       GTK_SOURCE_STYLE_USE_SCALE           = 1 << 7   /*< nick=use_scale >*/
+       GTK_SOURCE_STYLE_USE_SCALE           = 1 << 7,  /*< nick=use_scale >*/
+       GTK_SOURCE_STYLE_USE_UNDERLINE_COLOR = 1 << 8   /*< nick=use_underline_color >*/
 };
 
 struct _GtkSourceStyle
@@ -50,6 +51,7 @@ struct _GtkSourceStyle
        const gchar *background;
        const gchar *line_background;
        const gchar *scale;
+       const gchar *underline_color;
 
        PangoUnderline underline;
 
diff --git a/gtksourceview/gtksourcestyle.c b/gtksourceview/gtksourcestyle.c
index 3b6cf3f..6b2327c 100644
--- a/gtksourceview/gtksourcestyle.c
+++ b/gtksourceview/gtksourcestyle.c
@@ -69,7 +69,9 @@ enum
        PROP_STRIKETHROUGH,
        PROP_STRIKETHROUGH_SET,
        PROP_SCALE,
-       PROP_SCALE_SET
+       PROP_SCALE_SET,
+       PROP_UNDERLINE_COLOR,
+       PROP_UNDERLINE_COLOR_SET
 };
 
 static void
@@ -163,6 +165,14 @@ gtk_source_style_class_init (GtkSourceStyleClass *klass)
                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
        g_object_class_install_property (object_class,
+                                        PROP_UNDERLINE_COLOR,
+                                        g_param_spec_string ("underline-color",
+                                                             "Underline Color",
+                                                             "Underline color",
+                                                             NULL,
+                                                             G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+       g_object_class_install_property (object_class,
                                         PROP_LINE_BACKGROUND_SET,
                                         g_param_spec_boolean ("line-background-set",
                                                               "Line background set",
@@ -225,6 +235,14 @@ gtk_source_style_class_init (GtkSourceStyleClass *klass)
                                                               "Whether scale attribute is set",
                                                               FALSE,
                                                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+       g_object_class_install_property (object_class,
+                                        PROP_UNDERLINE_COLOR_SET,
+                                        g_param_spec_boolean ("underline-color-set",
+                                                              "Underline color set",
+                                                              "Whether underline color attribute is set",
+                                                              FALSE,
+                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 }
 
 static void
@@ -341,6 +359,20 @@ gtk_source_style_set_property (GObject      *object,
                        }
                        break;
 
+               case PROP_UNDERLINE_COLOR:
+                       string = g_value_get_string (value);
+                       if (string != NULL)
+                       {
+                               style->underline_color = g_intern_string (string);
+                               SET_MASK (style, UNDERLINE_COLOR);
+                       }
+                       else
+                       {
+                               style->underline_color = NULL;
+                               UNSET_MASK (style, UNDERLINE_COLOR);
+                       }
+                       break;
+
                case PROP_FOREGROUND_SET:
                        MODIFY_MASK (style, value, FOREGROUND);
                        break;
@@ -368,10 +400,15 @@ gtk_source_style_set_property (GObject      *object,
                case PROP_STRIKETHROUGH_SET:
                        MODIFY_MASK (style, value, STRIKETHROUGH);
                        break;
+
                case PROP_SCALE_SET:
                        MODIFY_MASK (style, value, SCALE);
                        break;
 
+               case PROP_UNDERLINE_COLOR_SET:
+                       MODIFY_MASK (style, value, UNDERLINE_COLOR);
+                       break;
+
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                        break;
@@ -424,6 +461,10 @@ gtk_source_style_get_property (GObject      *object,
                        g_value_set_string (value, style->scale);
                        break;
 
+               case PROP_UNDERLINE_COLOR:
+                       g_value_set_string (value, style->underline_color);
+                       break;
+
                case PROP_FOREGROUND_SET:
                        GET_MASK (style, value, FOREGROUND);
                        break;
@@ -456,6 +497,10 @@ gtk_source_style_get_property (GObject      *object,
                        GET_MASK (style, value, SCALE);
                        break;
 
+               case PROP_UNDERLINE_COLOR_SET:
+                       GET_MASK (style, value, UNDERLINE_COLOR);
+                       break;
+
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                        break;
@@ -489,6 +534,7 @@ gtk_source_style_copy (const GtkSourceStyle *style)
        copy->italic = style->italic;
        copy->bold = style->bold;
        copy->underline = style->underline;
+       copy->underline_color = style->underline_color;
        copy->strikethrough = style->strikethrough;
        copy->mask = style->mask;
        copy->scale = style->scale;
@@ -572,6 +618,18 @@ _gtk_source_style_apply (const GtkSourceStyle *style,
                        g_object_set (tag, "underline-set", FALSE, NULL);
                }
 
+               if (style->mask & GTK_SOURCE_STYLE_USE_UNDERLINE_COLOR)
+               {
+                       GdkRGBA underline_rgba;
+
+                       gdk_rgba_parse (&underline_rgba, style->underline_color);
+                       g_object_set (tag, "underline-rgba", &underline_rgba, NULL);
+               }
+               else
+               {
+                       g_object_set (tag, "underline-rgba-set", FALSE, NULL);
+               }
+
                if (style->mask & GTK_SOURCE_STYLE_USE_STRIKETHROUGH)
                {
                        g_object_set (tag, "strikethrough", style->strikethrough != 0, NULL);
@@ -636,6 +694,7 @@ _gtk_source_style_apply (const GtkSourceStyle *style,
                              "style-set", FALSE,
                              "weight-set", FALSE,
                              "underline-set", FALSE,
+                             "underline-rgba-set", FALSE,
                              "strikethrough-set", FALSE,
                              "scale-set", FALSE,
                              NULL);
diff --git a/gtksourceview/gtksourcestylescheme.c b/gtksourceview/gtksourcestylescheme.c
index 1f147d8..f9c2e89 100644
--- a/gtksourceview/gtksourcestylescheme.c
+++ b/gtksourceview/gtksourcestylescheme.c
@@ -440,7 +440,8 @@ fix_style_colors (GtkSourceStyleScheme *scheme,
        } attributes[] = {
                { GTK_SOURCE_STYLE_USE_BACKGROUND, G_STRUCT_OFFSET (GtkSourceStyle, background) },
                { GTK_SOURCE_STYLE_USE_FOREGROUND, G_STRUCT_OFFSET (GtkSourceStyle, foreground) },
-               { GTK_SOURCE_STYLE_USE_LINE_BACKGROUND, G_STRUCT_OFFSET (GtkSourceStyle, line_background) }
+               { GTK_SOURCE_STYLE_USE_LINE_BACKGROUND, G_STRUCT_OFFSET (GtkSourceStyle, line_background) },
+               { GTK_SOURCE_STYLE_USE_UNDERLINE_COLOR, G_STRUCT_OFFSET (GtkSourceStyle, underline_color) }
        };
 
        style = gtk_source_style_copy (real_style);
@@ -965,6 +966,7 @@ parse_style (GtkSourceStyleScheme *scheme,
        gboolean italic = FALSE;
        gboolean strikethrough = FALSE;
        xmlChar *underline = NULL;
+       xmlChar *underline_color = NULL;
        xmlChar *scale = NULL;
        xmlChar *tmp;
 
@@ -1012,11 +1014,18 @@ parse_style (GtkSourceStyleScheme *scheme,
        get_bool (node, "bold", &mask, GTK_SOURCE_STYLE_USE_BOLD, &bold);
        get_bool (node, "strikethrough", &mask, GTK_SOURCE_STYLE_USE_STRIKETHROUGH, &strikethrough);
        underline = xmlGetProp (node, BAD_CAST "underline");
+       underline_color = xmlGetProp (node, BAD_CAST "underline-color");
        scale = xmlGetProp (node, BAD_CAST "scale");
 
        if (use_style)
        {
-               if (fg != NULL || bg != NULL || line_bg != NULL || mask != 0 || underline != NULL || scale != 
NULL)
+               if (fg != NULL ||
+                   bg != NULL ||
+                   line_bg != NULL ||
+                   mask != 0 ||
+                   underline != NULL ||
+                   underline_color != NULL ||
+                   scale != NULL)
                {
                        g_set_error (error, ERROR_QUARK, 0,
                                     "in style '%s': style attributes used along with use-style",
@@ -1026,6 +1035,9 @@ parse_style (GtkSourceStyleScheme *scheme,
                        xmlFree (fg);
                        xmlFree (bg);
                        xmlFree (line_bg);
+                       xmlFree (underline);
+                       xmlFree (underline_color);
+                       xmlFree (scale);
                        return FALSE;
                }
 
@@ -1091,6 +1103,12 @@ parse_style (GtkSourceStyleScheme *scheme,
                        }
                }
 
+               if (underline_color != NULL)
+               {
+                       result->underline_color = g_intern_string ((char*) underline_color);
+                       result->mask |= GTK_SOURCE_STYLE_USE_UNDERLINE_COLOR;
+               }
+
                if (scale != NULL)
                {
                        result->scale = g_intern_string ((char*) scale);
@@ -1101,10 +1119,12 @@ parse_style (GtkSourceStyleScheme *scheme,
        *style_p = result;
        *style_name_p = style_name;
 
-       xmlFree (scale);
-       xmlFree (line_bg);
-       xmlFree (bg);
        xmlFree (fg);
+       xmlFree (bg);
+       xmlFree (line_bg);
+       xmlFree (underline);
+       xmlFree (underline_color);
+       xmlFree (scale);
 
        return TRUE;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]