[gnumeric] GUI: Start styling parts with css.



commit 1dbfbca99e0b05efdbe2c1d55934e558b27a62ef
Author: Morten Welinder <terra gnome org>
Date:   Sun Mar 24 09:57:54 2013 -0400

    GUI: Start styling parts with css.

 src/Makefile.am            |    1 +
 src/gnm-i18n.h             |    3 +
 src/gnm-pane.c             |   10 --
 src/gnumeric.css           |   45 +++++++++
 src/item-bar.c             |  236 +++++++++++++++++++++++---------------------
 src/item-cursor.c          |    2 +-
 src/item-grid.c            |   79 +++++++++++----
 src/pattern.c              |    3 +-
 src/wbc-gtk.c              |   24 +++++
 src/widgets/gnm-notebook.c |   18 ----
 10 files changed, 257 insertions(+), 164 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index bdc5eb6..5555a66 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -416,6 +416,7 @@ gnumeric_app_libs =                         \
        widgets/libwidgets.la
 
 embedded_imgs =                                                \
+       gnumeric.css                                    \
        pixmaps/add_decimals.png                        \
        pixmaps/auto-sum.xpm                            \
        pixmaps/autofilter_16.png                       \
diff --git a/src/gnm-i18n.h b/src/gnm-i18n.h
index 09fc3ec..c584e60 100644
--- a/src/gnm-i18n.h
+++ b/src/gnm-i18n.h
@@ -8,6 +8,9 @@ G_BEGIN_DECLS
 
 #define F_(String) (String)
 
+/* For properties.  */
+#define P_(String) (String)
+
 G_END_DECLS
 
 #endif /* _GNM_I18N_H_ */
diff --git a/src/gnm-pane.c b/src/gnm-pane.c
index 751d7cc..13d0dbc 100644
--- a/src/gnm-pane.c
+++ b/src/gnm-pane.c
@@ -656,19 +656,9 @@ gnm_pane_focus_out (GtkWidget *widget, GdkEventFocus *event)
 static void
 gnm_pane_realize (GtkWidget *w)
 {
-       GtkStyleContext *ctxt;
-       GdkRGBA rgba;
-
        if (GTK_WIDGET_CLASS (parent_klass)->realize)
                (*GTK_WIDGET_CLASS (parent_klass)->realize) (w);
 
-       /* Set the default background color of the canvas itself to white.
-        * This makes the redraws when the canvas scrolls flicker less. */
-       ctxt = gtk_widget_get_style_context (w);
-       gtk_style_context_get_background_color (ctxt, GTK_STATE_FLAG_SELECTED, &rgba);
-       gtk_widget_override_background_color (w, GTK_STATE_FLAG_NORMAL, &gs_white);
-       gtk_widget_override_background_color (w, GTK_STATE_FLAG_SELECTED, &rgba);
-
        gtk_im_context_set_client_window
                (GNM_PANE (w)->im_context,
                 gtk_widget_get_window (gtk_widget_get_toplevel (w)));
diff --git a/src/gnumeric.css b/src/gnumeric.css
new file mode 100644
index 0000000..3b8ab57
--- /dev/null
+++ b/src/gnumeric.css
@@ -0,0 +1,45 @@
+/* ------------------------------------------------------------------------- */
+/* GnmPane is the canvas. */
+/* The ItemGrid is the canvas area that holds all the cells.  */
+GnmPane, ItemGrid {
+  background: white;
+}
+
+/* Function markers are enabled from View->View Properties->Cell Markers */
+ItemGrid function-marker {
+  color: green;
+  border-color: #555555;
+}
+
+/* This is the divider between panes when an area is frozen.  */
+ItemGrid pane-divider {
+  color: #333333;
+
+  /* This isn't working well yet: */
+  border-style: solid;
+  border-width: 1px;
+}
+
+/* ------------------------------------------------------------------------- */
+/* ItemBar canvas items are the header buttons "A".."IV" and "1".."65536" */
+/* These are also styled with class button */
+
+ItemBar {
+  padding-left: 5px;
+  padding-right: 5px;
+  padding-top: 2px;
+  padding-bottom: 2px;
+}
+
+/* ------------------------------------------------------------------------- */
+/* GnmNotebook is a fake notebook holding just the sheet tabs area */
+
+GnmNotebook tab {
+  /* background: #ff0000; */ /* Debug */
+}
+
+GnmNotebook {
+  padding: 0;
+}
+
+/* ------------------------------------------------------------------------- */
diff --git a/src/item-bar.c b/src/item-bar.c
index 390ab81..c738a6e 100644
--- a/src/item-bar.c
+++ b/src/item-bar.c
@@ -53,6 +53,10 @@ struct _ItemBar {
                PangoItem        *item;
                PangoGlyphString *glyphs;
        } pango;
+
+       /* Style: */
+       GdkRGBA selection_colors[3];  /* [ColRowSelectionType] */
+       GtkBorder padding;
 };
 
 typedef GocItemClass ItemBarClass;
