[gnumeric] GUI: Style cell comment markers.



commit f2c2580888ccf5b3e94b42b0fffe57910819ac31
Author: Morten Welinder <terra gnome org>
Date:   Mon Mar 25 15:33:16 2013 -0400

    GUI: Style cell comment markers.

 src/gnm-pane.c                  |   22 ++++++++++++++++-
 src/gnumeric.css                |   15 ++++++++++-
 src/item-grid.c                 |   32 ++++++++++--------------
 src/sheet-object-cell-comment.c |   51 ++++++++++++++++++++++++++++++--------
 4 files changed, 88 insertions(+), 32 deletions(-)
---
diff --git a/src/gnm-pane.c b/src/gnm-pane.c
index 13d0dbc..faf4fd3 100644
--- a/src/gnm-pane.c
+++ b/src/gnm-pane.c
@@ -7,7 +7,7 @@
  *     Jody Goldberg (jody gnome org)
  */
 #include <gnumeric-config.h>
-#include <glib/gi18n-lib.h>
+#include <gnm-i18n.h>
 #include "gnumeric.h"
 #include "gnm-pane-impl.h"
 #include "gnm-pane.h"
@@ -972,6 +972,26 @@ 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;
+
+       gtk_widget_class_install_style_property
+               (widget_class,
+                g_param_spec_int ("function-indicator-size",
+                                  P_("Function Indicator Size"),
+                                  P_("Size of function indicator"),
+                                  0,
+                                  G_MAXINT,
+                                  10,
+                                  G_PARAM_READABLE));
+
+       gtk_widget_class_install_style_property
+               (widget_class,
+                g_param_spec_int ("comment-indicator-size",
+                                  P_("comment Indicator Size"),
+                                  P_("Size of comment indicator"),
+                                  0,
+                                  G_MAXINT,
+                                  6,
+                                  G_PARAM_READABLE));
 }
 
 GSF_CLASS (GnmPane, gnm_pane,
diff --git a/src/gnumeric.css b/src/gnumeric.css
index 3e4f99f..42c3f1a 100644
--- a/src/gnumeric.css
+++ b/src/gnumeric.css
@@ -8,7 +8,7 @@ ItemGrid {
 ItemGrid function-marker {
   color: green;
   border-color: #555555;
-  border-radius: 10px;  /* Cheesy overload of property. */
+  /* See also GnmPane */
 }
 
 /* This is the divider between panes when an area is frozen.  */
@@ -20,6 +20,19 @@ ItemGrid pane-divider {
   border-width: 1px;
 }
 
+
+/* GnmPane is the canvas we use for sheets.  We store custom properties
+   here because there is no un-deprecated way to store them for the
+   canvas items which aren't widgets.  */
+GnmPane {
+  -GnmPane-function-indicator-size: 10px;
+  -GnmPane-cell-comment-indicator-size: 6px;
+}
+
+CommentView {
+  color: red;
+}
+
 /* ------------------------------------------------------------------------- */
 /* ItemBar canvas items are the header buttons "A".."IV" and "1".."65536" */
 /* These are also styled with class button */
diff --git a/src/item-grid.c b/src/item-grid.c
index 6218369..2063dea 100644
--- a/src/item-grid.c
+++ b/src/item-grid.c
@@ -105,6 +105,7 @@ ig_reload_style (ItemGrid *ig)
        GtkStyleContext *context = goc_item_get_style_context (item);
        GtkBorder border;
        GtkStateFlags state = GTK_STATE_FLAG_NORMAL;
+       GnmPane *pane = GNM_PANE (item->canvas);
 
        gtk_style_context_save (context);
        gtk_style_context_add_region (context, "function-marker", 0);
@@ -112,10 +113,6 @@ ig_reload_style (ItemGrid *ig)
                                     &ig->function_marker_color);
        gtk_style_context_get_border_color (context, state,
                                            &ig->function_marker_border_color);
-       gtk_style_context_get (context, state,
-                              "border-radius",
-                              &ig->function_marker_size,
-                              NULL);
        gtk_style_context_restore (context);
 
        gtk_style_context_save (context);
@@ -125,6 +122,14 @@ ig_reload_style (ItemGrid *ig)
        gtk_style_context_get_border (context, GTK_STATE_FLAG_NORMAL, &border);
        ig->pane_divider_width = border.top;  /* Hack? */
        gtk_style_context_restore (context);
+
+       /* ---------------------------------------- */
+
+       context = gtk_widget_get_style_context (GTK_WIDGET (pane));
+       gtk_widget_style_get (GTK_WIDGET (pane),
+                             "function-indicator-size",
+                             &ig->function_marker_size,
+                             NULL);
 }
 
 static void
@@ -195,8 +200,7 @@ item_grid_realize (GocItem *item)
        GdkDisplay *display;
        ItemGrid   *ig;
 
-       if (parent_class->realize)
-               parent_class->realize (item);
+       parent_class->realize (item);
 
        ig = ITEM_GRID (item);
        ig_reload_style (ig);
