[gtksourceview/wip/fix-deprecations: 69/69] StyleScheme: style cursors with CSS (not finished)



commit e72944eec2a594fc65bb7732378a2cde904b50e0
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Nov 26 21:59:16 2014 +0100

    StyleScheme: style cursors with CSS (not finished)
    
    To avoid using deprecated GTK+ functions.
    
    CSS example:
    
    GtkSourceView {
            -GtkWidget-cursor-color: red;
            -GtkWidget-secondary-cursor-color: green;
    }

 gtksourceview/gtksourcestylescheme.c |  130 +++++++++++++++++++---------------
 1 files changed, 74 insertions(+), 56 deletions(-)
---
diff --git a/gtksourceview/gtksourcestylescheme.c b/gtksourceview/gtksourcestylescheme.c
index 120b709..dcccb04 100644
--- a/gtksourceview/gtksourcestylescheme.c
+++ b/gtksourceview/gtksourcestylescheme.c
@@ -653,52 +653,6 @@ _gtk_source_style_scheme_get_background_pattern_color (GtkSourceStyleScheme *sch
        return get_color (style, FALSE, color);
 }
 
-static void
-update_cursor_colors (GtkWidget      *widget,
-                     GtkSourceStyle *style_primary,
-                     GtkSourceStyle *style_secondary)
-{
-       GdkRGBA primary_color;
-       GdkRGBA secondary_color;
-       GdkRGBA *primary = NULL;
-       GdkRGBA *secondary = NULL;
-
-       if (get_color (style_primary, TRUE, &primary_color))
-       {
-               primary = &primary_color;
-       }
-
-       if (get_color (style_secondary, TRUE, &secondary_color))
-       {
-               secondary = &secondary_color;
-       }
-
-       if (primary != NULL && secondary == NULL)
-       {
-               GtkStyleContext *context;
-
-               context = gtk_widget_get_style_context (widget);
-               gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL,
-                                                       &secondary_color);
-
-               /* shade the secondary cursor */
-               secondary_color.red *= 0.5;
-               secondary_color.green *= 0.5;
-               secondary_color.blue *= 0.5;
-
-               secondary = &secondary_color;
-       }
-
-       if (primary != NULL)
-       {
-               gtk_widget_override_cursor (widget, primary, secondary);
-       }
-       else
-       {
-               gtk_widget_override_cursor (widget, NULL, NULL);
-       }
-}
-
 /**
  * _gtk_source_style_scheme_apply:
  * @scheme:: a #GtkSourceStyleScheme.
@@ -712,7 +666,6 @@ void
 _gtk_source_style_scheme_apply (GtkSourceStyleScheme *scheme,
                                GtkWidget            *widget)
 {
-       GtkSourceStyle *style, *style2;
        GtkStyleContext *context;
 
        g_return_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme));
@@ -728,10 +681,6 @@ _gtk_source_style_scheme_apply (GtkSourceStyleScheme *scheme,
        /* See https://bugzilla.gnome.org/show_bug.cgi?id=708583 */
        gtk_style_context_invalidate (context);
        G_GNUC_END_IGNORE_DEPRECATIONS;
-
-       style = gtk_source_style_scheme_get_style (scheme, STYLE_CURSOR);
-       style2 = gtk_source_style_scheme_get_style (scheme, STYLE_SECONDARY_CURSOR);
-       update_cursor_colors (widget, style, style2);
 }
 
 /**
@@ -760,8 +709,6 @@ _gtk_source_style_scheme_unapply (GtkSourceStyleScheme *scheme,
        /* See https://bugzilla.gnome.org/show_bug.cgi?id=708583 */
        gtk_style_context_invalidate (context);
        G_GNUC_END_IGNORE_DEPRECATIONS;
-
-       update_cursor_colors (widget, NULL, NULL);
 }
 
 /* --- PARSER ---------------------------------------------------------------- */
@@ -825,6 +772,75 @@ append_css_style (GString        *string,
 }
 
 static void
+append_cursors_css_style (GtkSourceStyleScheme *scheme,
+                         GString              *string)
+{
+       GtkSourceStyle *primary_style;
+       GtkSourceStyle *secondary_style;
+       GdkRGBA primary_color;
+       GdkRGBA secondary_color;
+
+       primary_style = gtk_source_style_scheme_get_style (scheme, STYLE_CURSOR);
+       secondary_style = gtk_source_style_scheme_get_style (scheme, STYLE_SECONDARY_CURSOR);
+
+       if (!get_color (primary_style, TRUE, &primary_color))
+       {
+               return;
+       }
+
+       if (!get_color (secondary_style, TRUE, &secondary_color))
+       {
+               /* TODO get background color */
+       }
+}
+
+static void
+update_cursor_colors (GtkWidget      *widget,
+                     GtkSourceStyle *style_primary,
+                     GtkSourceStyle *style_secondary)
+{
+       GdkRGBA primary_color;
+       GdkRGBA secondary_color;
+       GdkRGBA *primary = NULL;
+       GdkRGBA *secondary = NULL;
+
+       if (get_color (style_primary, TRUE, &primary_color))
+       {
+               primary = &primary_color;
+       }
+
+       if (get_color (style_secondary, TRUE, &secondary_color))
+       {
+               secondary = &secondary_color;
+       }
+
+       if (primary != NULL && secondary == NULL)
+       {
+               GtkStyleContext *context;
+
+               context = gtk_widget_get_style_context (widget);
+               gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL,
+                                                       &secondary_color);
+
+               /* shade the secondary cursor */
+               secondary_color.red *= 0.5;
+               secondary_color.green *= 0.5;
+               secondary_color.blue *= 0.5;
+
+               secondary = &secondary_color;
+       }
+
+       if (primary != NULL)
+       {
+               gtk_widget_override_cursor (widget, primary, secondary);
+       }
+       else
+       {
+               gtk_widget_override_cursor (widget, NULL, NULL);
+       }
+}
+
+static void
 generate_css_style (GtkSourceStyleScheme *scheme)
 {
        GString *final_style;
@@ -839,9 +855,9 @@ generate_css_style (GtkSourceStyleScheme *scheme)
        append_css_style (final_style, style, ".view:selected:focused");
 
        style2 = gtk_source_style_scheme_get_style (scheme, STYLE_SELECTED_UNFOCUSED);
-       if (style2 == NULL)
-               style2 = style;
-       append_css_style (final_style, style2, ".view:selected");
+       append_css_style (final_style,
+                         style2 != NULL ? style2 : style,
+                         ".view:selected");
 
        /* For now we use "line numbers" colors for all the gutters */
        style = gtk_source_style_scheme_get_style (scheme, STYLE_LINE_NUMBERS);
@@ -864,6 +880,8 @@ generate_css_style (GtkSourceStyleScheme *scheme)
                append_css_style (final_style, style, ".current-line-number");
        }
 
+       append_cursors_css_style (scheme, final_style);
+
        if (*final_style->str != '\0')
        {
                GError *error = NULL;


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