@@ -65,8 +69,9 @@ enum {
 };
 
 static int
-ib_compute_pixels_from_indent (Sheet const *sheet, gboolean const is_cols)
+ib_compute_pixels_from_indent (ItemBar *ib, Sheet const *sheet)
 {
+       gboolean is_cols = ib->is_col_header;
        double const scale =
                sheet->last_zoom_factor_used *
                gnm_app_display_dpi_get (is_cols) / 72.;
@@ -75,21 +80,44 @@ ib_compute_pixels_from_indent (Sheet const *sheet, gboolean const is_cols)
                : sheet->rows.max_outline_level;
        if (!sheet->display_outlines || indent <= 0)
                return 0;
-       return (int)(5 + (indent + 1) * 14 * scale + 0.5);
+       return (int)(ib->padding.left + (indent + 1) * 14 * scale + 0.5);
 }
 
 static void
-ib_fonts_unref (ItemBar *ib)
+ib_dispose_fonts (ItemBar *ib)
 {
-       if (ib->normal_font != NULL) {
-               g_object_unref (ib->normal_font);
-               ib->normal_font = NULL;
-       }
+       g_clear_object (&ib->normal_font);
+       g_clear_object (&ib->bold_font);
+}
 
-       if (ib->bold_font != NULL) {
-               g_object_unref (ib->bold_font);
-               ib->bold_font = NULL;
-       }
+static const gboolean selection_type_bold[3] = {
+       FALSE, TRUE, TRUE
+};
+static const GtkStateFlags selection_type_flags[3] = {
+       GTK_STATE_FLAG_NORMAL,
+       GTK_STATE_FLAG_PRELIGHT,
+       GTK_STATE_FLAG_ACTIVE
+};
+
+
+static void
+ib_reload_style (ItemBar *ib)
+{
+       GocItem *item = GOC_ITEM (ib);
+       GtkStyleContext *context = goc_item_get_style_context (item);
+
+       gtk_style_context_get_color
+               (context, selection_type_flags[COL_ROW_NO_SELECTION],
+                &ib->selection_colors[COL_ROW_NO_SELECTION]);
+       gtk_style_context_get_color
+               (context, selection_type_flags[COL_ROW_PARTIAL_SELECTION],
+                &ib->selection_colors[COL_ROW_PARTIAL_SELECTION]);
+       gtk_style_context_get_color
+               (context, selection_type_flags[COL_ROW_FULL_SELECTION],
+                &ib->selection_colors[COL_ROW_FULL_SELECTION]);
+
+       gtk_style_context_get_padding (context, GTK_STATE_NORMAL,
+                                      &ib->padding);
 }
 
 /**
@@ -116,7 +144,8 @@ item_bar_calc_size (ItemBar *ib)
        GList *item_list;
        PangoAttrList *attr_list;
 
-       ib_fonts_unref (ib);
+       ib_dispose_fonts (ib);
+       ib_reload_style (ib);
 
        context = gtk_widget_get_pango_context (GTK_WIDGET (ib->pane));
        desc = pango_font_description_copy (src_desc);
@@ -137,22 +166,25 @@ item_bar_calc_size (ItemBar *ib)
 
        /*
         * Use the size of the bold header font to size the free dimensions.
-        * Add 2 pixels above and below.
         */
        pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD);
        ib->bold_font = pango_context_load_font (context, desc);
        pango_layout_set_font_description (layout, desc);
        pango_layout_get_extents (layout, &ink_rect, &logical_rect);
-       ib->cell_height = 2 + 2 + PANGO_PIXELS (logical_rect.height);
+       ib->cell_height = PANGO_PIXELS (logical_rect.height) +
+               (ib->padding.top + ib->padding.bottom);
        ib->bold_font_ascent = PANGO_PIXELS (ink_rect.height + ink_rect.y);
 
-       /* 5 pixels left and right plus the width of the widest string I can think of */
+       /* The width of the widest string I can think of + padding */
        if (char_label)
