[gnumeric] Objects: don't use "pointer" as property type



commit 954034eacc4b5dba1cdf4c6798fe346749167e74
Author: Morten Welinder <terra gnome org>
Date:   Sun Apr 15 14:02:10 2018 -0400

    Objects: don't use "pointer" as property type
    
    We have boxed types now.

 NEWS                              |    1 +
 src/parse-util.c                  |    9 +++---
 src/parse-util.h                  |    2 +-
 src/preview-grid.c                |   54 ++++++++++++++++++++-----------------
 src/sheet-object-widget.c         |    7 +++--
 src/sheet.c                       |   26 +++++++++++-------
 src/sheet.h                       |    2 +-
 src/wbc-gtk.c                     |    5 ++-
 src/widgets/gnumeric-expr-entry.c |   13 +++++----
 src/workbook-view.c               |   28 ++++++++++---------
 10 files changed, 82 insertions(+), 65 deletions(-)
---
diff --git a/NEWS b/NEWS
index 66b9c44..65b40d4 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ Morten:
        * Clean up workbook view construction.
        * Test suite improvements.
        * Fix problems with boxed types.
+       * Avoid most punting for object properties.
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.39
diff --git a/src/parse-util.c b/src/parse-util.c
index 8bd9469..08013b1 100644
--- a/src/parse-util.c
+++ b/src/parse-util.c
@@ -1586,11 +1586,12 @@ gnm_conventions_unref (GnmConventions *c)
  * Returns: (transfer full) (nullable): a new reference to @c
  **/
 GnmConventions *
-gnm_conventions_ref (GnmConventions *c)
+gnm_conventions_ref (GnmConventions const *c)
 {
-       if (c)
-               c->ref_count++;
-       return c;
+       GnmConventions *uc = (GnmConventions *)c;
+       if (uc)
+               uc->ref_count++;
+       return uc;
 }
 
 GType
diff --git a/src/parse-util.h b/src/parse-util.h
index 13cfe28..1dea9f4 100644
--- a/src/parse-util.h
+++ b/src/parse-util.h
@@ -208,7 +208,7 @@ GType           gnm_conventions_get_type (void);
 GnmConventions *gnm_conventions_new     (void);
 GnmConventions *gnm_conventions_new_full (unsigned size);
 
-GnmConventions *gnm_conventions_ref     (GnmConventions *c);
+GnmConventions *gnm_conventions_ref     (GnmConventions const *c);
 void           gnm_conventions_unref    (GnmConventions *c);
 
 