@@ -213,19 +217,9 @@ static void
 item_grid_unrealize (GocItem *item)
 {
        ItemGrid *ig = ITEM_GRID (item);
-
-       if (ig->cursor_link) {
-               g_object_unref (ig->cursor_link);
-               ig->cursor_link = NULL;
-       }
-
-       if (ig->cursor_cross) {
-               g_object_unref (ig->cursor_cross);
-               ig->cursor_cross = NULL;
-       }
-
-       if (parent_class->unrealize)
-               parent_class->unrealize (item);
+       g_clear_object (&ig->cursor_link);
+       g_clear_object (&ig->cursor_cross);
+       parent_class->unrealize (item);
 }
 
 static void
diff --git a/src/sheet-object-cell-comment.c b/src/sheet-object-cell-comment.c
index 326b15a..22ca4c0 100644
--- a/src/sheet-object-cell-comment.c
+++ b/src/sheet-object-cell-comment.c
@@ -45,6 +45,7 @@ struct _GnmComment {
        PangoAttrList  *markup;
 };
 typedef SheetObjectClass GnmCommentClass;
+static GObjectClass *cell_comment_parent_class;
 enum {
        CC_PROP_0,
        CC_PROP_TEXT,
@@ -52,13 +53,37 @@ enum {
        CC_PROP_MARKUP
 };
 
-static GObjectClass *parent_klass;
+typedef struct {
+       SheetObjectView base;
 
-#define TRIANGLE_WIDTH 6
+       GdkRGBA comment_indicator_color;
+       int comment_indicator_size;
+} CommentView;
+typedef SheetObjectViewClass   CommentViewClass;
+static GocItemClass *comment_view_parent_class;
+
+static void
+comment_view_reload_style (CommentView *cv)
+{
+       GocItem *item = GOC_ITEM (cv);
+       GnmPane *pane = GNM_PANE (item->canvas);
+       GtkStyleContext *context;
+
+       context = goc_item_get_style_context (item);
+       gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL,
+                                    &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);
+}
 
 static void
 comment_view_set_bounds (SheetObjectView *sov, double const *coords, gboolean visible)
 {
+       CommentView *cv = (CommentView *)sov;
        GocPoints *points = goc_points_new (3);
        GocItem *item = GOC_ITEM (GOC_GROUP (sov)->children->data);
        if (visible) {
@@ -83,9 +108,9 @@ comment_view_set_bounds (SheetObjectView *sov, double const *coords, gboolean vi
                y = scg_colrow_distance_get (scg, FALSE, 0, so->anchor.cell_bound.start.row)+ 1;
                points->points[0].y = scale * y;
                points->points[1].y = scale * y;
-               points->points[2].y = scale * y + TRIANGLE_WIDTH;
+               points->points[2].y = scale * y + cv->comment_indicator_size;
 
-               dx = TRIANGLE_WIDTH;
+               dx = cv->comment_indicator_size;
                x = scg_colrow_distance_get (scg, TRUE, 0, far_col);
                points->points[0].x = scale * x - dx;
                points->points[1].x = scale * x;
@@ -168,6 +193,8 @@ comment_view_class_init (SheetObjectViewClass *sov_klass)
 {
        GocItemClass *item_klass = (GocItemClass *) sov_klass;
 
+       comment_view_parent_class = g_type_class_peek_parent (sov_klass);
+
        sov_klass->set_bounds   = comment_view_set_bounds;
 
        item_klass->button_pressed = comment_view_button_pressed;
@@ -177,8 +204,6 @@ comment_view_class_init (SheetObjectViewClass *sov_klass)
        item_klass->leave_notify = comment_view_leave_notify;
 }
 
-typedef SheetObjectView                CommentView;
-typedef SheetObjectViewClass   CommentViewClass;
 static GSF_CLASS (CommentView, comment_view,
        comment_view_class_init, NULL,
        SHEET_OBJECT_VIEW_TYPE)
@@ -206,7 +231,7 @@ cell_comment_finalize (GObject *object)
                cc->markup = NULL;
        }
 
-       parent_klass->finalize (object);
+       cell_comment_parent_class->finalize (object);
 }
 
 static void
@@ -264,13 +289,17 @@ cell_comment_new_view (SheetObject *so, SheetObjectViewContainer *container)
 {
        GnmPane *pane = GNM_PANE (container);
        GocItem *view = goc_item_new (pane->grid_items,
-               comment_view_get_type (),
-               NULL);
+                                     comment_view_get_type (),
+                                     NULL);
+       CommentView *cv = (CommentView *)view;
        GOStyle *style = go_styled_object_get_style (
                GO_STYLED_OBJECT (goc_item_new (GOC_GROUP (view),
                        GOC_TYPE_POLYGON, NULL)));
+
+       comment_view_reload_style (cv);
+
        style->line.dash_type = GO_LINE_NONE;
-       style->fill.pattern.back = GO_COLOR_RED;
+       style->fill.pattern.back = go_color_from_gdk_rgba (&cv->comment_indicator_color, NULL);
        return gnm_pane_object_register (so, view, FALSE);
 }
 
@@ -331,7 +360,7 @@ cell_comment_class_init (GObjectClass *gobject_class)
 {
        SheetObjectClass *sheet_object_class = SHEET_OBJECT_CLASS (gobject_class);
 
-       parent_klass = g_type_class_peek_parent (gobject_class);
+       cell_comment_parent_class = g_type_class_peek_parent (gobject_class);
 
        /* Object class method overrides */
        gobject_class->finalize         = cell_comment_finalize;


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