-               pango_layout_set_text (layout, "WWWWWWWWWW", strlen (col_name (gnm_sheet_get_last_col 
(sheet))));
+               pango_layout_set_text (layout, "WWWWWWWWWW",
+                                      strlen (col_name (gnm_sheet_get_last_col (sheet))));
        else
-               pango_layout_set_text (layout, "8888888888", strlen (row_name (gnm_sheet_get_last_row 
(sheet))));
+               pango_layout_set_text (layout, "8888888888",
+                                      strlen (row_name (gnm_sheet_get_last_row (sheet))));
        pango_layout_get_extents (layout, NULL, &logical_rect);
-       ib->cell_width = 5 + 5 + PANGO_PIXELS (logical_rect.width);
+       ib->cell_width = PANGO_PIXELS (logical_rect.width) +
+               (ib->padding.left + ib->padding.right);
 
        attr_list = pango_attr_list_new ();
        pango_attr_list_insert (attr_list, pango_attr_font_desc_new (desc));
@@ -160,16 +192,16 @@ item_bar_calc_size (ItemBar *ib)
        pango_attr_list_unref (attr_list);
 
        if (ib->pango.item)
-         pango_item_free (ib->pango.item);
+               pango_item_free (ib->pango.item);
        ib->pango.item = item_list->data;
        item_list->data = NULL;
 
        if (item_list->next != NULL)
-         g_warning ("Leaking pango items");
+               g_warning ("Leaking pango items");
 
        g_list_free (item_list);
 
