[gnumeric] css: dead kitten and debug improvements.



commit d95f32cdfb24fad66b2de03215f6b93ff06c3105
Author: Morten Welinder <terra gnome org>
Date:   Fri Feb 19 19:15:17 2021 -0500

    css: dead kitten and debug improvements.

 NEWS                            |  1 +
 configure.ac                    |  2 +-
 src/gnm-pane.c                  | 10 +++++++
 src/gnumeric.css                | 65 ++++++++++++++++++++++++-----------------
 src/gui-util.c                  | 44 +++++++++++++++++++++++-----
 src/gui-util.h                  |  3 ++
 src/item-bar.c                  | 11 +++++--
 src/item-grid.c                 |  5 ++++
 src/sheet-object-cell-comment.c |  2 ++
 9 files changed, 106 insertions(+), 37 deletions(-)
---
diff --git a/NEWS b/NEWS
index c3029d7de..f39f87110 100644
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,7 @@ Morten:
        * Fix ssconvert problem with conditional styles.
        * Move from style regions to style classes in css.
        * Implement #ifdef for built-in css.
+       * Dead kitten in css.
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.48
diff --git a/configure.ac b/configure.ac
index 067471f86..35f627ab3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -555,7 +555,7 @@ CFLAGS="$CFLAGS $GNUMERIC_CFLAGS"
 LIBS="$GNUMERIC_LIBS $LIBS"
 
 AC_CHECK_FUNCS(gtk_cell_renderer_text_get_background_set gtk_cell_renderer_text_get_foreground_set 
gtk_cell_renderer_text_get_editable)
-AC_CHECK_FUNCS(gtk_entry_set_editing_cancelled gtk_icon_theme_add_resource_path)
+AC_CHECK_FUNCS(gtk_entry_set_editing_cancelled gtk_icon_theme_add_resource_path 
gtk_widget_class_set_css_name)
 AC_CHECK_FUNCS(g_ptr_array_insert)
 
 AC_MSG_CHECKING([for OO_NS_LOCALC_EXT])
diff --git a/src/gnm-pane.c b/src/gnm-pane.c
index 8425ef65c..26e432a6e 100644
--- a/src/gnm-pane.c
+++ b/src/gnm-pane.c
@@ -976,6 +976,9 @@ gnm_pane_class_init (GnmPaneClass *klass)
        widget_class->key_release_event    = gnm_pane_key_release;
        widget_class->focus_in_event       = gnm_pane_focus_in;
        widget_class->focus_out_event      = gnm_pane_focus_out;