diff --git a/src/preview-grid.c b/src/preview-grid.c
index 6bddf73..1e56703 100644
--- a/src/preview-grid.c
+++ b/src/preview-grid.c
@@ -320,21 +320,18 @@ preview_grid_set_property (GObject *obj, guint param_id,
        case PREVIEW_GRID_PROP_DEFAULT_ROW_HEIGHT :
                pg->defaults.row_height = g_value_get_uint (value);
                break;
-       case PREVIEW_GRID_PROP_DEFAULT_STYLE : { /* add a  ref */
-               GnmStyle *style = g_value_get_pointer (value);
+       case PREVIEW_GRID_PROP_DEFAULT_STYLE : {
+               GnmStyle *style = g_value_dup_boxed (value);
                g_return_if_fail (style != NULL);
-               gnm_style_ref (style);
                gnm_style_unref (pg->defaults.style);
                pg->defaults.style = style;
                break;
        }
-       case PREVIEW_GRID_PROP_DEFAULT_VALUE : { /* steal ownership */
-               GnmValue *val = g_value_get_pointer (value);
+       case PREVIEW_GRID_PROP_DEFAULT_VALUE: {
+               GnmValue *val = g_value_dup_boxed (value);
                g_return_if_fail (val != NULL);
-               if (pg->defaults.value != val) {
-                       value_release (pg->defaults.value);
-                       pg->defaults.value = val;
-               }
+               value_release (pg->defaults.value);
+               pg->defaults.value = val;
                break;
        }
        default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, param_id, pspec);
@@ -384,24 +381,31 @@ gnm_preview_grid_class_init (GObjectClass *gobject_klass)
 
        gobject_klass->set_property = preview_grid_set_property;
        gobject_klass->dispose = preview_grid_dispose;
-       g_object_class_install_property (gobject_klass, PREVIEW_GRID_PROP_RENDER_GRIDLINES,
-               g_param_spec_boolean ("render-gridlines", NULL, NULL,
-                       FALSE,
-                       GSF_PARAM_STATIC | G_PARAM_WRITABLE));
-        g_object_class_install_property (gobject_klass, PREVIEW_GRID_PROP_DEFAULT_COL_WIDTH,
+       g_object_class_install_property
+               (gobject_klass, PREVIEW_GRID_PROP_RENDER_GRIDLINES,
+                g_param_spec_boolean ("render-gridlines", NULL, NULL,
+                                      FALSE,
+                                      GSF_PARAM_STATIC | G_PARAM_WRITABLE));
+        g_object_class_install_property
+               (gobject_klass, PREVIEW_GRID_PROP_DEFAULT_COL_WIDTH,
                  g_param_spec_uint ("default-col-width", NULL, NULL,
-                       0, G_MAXUINT, 0,
-                       GSF_PARAM_STATIC | G_PARAM_WRITABLE));
-        g_object_class_install_property (gobject_klass, PREVIEW_GRID_PROP_DEFAULT_ROW_HEIGHT,
+                                   0, G_MAXUINT, 0,
+                                   GSF_PARAM_STATIC | G_PARAM_WRITABLE));
+        g_object_class_install_property
+               (gobject_klass, PREVIEW_GRID_PROP_DEFAULT_ROW_HEIGHT,
                  g_param_spec_uint ("default-row-height", NULL, NULL,
-                       0, G_MAXUINT, 0,
-                       GSF_PARAM_STATIC | G_PARAM_WRITABLE));
-        g_object_class_install_property (gobject_klass, PREVIEW_GRID_PROP_DEFAULT_STYLE,
-                 g_param_spec_pointer ("default-style", NULL, NULL,
-                       GSF_PARAM_STATIC | G_PARAM_WRITABLE));
-        g_object_class_install_property (gobject_klass, PREVIEW_GRID_PROP_DEFAULT_VALUE,
-                 g_param_spec_pointer ("default-value", NULL, NULL,
-                       GSF_PARAM_STATIC | G_PARAM_WRITABLE));
+                                   0, G_MAXUINT, 0,
+                                   GSF_PARAM_STATIC | G_PARAM_WRITABLE));
+        g_object_class_install_property
+               (gobject_klass, PREVIEW_GRID_PROP_DEFAULT_STYLE,
+                 g_param_spec_boxed ("default-style", NULL, NULL,
+                                     gnm_style_get_type (),
+                                     GSF_PARAM_STATIC | G_PARAM_WRITABLE));
+        g_object_class_install_property
+               (gobject_klass, PREVIEW_GRID_PROP_DEFAULT_VALUE,
+                 g_param_spec_boxed ("default-value", NULL, NULL,
+                                    gnm_value_get_type (),
+                                    GSF_PARAM_STATIC | G_PARAM_WRITABLE));
 
        item_klass->update_bounds = preview_grid_update_bounds;
        item_klass->draw_region = preview_grid_draw_region;
diff --git a/src/sheet-object-widget.c b/src/sheet-object-widget.c
index b90ae27..10c9659 100644
--- a/src/sheet-object-widget.c
+++ b/src/sheet-object-widget.c
@@ -2845,7 +2845,7 @@ sheet_widget_radio_button_get_property (GObject *obj, guint param_id,
                g_value_set_boxed (value, NULL); /* swrb->markup */
                break;
        case SOR_PROP_VALUE:
-               g_value_set_pointer (value, swrb->value);
+               g_value_set_boxed (value, swrb->value);
                break;
        default :
                G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, param_id, pspec);
@@ -2876,7 +2876,7 @@ sheet_widget_radio_button_set_property (GObject *obj, guint param_id,
                break;
        case SOR_PROP_VALUE:
                sheet_widget_radio_button_set_value (GNM_SO (swrb),
-                                                     g_value_peek_pointer (value));
+                                                    g_value_get_boxed (value));
                break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, param_id, pspec);
@@ -3412,7 +3412,8 @@ SOW_MAKE_TYPE (radio_button, RadioButton,
                                                    GSF_PARAM_STATIC | G_PARAM_READWRITE));
                       g_object_class_install_property
                               (object_class, SOR_PROP_VALUE,
-                               g_param_spec_pointer ("value", NULL, NULL,
+                               g_param_spec_boxed ("value", NULL, NULL,
+                                                   gnm_value_get_type (),
                                                    GSF_PARAM_STATIC | G_PARAM_READWRITE));
               })
 