-       size = ib_compute_pixels_from_indent (sheet, ib->is_col_header);
+       size = ib_compute_pixels_from_indent (ib, sheet);
        if (size != ib->indent) {
                ib->indent = size;
                goc_item_bounds_changed (GOC_ITEM (ib));
@@ -218,20 +250,20 @@ item_bar_update_bounds (GocItem *item)
 static void
 item_bar_realize (GocItem *item)
 {
-       ItemBar *ib;
+       ItemBar *ib = ITEM_BAR (item);
        GdkDisplay *display;
 
-       if (parent_class->realize)
-               (*parent_class->realize)(item);
-
-       ib = ITEM_BAR (item);
+       parent_class->realize (item);
 
        display = gtk_widget_get_display (GTK_WIDGET (item->canvas));
-       ib->normal_cursor = gdk_cursor_new_for_display (display, GDK_LEFT_PTR);
-       if (ib->is_col_header)
-               ib->change_cursor = gdk_cursor_new_for_display (display, GDK_SB_H_DOUBLE_ARROW);
-       else
-               ib->change_cursor = gdk_cursor_new_for_display (display, GDK_SB_V_DOUBLE_ARROW);
+       ib->normal_cursor =
+               gdk_cursor_new_for_display (display, GDK_LEFT_PTR);
+       ib->change_cursor =
+               gdk_cursor_new_for_display (display, 
+                                           ib->is_col_header
+                                           ? GDK_SB_H_DOUBLE_ARROW
+                                           : GDK_SB_V_DOUBLE_ARROW);
+
        item_bar_calc_size (ib);
 }
 
@@ -240,8 +272,8 @@ item_bar_unrealize (GocItem *item)
 {
        ItemBar *ib = ITEM_BAR (item);
 
-       g_object_unref (ib->change_cursor);
-       g_object_unref (ib->normal_cursor);
+       g_clear_object (&ib->change_cursor);
+       g_clear_object (&ib->normal_cursor);
 
        parent_class->unrealize (item);
 }
@@ -251,89 +283,74 @@ ib_draw_cell (ItemBar const * const ib, cairo_t *cr,
              ColRowSelectionType const type,
              char const * const str, GocRect *rect)
 {
-       GtkLayout *canvas = GTK_LAYOUT (ib->base.canvas);
-       GtkWidget *widget = GTK_WIDGET (canvas);
-       GtkStyleContext *ctxt = gtk_widget_get_style_context (widget);
-       PangoFont *font;
-       PangoRectangle size;
-       GdkRGBA color, font_color;
-       int ascent;
-
-       /* add "button" to the context path */
-       gtk_style_context_save (ctxt);
-       gtk_style_context_add_class (ctxt, GTK_STYLE_CLASS_BUTTON);
-       switch (type) {
-       default:
-       case COL_ROW_NO_SELECTION:
-               font   = ib->normal_font;
-               gtk_style_context_set_state (ctxt, GTK_STATE_FLAG_NORMAL);
-               gtk_style_context_get_background_color (ctxt, GTK_STATE_FLAG_NORMAL, &color);
-               gtk_style_context_get_color (ctxt, GTK_STATE_FLAG_NORMAL,
-                                            &font_color);
-               ascent = ib->normal_font_ascent;
-               break;
+       GtkStyleContext *ctxt = goc_item_get_style_context (GOC_ITEM (ib));
 
-       case COL_ROW_PARTIAL_SELECTION:
-               font   = ib->bold_font;
-               gtk_style_context_set_state (ctxt, GTK_STATE_FLAG_PRELIGHT);
-               gtk_style_context_get_background_color (ctxt, GTK_STATE_FLAG_PRELIGHT, &color);
-               gtk_style_context_get_color (ctxt, GTK_STATE_FLAG_PRELIGHT,
-                                            &font_color);
-               ascent = ib->bold_font_ascent;
-               break;
+       g_return_if_fail ((size_t)type < G_N_ELEMENTS (selection_type_bold));
 
-       case COL_ROW_FULL_SELECTION:
-               font   = ib->bold_font;
-               gtk_style_context_set_state (ctxt, GTK_STATE_FLAG_ACTIVE);
-               gtk_style_context_get_background_color (ctxt, GTK_STATE_FLAG_ACTIVE, &color);
-               gtk_style_context_get_color (ctxt, GTK_STATE_FLAG_ACTIVE,
-                                            &font_color);
-               ascent = ib->bold_font_ascent;
-               break;
-       }
-       /* When we are really small leave out the shadow and the text */
        cairo_save (cr);
-       gdk_cairo_set_source_rgba (cr, &color);
-       if (rect->width <= 2 || rect->height <= 2) {
-               cairo_rectangle (cr, rect->x, rect->y, rect->width, rect->height);
-               cairo_fill (cr);
-               cairo_restore (cr);
-               /* restore style context */
-               gtk_style_context_restore (ctxt);
-               return;
-       }
 
-       gtk_render_background (ctxt, cr, rect->x, rect->y, rect->width + 1, rect->height + 1);
-       gtk_render_frame (ctxt, cr, rect->x, rect->y, rect->width + 1, rect->height + 1);
-       cairo_rectangle (cr, rect->x + 1, rect->y + 1, rect->width - 2, rect->height - 2);
-       cairo_restore (cr);
+       /* Style-wise we are a button in the given state.  */
+       gtk_style_context_save (ctxt);
+       gtk_style_context_add_class (ctxt, GTK_STYLE_CLASS_BUTTON);
+       gtk_style_context_set_state (ctxt, selection_type_flags[type]);
+       gtk_render_background (ctxt, cr, rect->x, rect->y,
+                              rect->width + 1, rect->height + 1);
 
-       g_return_if_fail (font != NULL);
-       g_object_unref (ib->pango.item->analysis.font);
-       ib->pango.item->analysis.font = g_object_ref (font);
-       pango_shape (str, strlen (str), &(ib->pango.item->analysis), ib->pango.glyphs);
-       pango_glyph_string_extents (ib->pango.glyphs, font, NULL, &size);
+       /* When we are really small leave out the shadow and the text */
+       if (rect->width >= 2 && rect->height >= 2) {
+               PangoRectangle size;
+               PangoFont *font;
+               int ascent;
+               int w, h;
+
+               if (selection_type_bold[type]) {
+                       font = ib->bold_font;
+                       ascent = ib->bold_font_ascent;
+               } else {
+                       font = ib->normal_font;
+                       ascent = ib->normal_font_ascent;
+               }
 
-       cairo_save (cr);
-       cairo_clip (cr);
-       gdk_cairo_set_source_rgba (cr, &font_color);
-       cairo_translate (cr,
-                                        rect->x + (rect->width - PANGO_PIXELS (size.width)) / 2,
-                                        rect->y + (rect->height - PANGO_PIXELS (size.height)) / 2 + ascent);
-       pango_cairo_show_glyph_string (cr, font, ib->pango.glyphs);
-       cairo_restore (cr);
-       /* restore style context */
+               g_return_if_fail (font != NULL);
+               g_object_unref (ib->pango.item->analysis.font);
+               ib->pango.item->analysis.font = g_object_ref (font);
+               pango_shape (str, strlen (str),
+                            &(ib->pango.item->analysis), ib->pango.glyphs);
+               pango_glyph_string_extents (ib->pango.glyphs, font,
+                                           NULL, &size);
+
+               gtk_render_frame (ctxt, cr, rect->x, rect->y,
+                                 rect->width + 1, rect->height + 1);
+               w = rect->width - (ib->padding.left + ib->padding.right);
+               h = rect->height - (ib->padding.top + ib->padding.bottom);
+               cairo_rectangle (cr, rect->x + 1, rect->y + 1,
+                                rect->width - 2, rect->height - 2);
+               cairo_clip (cr);
+
+               gdk_cairo_set_source_rgba (cr, &ib->selection_colors[type]);
+
+               cairo_translate (cr,
+                                rect->x + ib->padding.left +
+                                (w - PANGO_PIXELS (size.width)) / 2,
+                                rect->y + ib->padding.top + ascent +
+                                (h - PANGO_PIXELS (size.height)) / 2);
+               pango_cairo_show_glyph_string (cr, font, ib->pango.glyphs);
+       }
        gtk_style_context_restore (ctxt);
+       cairo_restore (cr);
 }
 
 int
 item_bar_group_size (ItemBar const *ib, int max_outline)
 {
-       return (max_outline > 0) ? (ib->indent - 2) / (max_outline + 1) : 0;
+       return max_outline > 0
+               ? (ib->indent - 2) / (max_outline + 1)
+               : 0;
 }
 
 static gboolean
-item_bar_draw_region (GocItem const *item, cairo_t *cr, double x_0, double y_0, double x_1, double y_1)
+item_bar_draw_region (GocItem const *item, cairo_t *cr,
+                     double x_0, double y_0, double x_1, double y_1)
 {
        double scale = item->canvas->pixels_per_unit;
        int x0, x1, y0, y1;
@@ -342,7 +359,6 @@ item_bar_draw_region (GocItem const *item, cairo_t *cr, double x_0, double y_0,
        SheetControlGUI const *scg    = pane->simple.scg;
        Sheet const           *sheet  = scg_sheet (scg);
        SheetView const       *sv     = scg_view (scg);
-       GtkWidget *canvas = GTK_WIDGET (item->canvas);
        ColRowInfo const *cri, *next = NULL;
        int pixels;
        gboolean prev_visible;
@@ -355,14 +371,12 @@ item_bar_draw_region (GocItem const *item, cairo_t *cr, double x_0, double y_0,
        gboolean const rtl = sheet->text_is_rtl != FALSE;
        int shadow;
        int first_line_offset = 1;
-       GdkRGBA rgba;
-       GtkStyleContext *ctxt = gtk_widget_get_style_context (canvas);
-       GOColor color;
+       GdkRGBA color;
+       GtkStyleContext *ctxt = goc_item_get_style_context (item);
 
        gtk_style_context_save (ctxt);
        gtk_style_context_add_class (ctxt, GTK_STYLE_CLASS_BUTTON);
-       gtk_style_context_get_color (ctxt, GTK_STATE_FLAG_NORMAL, &rgba);
-       color = GO_COLOR_FROM_GDK_RGBA (rgba);
+       gtk_style_context_get_color (ctxt, GTK_STATE_FLAG_NORMAL, &color);
        goc_canvas_c2w (item->canvas, x_0, y_0, &x0, &y0);
        goc_canvas_c2w (item->canvas, x_1, y_1, &x1, &y1);
 
@@ -431,7 +445,7 @@ item_bar_draw_region (GocItem const *item, cairo_t *cr, double x_0, double y_0,
                                        cairo_set_line_width (cr, 2.0);
                                        cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
                                        cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
-                                       cairo_set_source_rgba (cr, GO_COLOR_TO_CAIRO (color));
+                                       gdk_cairo_set_source_rgba (cr, &color);
                                        if (!draw_right) {
                                                next = sheet_col_get_info (sheet, col + 1);
                                                prev_level = next->outline_level;
@@ -590,7 +604,7 @@ item_bar_draw_region (GocItem const *item, cairo_t *cr, double x_0, double y_0,
                                        cairo_set_line_width (cr, 2.0);
                                        cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
                                        cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
-                                       cairo_set_source_rgba (cr, GO_COLOR_TO_CAIRO (color));
+                                       gdk_cairo_set_source_rgba (cr, &color);
                                        if (!draw_below) {
                                                next = sheet_row_get_info (sheet, row + 1);
                                                points[0].y = top;
@@ -700,7 +714,7 @@ item_bar_draw_region (GocItem const *item, cairo_t *cr, double x_0, double y_0,
 
 static double
 item_bar_distance (GocItem *item, double x, double y,
-               GocItem **actual_item)
+                  GocItem **actual_item)
 {
        *actual_item = item;
        return 0.0;
@@ -1095,7 +1109,7 @@ item_bar_dispose (GObject *obj)
 {
        ItemBar *ib = ITEM_BAR (obj);
 
-       ib_fonts_unref (ib);
+       ib_dispose_fonts (ib);
 
        if (ib->tip) {
                gtk_widget_destroy (ib->tip);
diff --git a/src/item-cursor.c b/src/item-cursor.c
index 36216da..92f0696 100644
--- a/src/item-cursor.c
+++ b/src/item-cursor.c
@@ -489,7 +489,7 @@ item_cursor_reposition (ItemCursor *ic)
 
 static double
 item_cursor_distance (GocItem *item, double x, double y,
-                  GocItem **actual_item)
+                     GocItem **actual_item)
 {
        ItemCursor const *ic = ITEM_CURSOR (item);
 
diff --git a/src/item-grid.c b/src/item-grid.c
index f18203b..3feb77e 100644
--- a/src/item-grid.c
+++ b/src/item-grid.c
@@ -39,6 +39,7 @@
 #include "commands.h"
 #include "hlink.h"
 #include "gui-util.h"
+#include "gnm-i18n.h"
 
 #include <goffice/goffice.h>
 #include <gtk/gtk.h>
@@ -71,13 +72,21 @@ struct _ItemGrid {
        /* information for the cursor motion handler */
        guint cursor_timer;
        gint64 last_x, last_y;
-       GnmHLink *cur_link; /* do not derference, just a pointer */
+       GnmHLink *cur_link; /* do not dereference, just a pointer */
        GtkWidget *tip;
        guint tip_timer;
 
        GdkCursor *cursor_link, *cursor_cross;
 
        guint32 last_click_time;
+
+       /* Style: */
+       GdkRGBA function_marker_color;
+       GdkRGBA function_marker_border_color;
+
+       GdkRGBA pane_divider_color;
+       int pane_divider_width;
+
 };
 typedef GocItemClass ItemGridClass;
 static GocItemClass *parent_class;
@@ -89,6 +98,30 @@ enum {
 };
 
 static void
+ig_reload_style (ItemGrid *ig)
+{
+       GocItem *item = GOC_ITEM (ig);
+       GtkStyleContext *context = goc_item_get_style_context (item);
+       GtkBorder border;
+
+       gtk_style_context_save (context);
+       gtk_style_context_add_region (context, "function-marker", 0);
+       gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL,
+                                    &ig->function_marker_color);
+       gtk_style_context_get_border_color (context, GTK_STATE_FLAG_NORMAL,
+                                           &ig->function_marker_border_color);
+       gtk_style_context_restore (context);
+
+       gtk_style_context_save (context);
+       gtk_style_context_add_region (context, "pane-divider", 0);
+       gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL,
+                                    &ig->pane_divider_color);
+       gtk_style_context_get_border (context, GTK_STATE_FLAG_NORMAL, &border);
+       ig->pane_divider_width = border.top;  /* Hack? */
+       gtk_style_context_restore (context);
+}
+
+static void
 ig_clear_hlink_tip (ItemGrid *ig)
 {
        if (ig->tip_timer != 0) {
@@ -160,6 +193,7 @@ item_grid_realize (GocItem *item)
                parent_class->realize (item);
 
        ig = ITEM_GRID (item);
+       ig_reload_style (ig);
 
        display = gtk_widget_get_display (GTK_WIDGET (item->canvas));
        ig->cursor_link  = gdk_cursor_new_for_display (display, GDK_HAND2);
@@ -198,7 +232,8 @@ item_grid_update_bounds (GocItem *item)
 }
 
 static void
-draw_function_marker (GnmCell const *cell, cairo_t *cr,
+draw_function_marker (ItemGrid *ig,
+                     GnmCell const *cell, cairo_t *cr,
                      double x, double y, double w, double h, int const dir)
 {
        if (cell == NULL || !gnm_cell_has_expr (cell))
@@ -219,9 +254,9 @@ draw_function_marker (GnmCell const *cell, cairo_t *cr,
                cairo_arc (cr, x + w, y, 10., M_PI/2., M_PI);
        }
        cairo_close_path (cr);
-       cairo_set_source_rgb(cr, 0.0, 1.0, 0.0);
+       gdk_cairo_set_source_rgba (cr, &ig->function_marker_color);
        cairo_fill_preserve (cr);
-       cairo_set_source_rgb(cr, 0.3, 0.3, 0.3);
+       gdk_cairo_set_source_rgba (cr, &ig->function_marker_border_color);
        cairo_set_line_width (cr, 0.5);
        cairo_stroke (cr);
        cairo_restore (cr);
@@ -311,14 +346,14 @@ item_grid_draw_merged_range (cairo_t *cr, ItemGrid *ig,
 
                if (dir > 0) {
                        if (show_function_cell_markers)
-                               draw_function_marker (cell, cr, l, t,
+                               draw_function_marker (ig, cell, cr, l, t,
                                                      r - l, b - t, dir);
                        cell_draw (cell, cr,
                                   l, t, r - l, b - t, -1,
                                   show_extension_markers);
                } else {
                        if (show_function_cell_markers)
-                               draw_function_marker (cell, cr, r, t,
+                               draw_function_marker (ig, cell, cr, r, t,
                                                      l - r, b - t, dir);
                        cell_draw (cell, cr,
                                   r, t, l - r, b - t, -1,
@@ -366,20 +401,22 @@ merged_col_cmp (GnmRange const *a, GnmRange const *b)
 }
 
 static void
-ig_cairo_draw_bound (cairo_t* cr, int x0, int y0, int x1, int y1)
+ig_cairo_draw_bound (ItemGrid *ig, cairo_t* cr, int x0, int y0, int x1, int y1)
 {
-       cairo_set_line_width (cr, 1.);
+       double width = ig->pane_divider_width;
+       cairo_set_line_width (cr, width);
        cairo_set_dash (cr, NULL, 0, 0.);
        cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
        cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
-       cairo_set_source_rgba (cr, 0.2, 0.2, 0.2, 1.);
-       cairo_move_to (cr, x0 - .5, y0 - .5);
-       cairo_line_to (cr, x1 - .5, y1 - .5);
+       gdk_cairo_set_source_rgba (cr, &ig->pane_divider_color);
+       cairo_move_to (cr, x0 - width / 2, y0 - width / 2);
+       cairo_line_to (cr, x1 - width / 2, y1 - width / 2);
        cairo_stroke (cr);
 }
 
 static gboolean
-item_grid_draw_region (GocItem const *item, cairo_t *cr, double x_0, double y_0, double x_1, double y_1)
+item_grid_draw_region (GocItem const *item, cairo_t *cr,
+                      double x_0, double y_0, double x_1, double y_1)
 {
        GocCanvas *canvas = item->canvas;
        double scale = canvas->pixels_per_unit;
@@ -477,10 +514,8 @@ item_grid_draw_region (GocItem const *item, cairo_t *cr, double x_0, double y_0,
 
        /* Fill entire region with default background (even past far edge) */
        cairo_save (cr);
-       /* FIXME: we previously used gs_white */
-       cairo_set_source_rgba (cr, GO_COLOR_TO_CAIRO (GO_COLOR_WHITE));
-       cairo_rectangle (cr, x0, y0, width, height);
-       cairo_fill (cr);
+       gtk_render_background (goc_item_get_style_context (item),
+                              cr, x0, y0, width, height);
        cairo_restore (cr);
 
        /* Get ordered list of merged regions */
@@ -670,7 +705,7 @@ plain_draw : /* a quick hack to deal with 142267 */
                        item_grid_draw_background (cr, ig,
                                style, col, row, x, y,
                                ci->size_pixels, ri->size_pixels,
-                                                  draw_selection, ctxt);
+                               draw_selection, ctxt);
 
 
                        /* Is this part of a span?
@@ -689,7 +724,7 @@ plain_draw : /* a quick hack to deal with 142267 */
                                GnmCell const *cell = sheet_cell_get (sheet, col, row);
                                if (!gnm_cell_is_empty (cell) && cell != edit_cell) {
                                        if (show_function_cell_markers)
-                                               draw_function_marker (cell, cr, x, y,
+                                               draw_function_marker (ig, cell, cr, x, y,
                                                                      ci->size_pixels,
                                                                      ri->size_pixels,
                                                                      dir);
@@ -747,7 +782,7 @@ plain_draw : /* a quick hack to deal with 142267 */
                                }
 
                                if (show_function_cell_markers)
-                                       draw_function_marker (cell, cr, real_x, y,
+                                       draw_function_marker (ig, cell, cr, real_x, y,
                                                              tmp_width,
                                                              ri->size_pixels, dir);
                                cell_draw (cell, cr,
@@ -792,13 +827,13 @@ plain_draw : /* a quick hack to deal with 142267 */
        }
 
        if (ig->bound.start.row > 0 && start_y < 1)
-               ig_cairo_draw_bound (cr, start_x, 1, x, 1);
+               ig_cairo_draw_bound (ig, cr, start_x, 1, x, 1);
        if (ig->bound.start.col > 0) {
                if (canvas->direction == GOC_DIRECTION_RTL && start_x >= goc_canvas_get_width (canvas)) {
                        x = goc_canvas_get_width (canvas);
-                       ig_cairo_draw_bound (cr, x, start_y, x, y);
+                       ig_cairo_draw_bound (ig, cr, x, start_y, x, y);
                } else if (canvas->direction == GOC_DIRECTION_LTR && start_x < 1)
-                       ig_cairo_draw_bound (cr, 1, start_y, 1, y);
+                       ig_cairo_draw_bound (ig, cr, 1, start_y, 1, y);
        }
 
        gtk_widget_destroy (entry);
diff --git a/src/pattern.c b/src/pattern.c
index 50946cc..6101637 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -89,8 +89,7 @@ gnumeric_background_set (GnmStyle const *mstyle, cairo_t *cr,
                return TRUE;
        } else if (is_selected) {
                if (ctxt == NULL)
-                       cairo_set_source_rgb
-                               (cr, gs_lavender.red, gs_lavender.green, gs_lavender.blue);
+                       gdk_cairo_set_source_rgba (cr, &gs_lavender);
                else {
                        GdkRGBA rgba;
                        gtk_style_context_get_background_color (ctxt, GTK_STATE_FLAG_SELECTED, &rgba);
diff --git a/src/wbc-gtk.c b/src/wbc-gtk.c
index 2cadd76..f984e8e 100644
--- a/src/wbc-gtk.c
+++ b/src/wbc-gtk.c
@@ -2300,6 +2300,27 @@ cb_realize (GtkWindow *toplevel, WBCGtk *wbcg)
        }
 }
 
+static void
+cb_screen_changed (GtkWidget *widget)
+{
+       GdkScreen *screen = gtk_widget_get_screen (widget);
+       const char *key = "wbcg-screen-css";
+
+       if (screen && !g_object_get_data (G_OBJECT (screen), key)) {
+               GtkCssProvider *css = gtk_css_provider_new ();
+               const char *csstext = go_rsm_lookup ("gnm:gnumeric.css", NULL);
+
+               gtk_css_provider_load_from_data (css, csstext, -1, NULL);
+               gtk_style_context_add_provider_for_screen
+                       (screen,
+                        GTK_STYLE_PROVIDER (css),
+                        GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+               g_object_unref (css);
+
+               g_object_set_data (G_OBJECT (screen), key, css);
+       }
+}
+
 void
 wbcg_set_status_text (WBCGtk *wbcg, char const *text)
 {
@@ -4919,6 +4940,9 @@ wbcg_set_toplevel (WBCGtk *wbcg, GtkWidget *w)
                G_CALLBACK (cb_scroll_wheel), wbcg);
        g_signal_connect (w, "realize",
                G_CALLBACK (cb_realize), wbcg);
+       g_signal_connect (w, "screen-changed",
+               G_CALLBACK (cb_screen_changed), NULL);
+       cb_screen_changed (w);
 
        /* Setup a test of Drag and Drop */
        gtk_drag_dest_set (GTK_WIDGET (w),
diff --git a/src/widgets/gnm-notebook.c b/src/widgets/gnm-notebook.c
index 982cf71..485bac6 100644
--- a/src/widgets/gnm-notebook.c
+++ b/src/widgets/gnm-notebook.c
@@ -78,25 +78,7 @@ gnm_notebook_class_init (GtkWidgetClass *klass)
 static void
 gnm_notebook_init (GnmNotebook *notebook)
 {
-       GtkCssProvider *css;
-       GtkStyleContext *context;
-
        gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
-
-       context = gtk_widget_get_style_context (GTK_WIDGET (notebook));
-       css = gtk_css_provider_new ();
-       gtk_css_provider_load_from_data (css,
-                                        "GnmNotebook {\n"
-                                        "  padding: 0;\n"
-                                        "/*  background-color: #dd0000; */\n"
-                                        "}\n"
-                                        "GnmNotebook tab {\n"
-                                        "}",
-                                        -1, NULL);
-       gtk_style_context_add_provider (context,
-                                       GTK_STYLE_PROVIDER (css),
-                                       GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
-       g_object_unref (css);
 }
 
 GSF_CLASS (GnmNotebook, gnm_notebook,


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