[gnumeric] Patterns: simplify code by insisting on a style context.



commit 9e042a6b522e47990ca20eac14e76bec941ca041
Author: Morten Welinder <terra gnome org>
Date:   Tue Mar 26 14:17:07 2013 -0400

    Patterns: simplify code by insisting on a style context.

 ChangeLog          |    7 +++++++
 src/item-edit.c    |    5 +++--
 src/item-grid.c    |    7 +++----
 src/pattern.c      |   36 +++++++++++++-----------------------
 src/preview-grid.c |    3 ++-
 5 files changed, 28 insertions(+), 30 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 48de2be..fe7bc3d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2013-03-26  Morten Welinder  <terra gnome org>
 
+       * src/pattern.c (gnumeric_background_set): Insist that ctxt is
+       non-NULL.
+
+       * src/preview-grid.c (preview_grid_draw_background): Always
+       provide a context to gnumeric_background_set.
+       * src/item-edit.c (item_edit_draw): Ditto.
+
        * src/item-cursor.c (ic_reload_style): Use class, not state, to
        separate the different cursor types.  Separate autofill colouring
        from drag ditto.
diff --git a/src/item-edit.c b/src/item-edit.c
index b15d4eb..c644002 100644
--- a/src/item-edit.c
+++ b/src/item-edit.c
@@ -116,7 +116,8 @@ gnm_apply_attribute_list (PangoAttrList *attrs, PangoAttrList *added_attrs)
 static void
 item_edit_draw (GocItem const *item, cairo_t *cr)
 {
-       GnmItemEdit  const *ie  = GNM_ITEM_EDIT (item);
+       GnmItemEdit const *ie = GNM_ITEM_EDIT (item);
+       GtkStyleContext *context = goc_item_get_style_context (item);
        int top, left;
        GOColor color;
        int x0, y0, x1, y1; /* in widget coordinates */
@@ -150,7 +151,7 @@ item_edit_draw (GocItem const *item, cairo_t *cr)
        /* avoid a weak/strong cursor to extent outside the item,
         a better fix would be to have enough room for cursors */
        cairo_clip_preserve (cr);
-       if (!gnumeric_background_set (ie->style, cr, FALSE, NULL))
+       if (!gnumeric_background_set (ie->style, cr, FALSE, context))
                cairo_set_source_rgba (cr, 1., 1., 0.878431373, 1.);
        cairo_fill (cr);
 
diff --git a/src/item-grid.c b/src/item-grid.c
index 8a8fe39..d6c8b4e 100644
--- a/src/item-grid.c
+++ b/src/item-grid.c
@@ -314,8 +314,8 @@ item_grid_draw_merged_range (cairo_t *cr, GnmItemGrid *ig,
        }
 
        /* Check for background THEN selection */
-       if (gnumeric_background_set (style, cr,
-                                    is_selected, ctxt) || is_selected) {
+       if (gnumeric_background_set (style, cr, is_selected, ctxt) ||
+           is_selected) {
                /* Remember X excludes the far pixels */
                if (dir > 0)
                        cairo_rectangle (cr, l, t, r-l+1, b-t+1);
@@ -378,8 +378,7 @@ item_grid_draw_background (cairo_t *cr, GnmItemGrid *ig,
                (sv->edit_pos.col != col || sv->edit_pos.row != row) &&
                sv_is_pos_selected (sv, col, row);
        gboolean const has_back =
-               gnumeric_background_set (style, cr,
-                                        is_selected, ctxt);
+               gnumeric_background_set (style, cr, is_selected, ctxt);
 
 #if DEBUG_SELECTION_PAINT
        if (is_selected) {
diff --git a/src/pattern.c b/src/pattern.c
index 6101637..fba7cfe 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -48,18 +48,14 @@ static GOPatternType patterns[] = {
  * return : TRUE if there is a background to paint.
  */
 
-static double
-gnm_get_light (double c)
-{
-       return ((1 + c)/2);
-}
-
 gboolean
 gnumeric_background_set (GnmStyle const *mstyle, cairo_t *cr,
                         gboolean const is_selected, GtkStyleContext *ctxt)
 {
        int pattern;
 
+       g_return_val_if_fail (ctxt != NULL, FALSE);
+
        /*
         * Draw the background if the PATTERN is non 0
         * Draw a stipple too if the pattern is > 1
@@ -74,12 +70,9 @@ gnumeric_background_set (GnmStyle const *mstyle, cairo_t *cr,
                if (is_selected) {
                        GOColor light;
                        GdkRGBA rgba;
-                       if (ctxt) {
-                               gtk_style_context_get_background_color (ctxt,
-                                               GTK_STATE_FLAG_SELECTED, &rgba);
-                               light = GO_COLOR_FROM_GDK_RGBA (rgba);
-                       } else
-                               light = GO_COLOR_FROM_RGB (230, 230, 250);
+                       gtk_style_context_get_background_color
+                               (ctxt, GTK_STATE_FLAG_SELECTED, &rgba);
+                       light = GO_COLOR_FROM_GDK_RGBA (rgba);
                        gopat.fore = GO_COLOR_INTERPOLATE (light, gopat.fore, .5);
                        gopat.back = GO_COLOR_INTERPOLATE (light, gopat.back, .5);
                }
@@ -88,17 +81,14 @@ gnumeric_background_set (GnmStyle const *mstyle, cairo_t *cr,
                cairo_pattern_destroy (crpat);
                return TRUE;
        } else if (is_selected) {
-               if (ctxt == NULL)
-                       gdk_cairo_set_source_rgba (cr, &gs_lavender);
-               else {
-                       GdkRGBA rgba;
-                       gtk_style_context_get_background_color (ctxt, GTK_STATE_FLAG_SELECTED, &rgba);
-                       cairo_set_source_rgba
-                               (cr, gnm_get_light (rgba.red),
-                                gnm_get_light (rgba.green),
-                                gnm_get_light (rgba.blue),
-                                gnm_get_light (rgba.alpha));
-               }
+               GdkRGBA rgba;
+               GOColor color;
+
+               gtk_style_context_get_background_color (ctxt, GTK_STATE_FLAG_SELECTED, &rgba);
+               color = GO_COLOR_FROM_GDK_RGBA (rgba);
+               /* Make a lighter version. */
+               color = GO_COLOR_INTERPOLATE (GO_COLOR_WHITE, color, .5);
+               cairo_set_source_rgba (cr, GO_COLOR_TO_CAIRO (color));
        }
        return FALSE;
 }
diff --git a/src/preview-grid.c b/src/preview-grid.c
index c206b46..2d8edf3 100644
--- a/src/preview-grid.c
+++ b/src/preview-grid.c
@@ -174,7 +174,8 @@ static void
 preview_grid_draw_background (cairo_t *cr, GnmPreviewGrid const *pg, GnmStyle const *mstyle,
                              int col, int row, int x, int y, int w, int h)
 {
-       if (gnumeric_background_set (mstyle, cr, FALSE, NULL)) {
+       GtkStyleContext *context = goc_item_get_style_context (GOC_ITEM (pg));
+       if (gnumeric_background_set (mstyle, cr, FALSE, context)) {
                cairo_rectangle (cr, x, y, w+1, h+1);
                cairo_fill (cr);
        }


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