+#ifdef HAVE_GTK_WIDGET_CLASS_SET_CSS_NAME
+       gtk_widget_class_set_css_name (widget_class, "pane");
+#endif
 
        gtk_widget_class_install_style_property
                (widget_class,
@@ -2107,6 +2110,13 @@ gnm_pane_size_guide_start (GnmPane *pane,
        if (is_colrow_resize)
                gtk_style_context_add_class (context, "end");
        gnm_style_context_get_color (context, GTK_STATE_FLAG_SELECTED, &rgba);
+       if (gnm_debug_flag ("css")) {
+               char *name = g_strconcat ("pane.", guide_class, ".", colrow_class,
+                                         (is_colrow_resize ? ".resize" : ""),
+                                         ".color", NULL);
+               gnm_css_debug_color (name, &rgba);
+               g_free (name);
+       }
        go_color_from_gdk_rgba (&rgba, &style->line.color);
 
        if (is_colrow_resize) {
diff --git a/src/gnumeric.css b/src/gnumeric.css
index be12d703b..4412aac3d 100644
--- a/src/gnumeric.css
+++ b/src/gnumeric.css
@@ -111,21 +111,6 @@ GnmItemBar:hover {
   font-weight: bold;
 }
 
-/* ------------------------------------------------------------------------- */
-/* The resize guide used when resizing columns or rows.  This can be
-   subclassed with "row" or "col" as well as with "start" or "end".  */
-GnmPane GocLine.resize-guide {
-  color: black;
-  /* See also GnmPane */
-}
-
-/* The resize guide used when resizing panes.  This can be subclassed with
-   "row" or "col".  */
-GnmPane GocLine.pane-resize-guide {
-  color: #c0c0c0;
-  /* See also GnmPane */
-}
-
 /* ------------------------------------------------------------------------- */
 /* This GtkDrawingArea is the select-all button above the row buttons.  */
 
@@ -196,17 +181,6 @@ GnmNotebookButton:active {
   font-weight: bold;
 }
 
-/* ------------------------------------------------------------------------- */
-/* Functions' arguments link-like appearance in pseudo-tooltips.  */
-
-GtkTextView.pseudo-tooltip.function-help {
-  -GtkWidget-link-color: #4040ff;
-}
-
-/* Ditto in the function selector.  */
-GtkDialog GtkTextView.function-help {
-  -GtkWidget-link-color: #4040ff;
-}
 
 #if GTK_CHECK_VERSION(3,20,0)
 /* ------------------------------------------------------------------------- */
@@ -224,6 +198,8 @@ button.itembar, button.itembar * {
   font-family: Sans;
   font-style: normal;
   font-variant: normal;
+  /* Could set background-image and background-color here, but it is
+     probably better to stick to the theme.  */
 }
 
 /* The whole column/row selected. */
@@ -256,6 +232,20 @@ dialog.fixed-format-ruler {
   color: red;
 }
 
+/* The resize guide used when resizing columns or rows.  This can be
+   subclassed with "row" or "col" as well as with "start" or "end".  */
+pane GocLine.resize-guide {
+  color: black;
+}
+
+/* The resize guide used when resizing panes.  This can be subclassed with
+   "row" or "col".  */
+pane GocLine.pane-resize-guide {
+  color: #c0c0c0;
+  /* See also GnmPane */
+}
+
+
 /* Auto filter in two versions: the first one for "all", second for others.  */
 /* Not working: */
 arrow.auto-filter {
@@ -290,6 +280,29 @@ GtkArrow.auto-filter:active {
   color: yellow;
 }
 
+/* Functions' arguments link-like appearance in pseudo-tooltips.  */
+GtkTextView.pseudo-tooltip.function-help {
+  -GtkWidget-link-color: #4040ff;
+}
+/* Ditto in the function selector.  */
+GtkDialog GtkTextView.function-help {
+  -GtkWidget-link-color: #4040ff;
+}
+
+/* The resize guide used when resizing columns or rows.  This can be
+   subclassed with "row" or "col" as well as with "start" or "end".  */
+GnmPane GocLine.resize-guide {
+  color: yellow;
+  /* See also GnmPane */
+}
+
+/* The resize guide used when resizing panes.  This can be subclassed with
+   "row" or "col".  */
+GnmPane GocLine.pane-resize-guide {
+  color: #c0c0c0;
+  /* See also GnmPane */
+}
+
 #endif
 
 /* ------------------------------------------------------------------------- */
diff --git a/src/gui-util.c b/src/gui-util.c
index 84c0b19a0..b39805363 100644
--- a/src/gui-util.c
+++ b/src/gui-util.c
@@ -1373,6 +1373,33 @@ gnm_action_group_add_action (GtkActionGroup *group, GtkAction *act)
        gtk_action_group_add_action_with_accel (group, act, NULL);
 }
 
+
+static int gnm_debug_css = -1;
+
+
+void
+gnm_css_debug_color (const char *name,
+                    const GdkRGBA *color)
+{
+       if (gnm_debug_css < 0) gnm_debug_css = gnm_debug_flag ("css");
+
+       if (gnm_debug_css) {
+               char *ctxt = gdk_rgba_to_string (color);
+               g_printerr ("css %s = %s\n", name, ctxt);
+               g_free (ctxt);
+       }
+}
+
+void
+gnm_css_debug_int (const char *name, int i)
+{
+       if (gnm_debug_css < 0) gnm_debug_css = gnm_debug_flag ("css");
+
+       if (gnm_debug_css)
+               g_printerr ("css %s = %d\n", name, i);
+}
+
+
 void
 gnm_style_context_get_color (GtkStyleContext *context,
                             GtkStateFlags state,
@@ -1388,21 +1415,18 @@ gnm_style_context_get_color (GtkStyleContext *context,
        gtk_style_context_restore (context);
 }
 
-#if GTK_CHECK_VERSION(3,12,0)
 void
 gnm_get_link_color (GtkWidget *widget, GdkRGBA *res)
 {
+#if GTK_CHECK_VERSION(3,12,0)
        GtkStyleContext *ctxt = gtk_widget_get_style_context (widget);
        gnm_style_context_get_color (ctxt, GTK_STATE_FLAG_LINK, res);
-}
 #else
-void
-gnm_get_link_color (G_GNUC_UNUSED GtkWidget *widget, GdkRGBA *res)
-{
+       (void)widget;
        gdk_rgba_parse (res, "blue");
-#warning GTK_STATE_FLAG_LINK is undefined, using color blue
+#endif
+       gnm_css_debug_color ("link.color", res);
 }
-#endif /* GTK_STATE_FLAG_LINK */
 
 gboolean
 gnm_theme_is_dark (GtkWidget *widget)
@@ -1410,6 +1434,7 @@ gnm_theme_is_dark (GtkWidget *widget)
        GtkStyleContext *context;
        GdkRGBA fg_color;
        double lum;
+       gboolean dark;
 
        context = gtk_widget_get_style_context (widget);
        gnm_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &fg_color);
@@ -1418,7 +1443,10 @@ gnm_theme_is_dark (GtkWidget *widget)
        lum = 0.299 * fg_color.red + 0.587 * fg_color.green + 0.114 * fg_color.blue;
 
        // Theme is dark if fg is light.
-       return lum > 0.5;
+       dark = lum > 0.5;
+       gnm_css_debug_int ("theme.dark", dark);
+
+       return dark;
 }
 
 
diff --git a/src/gui-util.h b/src/gui-util.h
index 8dd6dd65e..8edd693cb 100644
--- a/src/gui-util.h
+++ b/src/gui-util.h
@@ -189,6 +189,9 @@ void gnm_style_context_get_color (GtkStyleContext *context,
 void gnm_get_link_color (GtkWidget *widget, GdkRGBA *res);
 gboolean gnm_theme_is_dark (GtkWidget *widget);
 
+void gnm_css_debug_color (const char *name, const GdkRGBA *color);
+void gnm_css_debug_int (const char *name, int i);
+
 G_END_DECLS
 
 #endif /* _GNM_GUI_UTIL_H_ */
diff --git a/src/item-bar.c b/src/item-bar.c
index 02d8ed827..239ed3504 100644
--- a/src/item-bar.c
+++ b/src/item-bar.c
@@ -110,6 +110,12 @@ static const char * const selection_styles[3] = {
        "button.itembar:active"
 };
 
+static const char * const selection_style_names[3] = {
+       "itembar.color",
+       "itembar.color.hover",
+       "itembar.color.selected"
+};
+
 static void
 ib_reload_color_style (GnmItemBar *ib)
 {
@@ -119,11 +125,13 @@ ib_reload_color_style (GnmItemBar *ib)
 
        gnm_style_context_get_color (context, GTK_STATE_FLAG_NORMAL,
                                     &ib->grouping_color);
+       gnm_css_debug_color ("item-bar.grouping-color", &ib->grouping_color);
 
        for (ui = 0; ui < G_N_ELEMENTS (selection_type_flags); ui++) {
                GtkStateFlags state = selection_type_flags[ui];
                gnm_style_context_get_color
                        (context, state, &ib->selection_colors[ui]);
+               gnm_css_debug_color (selection_style_names[ui], &ib->selection_colors[ui]);
        }
 }
 
@@ -312,6 +320,7 @@ item_bar_realize (GocItem *item)
                                            ? GDK_SB_H_DOUBLE_ARROW
                                            : GDK_SB_V_DOUBLE_ARROW);
 
+       ib_reload_color_style (ib);
        gnm_item_bar_calc_size (ib);
 }
 
@@ -419,8 +428,6 @@ item_bar_draw_region (GocItem const *item, cairo_t *cr,
        goc_canvas_c2w (item->canvas, x_0, y_0, &x0, &y0);
        goc_canvas_c2w (item->canvas, x_1, y_1, &x1, &y1);
 
-       ib_reload_color_style (ib);
-
        if (ib->is_col_header) {
                int const inc = gnm_item_bar_group_size (ib, sheet->cols.max_outline_level);
                int const base_pos = .2 * inc;
diff --git a/src/item-grid.c b/src/item-grid.c
index ed304b198..a9c8d764e 100644
--- a/src/item-grid.c
+++ b/src/item-grid.c
@@ -108,16 +108,20 @@ ig_reload_style (GnmItemGrid *ig)
        gtk_style_context_add_class (context, "function-marker");
        gnm_style_context_get_color (context, GTK_STATE_FLAG_NORMAL,
                                     &ig->function_marker_color);
+       gnm_css_debug_color ("function-marker.color", &ig->function_marker_color);
        gtk_style_context_get_border_color (context, state,
                                            &ig->function_marker_border_color);
+       gnm_css_debug_color ("function-marker.border-border", &ig->function_marker_border_color);
        gtk_style_context_restore (context);
 
        gtk_style_context_save (context);
        gtk_style_context_add_class (context, "pane-divider");
        gnm_style_context_get_color (context, GTK_STATE_FLAG_NORMAL,
                                     &ig->pane_divider_color);
+       gnm_css_debug_color ("pane-divider.color", &ig->pane_divider_color);
        gtk_style_context_get_border (context, GTK_STATE_FLAG_NORMAL, &border);
        ig->pane_divider_width = border.top;  /* Hack? */
+       gnm_css_debug_int ("pane-divider.border", ig->pane_divider_width);
        gtk_style_context_restore (context);
 
        /* ---------------------------------------- */
@@ -127,6 +131,7 @@ ig_reload_style (GnmItemGrid *ig)
                              "function-indicator-size",
                              &ig->function_marker_size,
                              NULL);
+       gnm_css_debug_int ("function-marker.size", ig->function_marker_size);
 }
 
 static void
diff --git a/src/sheet-object-cell-comment.c b/src/sheet-object-cell-comment.c
index 0bb57fbd1..3961da8cc 100644
--- a/src/sheet-object-cell-comment.c
+++ b/src/sheet-object-cell-comment.c
@@ -71,12 +71,14 @@ comment_view_reload_style (CommentView *cv)
        context = goc_item_get_style_context (item);
        gnm_style_context_get_color (context, GTK_STATE_FLAG_NORMAL,
                                     &cv->comment_indicator_color);
+       gnm_css_debug_color ("comment-indicator.color", &cv->comment_indicator_color);
 
        context = gtk_widget_get_style_context (GTK_WIDGET (pane));
        gtk_widget_style_get (GTK_WIDGET (pane),
                              "comment-indicator-size",
                              &cv->comment_indicator_size,
                              NULL);
+       gnm_css_debug_int ("comment-indicator.size", cv->comment_indicator_size);
 }
 
 static void


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