diff --git a/src/sheet.c b/src/sheet.c
index 898ade4..5ae33b3 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -205,7 +205,8 @@ sheet_set_conventions (Sheet *sheet, GnmConventions const *convs)
 {
        if (sheet->convs == convs)
                return;
-       sheet->convs = convs;
+       gnm_conventions_unref (sheet->convs);
+       sheet->convs = gnm_conventions_ref (convs);
        if (sheet->display_formulas)
                re_render_formulas (sheet);
        SHEET_FOREACH_VIEW (sheet, sv,
@@ -505,7 +506,7 @@ gnm_sheet_set_property (GObject *object, guint property_id,
                break;
 
        case PROP_CONVENTIONS:
-               sheet_set_conventions (sheet, g_value_get_pointer (value));
+               sheet_set_conventions (sheet, g_value_get_boxed (value));
                break;
        case PROP_USE_R1C1: /* convenience api */
                sheet_set_conventions (sheet, !!g_value_get_boolean (value)
@@ -640,7 +641,7 @@ gnm_sheet_get_property (GObject *object, guint property_id,
                break;
 
        case PROP_CONVENTIONS:
-               g_value_set_pointer (value, (gpointer)sheet->convs);
+               g_value_set_boxed (value, sheet->convs);
                break;
        case PROP_USE_R1C1: /* convenience api */
                g_value_set_boolean (value, sheet->convs->r1c1_addresses);
@@ -817,7 +818,7 @@ gnm_sheet_init (Sheet *sheet)
                                             (GCompareFunc)&cell_set_equal);
 
        /* Init preferences */
-       sheet->convs = gnm_conventions_default;
+       sheet->convs = gnm_conventions_ref (gnm_conventions_default);
 
        /* FIXME: probably not here.  */
        /* See also gtk_widget_create_pango_context ().  */
@@ -1031,12 +1032,14 @@ gnm_sheet_class_init (GObjectClass *gobject_class)
                                      P_("Allow the user to select unlocked cells while a sheet is 
protected"),
                                      TRUE, GSF_PARAM_STATIC | G_PARAM_READWRITE));
 
-       g_object_class_install_property (gobject_class, PROP_CONVENTIONS,
-               g_param_spec_pointer ("conventions",
-                                     P_("Display convention for expressions (default Gnumeric A1)"),
-                                     P_("How to format displayed expressions, (A1 vs R1C1, function names, 
...)"),
-                                     GSF_PARAM_STATIC |
-                                     G_PARAM_READWRITE));
+       g_object_class_install_property
+               (gobject_class, PROP_CONVENTIONS,
+                g_param_spec_boxed ("conventions",
+                                    P_("Display convention for expressions (default Gnumeric A1)"),
+                                    P_("How to format displayed expressions, (A1 vs R1C1, function names, 
...)"),
+                                    gnm_conventions_get_type (),
+                                    GSF_PARAM_STATIC |
+                                    G_PARAM_READWRITE));
        g_object_class_install_property (gobject_class, PROP_USE_R1C1, /* convenience wrapper to CONVENTIONS 
*/
                g_param_spec_boolean ("use-r1c1",
                                      P_("Display convention for expressions as XLS_R1C1 vs default"),
@@ -4675,6 +4678,9 @@ gnm_sheet_finalize (GObject *obj)
 
        g_clear_object (&sheet->solver_parameters);
 
+       gnm_conventions_unref (sheet->convs);
+       sheet->convs = NULL;
+
        g_list_free_full (sheet->scenarios, g_object_unref);
        sheet->scenarios = NULL;
 
diff --git a/src/sheet.h b/src/sheet.h
index abce118..a5936a3 100644
--- a/src/sheet.h
+++ b/src/sheet.h
@@ -58,7 +58,7 @@ struct _Sheet {
        GnmCellPos   max_object_extent;
 
        /* Sheet level preferences */
-       GnmConventions const *convs;
+       GnmConventions *convs;
        gboolean    display_formulas;
        gboolean    hide_zero;
        gboolean    hide_grid;
diff --git a/src/wbc-gtk.c b/src/wbc-gtk.c
index 18c0e5a..fac5ebc 100644
--- a/src/wbc-gtk.c
+++ b/src/wbc-gtk.c
@@ -4014,9 +4014,10 @@ cb_auto_expr_insert_formula (WBCGtk *wbcg, gboolean below)
        specs->func = NULL;
        g_object_get (G_OBJECT (wb_control_view (GNM_WBC (wbcg))),
                      "auto-expr-func", &(specs->func), NULL);
-       if (specs->func == NULL)
+       if (specs->func == NULL) {
                specs->func =  gnm_func_lookup_or_add_placeholder ("sum");
-       gnm_func_ref (specs->func);
+               gnm_func_ref (specs->func);
+       }
 
        cmd_analysis_tool (GNM_WBC (wbcg), scg_sheet (scg),
                           dao, specs, analysis_tool_auto_expression_engine,
diff --git a/src/widgets/gnumeric-expr-entry.c b/src/widgets/gnumeric-expr-entry.c
index 484284a..32cb0cd 100644
--- a/src/widgets/gnumeric-expr-entry.c
+++ b/src/widgets/gnumeric-expr-entry.c
@@ -511,7 +511,7 @@ gee_set_property (GObject      *object,
                gee->wbcg = WBC_GTK (g_value_get_object (value));
                break;
        case PROP_CONSTANT_FORMAT:
-               gee_set_format (gee, g_value_get_pointer (value));
+               gee_set_format (gee, g_value_get_boxed (value));
                break;
        case PROP_EDITING_CANCELED:
                gee->editing_canceled = g_value_get_boolean (value);
@@ -547,7 +547,7 @@ gee_get_property (GObject      *object,
                g_value_set_object (value, G_OBJECT (gee->wbcg));
                break;
        case PROP_CONSTANT_FORMAT:
-               g_value_set_pointer (value, (gpointer)gee->constant_format);
+               g_value_set_boxed (value, (gpointer)gee->constant_format);
                break;
        case PROP_EDITING_CANCELED:
                g_value_set_boolean (value, gee->editing_canceled);
@@ -1742,10 +1742,11 @@ gee_class_init (GObjectClass *gobject_class)
 
        g_object_class_install_property
                (gobject_class, PROP_CONSTANT_FORMAT,
-                g_param_spec_pointer ("constant-format",
-                                      P_("Constant Format"),
-                                      P_("Format for constants"),
-                                      GSF_PARAM_STATIC | G_PARAM_READWRITE));
+                g_param_spec_boxed ("constant-format",
+                                    P_("Constant Format"),
+                                    P_("Format for constants"),
+                                    go_format_get_type (),
+                                    GSF_PARAM_STATIC | G_PARAM_READWRITE));
 
        gee_debug = gnm_debug_flag ("gee");
 }
diff --git a/src/workbook-view.c b/src/workbook-view.c
index d982855..93adb0b 100644
--- a/src/workbook-view.c
+++ b/src/workbook-view.c
@@ -709,7 +709,7 @@ wb_view_set_property (GObject *object, guint property_id,
 
        switch (property_id) {
        case PROP_AUTO_EXPR_FUNC:
-               wb_view_auto_expr_func (wbv, g_value_get_pointer (value));
+               wb_view_auto_expr_func (wbv, g_value_get_boxed (value));
                break;
        case PROP_AUTO_EXPR_DESCR:
                wb_view_auto_expr_descr (wbv, g_value_get_string (value));
@@ -721,7 +721,7 @@ wb_view_set_property (GObject *object, guint property_id,
                wb_view_auto_expr_value (wbv, g_value_get_boxed (value));
                break;
        case PROP_AUTO_EXPR_EVAL_POS:
-               wb_view_auto_expr_eval_pos (wbv, g_value_get_pointer (value));
+               wb_view_auto_expr_eval_pos (wbv, g_value_get_boxed (value));
                break;
        case PROP_SHOW_HORIZONTAL_SCROLLBAR:
                wbv->show_horizontal_scrollbar = !!g_value_get_boolean (value);
@@ -771,7 +771,7 @@ wb_view_get_property (GObject *object, guint property_id,
 
        switch (property_id) {
        case PROP_AUTO_EXPR_FUNC:
-               g_value_set_pointer (value, wbv->auto_expr.func);
+               g_value_set_boxed (value, wbv->auto_expr.func);
                break;
        case PROP_AUTO_EXPR_DESCR:
                g_value_set_string (value, wbv->auto_expr.descr);
@@ -910,11 +910,12 @@ workbook_view_class_init (GObjectClass *gobject_class)
         g_object_class_install_property
                (gobject_class,
                 PROP_AUTO_EXPR_FUNC,
-                g_param_spec_pointer ("auto-expr-func",
-                                      P_("Auto-expression function"),
-                                      P_("The automatically computed sheet function."),
-                                      GSF_PARAM_STATIC |
-                                      G_PARAM_READWRITE));
+                g_param_spec_boxed ("auto-expr-func",
+                                    P_("Auto-expression function"),
+                                    P_("The automatically computed sheet function."),
+                                    gnm_func_get_type (),
+                                    GSF_PARAM_STATIC |
+                                    G_PARAM_READWRITE));
         g_object_class_install_property
                (gobject_class,
                 PROP_AUTO_EXPR_DESCR,
@@ -945,11 +946,12 @@ workbook_view_class_init (GObjectClass *gobject_class)
         g_object_class_install_property
                (gobject_class,
                 PROP_AUTO_EXPR_EVAL_POS,
-                g_param_spec_pointer ("auto-expr-eval-pos",
-                                      P_("Auto-expression position"),
-                                      P_("The cell position to track."),
-                                      GSF_PARAM_STATIC |
-                                      G_PARAM_WRITABLE));
+                g_param_spec_boxed ("auto-expr-eval-pos",
+                                    P_("Auto-expression position"),
+                                    P_("The cell position to track."),
+                                    gnm_eval_pos_get_type (),
+                                    GSF_PARAM_STATIC |
+                                    G_PARAM_WRITABLE));
         g_object_class_install_property
                (gobject_class,
                 PROP_SHOW_HORIZONTAL_SCROLLBAR,


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