[gnumeric] Code cleanups.



commit d5b2f223ba9f8327a8b0f15425a0cc573963c8d6
Author: Morten Welinder <terra gnome org>
Date:   Thu Apr 26 15:49:22 2018 -0400

    Code cleanups.

 src/gnm-pane.c                    |    6 ++--
 src/sheet-control-gui.c           |   14 ++++++------
 src/sheet-control-priv.h          |    2 +-
 src/sheet-control.c               |   20 +++++++----------
 src/sheet-control.h               |    6 ++--
 src/sheet-object.c                |    6 +---
 src/sheet-view.c                  |   41 ++++++++++++++++++++----------------
 src/sheet-view.h                  |   21 +++++++++----------
 src/wbc-gtk-actions.c             |    2 +-
 src/wbc-gtk-edit.c                |    2 +-
 src/widgets/gnumeric-expr-entry.c |    4 +-
 11 files changed, 61 insertions(+), 63 deletions(-)
---
diff --git a/src/gnm-pane.c b/src/gnm-pane.c
index 52a8e67..db731a9 100644
--- a/src/gnm-pane.c
+++ b/src/gnm-pane.c
@@ -84,7 +84,7 @@ static gboolean
 gnm_pane_object_key_press (GnmPane *pane, GdkEventKey *ev)
 {
        SheetControlGUI *scg = pane->simple.scg;
-       SheetControl    *sc = GNM_SC (scg);
+       SheetControl    *sc = GNM_SHEET_CONTROL (scg);
        gboolean const shift    = 0 != (ev->state & GDK_SHIFT_MASK);
        gboolean const control  = 0 != (ev->state & GDK_CONTROL_MASK);
        gboolean const alt      = 0 != (ev->state & GDK_MOD1_MASK);
@@ -1474,7 +1474,7 @@ gnm_pane_compute_visible_region (GnmPane *pane,
 
        /* Update the scrollbar sizes for the primary pane */
        if (pane->index == 0)
-               sc_scrollbar_config (GNM_SC (scg));
+               sc_scrollbar_config (GNM_SHEET_CONTROL (scg));
 
        /* Force the cursor to update its bounds relative to the new visible region */
        gnm_pane_reposition_cursors (pane);
@@ -2741,7 +2741,7 @@ control_point_button2_pressed (GocItem *item, int button, G_GNUC_UNUSED double x
 
        so  = g_object_get_data (G_OBJECT (item), "so");
        if (pane->drag.button == 1)
-               sheet_object_get_editor (so, GNM_SC (scg));
+               sheet_object_get_editor (so, GNM_SHEET_CONTROL (scg));
        return TRUE;
 }
 
diff --git a/src/sheet-control-gui.c b/src/sheet-control-gui.c
index 8080db6..f623f98 100644
--- a/src/sheet-control-gui.c
+++ b/src/sheet-control-gui.c
@@ -1554,7 +1554,7 @@ cb_canvas_resize (GtkWidget *w, G_GNUC_UNUSED GtkAllocation *allocation,
 static gboolean
 post_create_cb (SheetControlGUI *scg)
 {
-       Sheet *sheet = sc_sheet (GNM_SC (scg));
+       Sheet *sheet = sc_sheet (GNM_SHEET_CONTROL (scg));
        if (sheet->sheet_objects)
                scg_object_select (scg, (SheetObject *) sheet->sheet_objects->data);
        return FALSE;
@@ -1755,7 +1755,7 @@ sheet_control_gui_new (SheetView *sv, WBCGtk *wbcg)
                        G_CALLBACK (cb_table_destroy), G_OBJECT (scg),
                        G_CONNECT_SWAPPED);
 
-               gnm_sheet_view_attach_control (sv, GNM_SC (scg));
+               gnm_sheet_view_attach_control (sv, GNM_SHEET_CONTROL (scg));
 
                g_object_connect (G_OBJECT (sheet),
                         "swapped_signal::notify::text-is-rtl", cb_scg_direction_changed, scg,
@@ -1790,7 +1790,7 @@ sheet_control_gui_new (SheetView *sv, WBCGtk *wbcg)
                        g_signal_connect (G_OBJECT (scg->vs), "key-press-event",
                                          G_CALLBACK (sheet_object_key_pressed), scg);
                }
-               gnm_sheet_view_attach_control (sv, GNM_SC (scg));
+               gnm_sheet_view_attach_control (sv, GNM_SHEET_CONTROL (scg));
                if (scg->vs) {
                        g_object_set_data (G_OBJECT (scg->vs), "sheet-control", scg);
                        if (sheet->sheet_objects) {
@@ -1897,7 +1897,7 @@ scg_finalize (GObject *object)
                g_signal_handlers_disconnect_by_func (sheet, cb_scg_redraw_resize, scg);
                g_signal_handlers_disconnect_by_func (sheet, cb_scg_sheet_resized, scg);
                g_signal_handlers_disconnect_by_func (sheet, cb_scg_direction_changed, scg);
-               gnm_sheet_view_detach_control (sc);
+               gnm_sheet_view_detach_control (sc->view, sc);
        }
 
        if (scg->grid) {
@@ -2655,7 +2655,7 @@ scg_object_select (SheetControlGUI *scg, SheetObject *so)
                wbcg_insert_object_clear (scg->wbcg);
                scg_cursor_visible (scg, FALSE);
                scg_set_display_cursor (scg);
-               scg_unant (GNM_SC (scg));
+               scg_unant (GNM_SHEET_CONTROL (scg));
 
                scg->selected_objects = g_hash_table_new_full (
                        g_direct_hash, g_direct_equal,
@@ -3979,7 +3979,7 @@ scg_class_init (GObjectClass *object_class)
 }
 
 GSF_CLASS (SheetControlGUI, sheet_control_gui,
-          scg_class_init, scg_init, GNM_SC_TYPE)
+          scg_class_init, scg_init, GNM_SHEET_CONTROL_TYPE)
 
 static gint
 cb_scg_queued_movement (SheetControlGUI *scg)
@@ -4534,7 +4534,7 @@ scg_drag_data_get (SheetControlGUI *scg, GtkSelectionData *selection_data)
                gtk_selection_data_set (selection_data, target,
                                        8, (void *)scg, sizeof (scg));
        else if (strcmp (target_name, "application/x-gnumeric") == 0)
-               scg_drag_send_clipboard_objects (GNM_SC (scg),
+               scg_drag_send_clipboard_objects (GNM_SHEET_CONTROL (scg),
                        selection_data, objects);
        else if (strcmp (target_name, "application/x-goffice-graph") == 0)
                scg_drag_send_graph (scg, selection_data, objects, target_name);
diff --git a/src/sheet-control-priv.h b/src/sheet-control-priv.h
index 8c7c659..f476ef0 100644
--- a/src/sheet-control-priv.h
+++ b/src/sheet-control-priv.h
@@ -39,7 +39,7 @@ typedef struct {
                                         GnmInputMsg *im, GnmCellPos *pos);
 } SheetControlClass;
 
-#define SHEET_CONTROL_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GNM_SC_TYPE, SheetControlClass))
+#define SHEET_CONTROL_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GNM_SHEET_CONTROL_TYPE, SheetControlClass))
 
 G_END_DECLS
 
diff --git a/src/sheet-control.c b/src/sheet-control.c
index 1e23806..a8ec2e0 100644
--- a/src/sheet-control.c
+++ b/src/sheet-control.c
@@ -1,5 +1,3 @@
-/* vim: set sw=8: */
-
 /*
  * sheet-control.c:
  *
@@ -33,7 +31,7 @@ void sc_ ## func arglist                                      \
 {                                                              \
        SheetControlClass *sc_class;                            \
                                                                \
-       g_return_if_fail (GNM_IS_SC (sc));              \
+       g_return_if_fail (GNM_IS_SHEET_CONTROL (sc));           \
                                                                \
        sc_class = SC_CLASS (sc);                               \
        if (sc_class->handle != NULL)                           \
@@ -49,7 +47,7 @@ static void
 sc_finalize (GObject *obj)
 {
        /* Commented out until needed */
-       /* SheetControl *sc = GNM_SC (obj); */
+       /* SheetControl *sc = GNM_SHEET_CONTROL (obj); */
        parent_class->finalize (obj);
 }
 
@@ -67,12 +65,12 @@ GSF_CLASS (SheetControl, sheet_control,
  * sc_wbc:
  * @sc: #SheetControl
  *
- * Returns: (transfer none): the workbook control.
+ * Returns: (transfer none) (nullable): the workbook control.
  **/
 WorkbookControl *
 sc_wbc (SheetControl const *sc)
 {
-       g_return_val_if_fail (GNM_IS_SC (sc), NULL);
+       g_return_val_if_fail (GNM_IS_SHEET_CONTROL (sc), NULL);
        return sc->wbc;
 }
 
@@ -80,12 +78,12 @@ sc_wbc (SheetControl const *sc)
  * sc_sheet:
  * @sc: #SheetControl
  *
- * Returns: (transfer none): the sheet.
+ * Returns: (transfer none) (nullable): the sheet.
  **/
 Sheet *
 sc_sheet (SheetControl const *sc)
 {
-       g_return_val_if_fail (GNM_IS_SC (sc), NULL);
+       g_return_val_if_fail (GNM_IS_SHEET_CONTROL (sc), NULL);
        return sc->view ? sc->view->sheet : NULL;
 }
 
@@ -93,12 +91,12 @@ sc_sheet (SheetControl const *sc)
  * sc_view:
  * @sc: #SheetControl
  *
- * Returns: (transfer none): the sheet view.
+ * Returns: (transfer none) (nullable): the sheet view.
  **/
 SheetView *
 sc_view (SheetControl const *sc)
 {
-       g_return_val_if_fail (GNM_IS_SC (sc), NULL);
+       g_return_val_if_fail (GNM_IS_SHEET_CONTROL (sc), NULL);
        return sc->view;
 }
 
@@ -137,5 +135,3 @@ SC_VIRTUAL (object_create_view,     (SheetControl *sc, SheetObject *so), (sc, so))
 SC_VIRTUAL (scale_changed,     (SheetControl *sc), (sc))
 
 SC_VIRTUAL (show_im_tooltip,   (SheetControl *sc, GnmInputMsg *im, GnmCellPos *pos), (sc, im, pos))
-
-
diff --git a/src/sheet-control.h b/src/sheet-control.h
index 11ae40c..ec7f779 100644
--- a/src/sheet-control.h
+++ b/src/sheet-control.h
@@ -7,9 +7,9 @@
 
 G_BEGIN_DECLS
 
-#define GNM_SC_TYPE    (sheet_control_get_type ())
-#define GNM_SC(obj)    (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNM_SC_TYPE, SheetControl))
-#define GNM_IS_SC(o)   (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNM_SC_TYPE))
+#define GNM_SHEET_CONTROL_TYPE (sheet_control_get_type ())
+#define GNM_SHEET_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNM_SHEET_CONTROL_TYPE, SheetControl))
+#define GNM_IS_SHEET_CONTROL(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNM_SHEET_CONTROL_TYPE))
 
 /* Lifecycle */
 GType sheet_control_get_type   (void);
diff --git a/src/sheet-object.c b/src/sheet-object.c
index ea85423..c3b9737 100644
--- a/src/sheet-object.c
+++ b/src/sheet-object.c
@@ -1344,8 +1344,6 @@ sheet_object_direction_set (SheetObject *so, gdouble const *coords)
  *
  * Returns: %TRUE if we should draw the object as we are laying it out on
  * an sheet. If %FALSE we draw a rectangle where the object is going to go
- *
- * Return Value:
  **/
 gboolean
 sheet_object_rubber_band_directly (G_GNUC_UNUSED SheetObject const *so)
@@ -1519,7 +1517,7 @@ cb_so_menu_activate (GObject *menu, GocItem *view)
                if (data == NULL)
                        data = GNM_SIMPLE_CANVAS (view->canvas)->scg;
 
-               (a->func) (so, GNM_SC (data));
+               (a->func) (so, GNM_SHEET_CONTROL (data));
        }
 }
 
@@ -1646,7 +1644,7 @@ static gboolean
 sheet_object_view_button2_pressed (GocItem *item, int button, double x, double y)
 {
        if (button == 1 && !GNM_IS_PANE (item->canvas)) {
-               SheetControl *sc = GNM_SC (g_object_get_data (G_OBJECT (item->canvas), "sheet-control"));
+               SheetControl *sc = GNM_SHEET_CONTROL (g_object_get_data (G_OBJECT (item->canvas), 
"sheet-control"));
                SheetObject *so = (SheetObject *) g_object_get_qdata (G_OBJECT (item), sov_so_quark);
 
                if (sc && sheet_object_can_edit (so))
diff --git a/src/sheet-view.c b/src/sheet-view.c
index b6a0d4c..6a0e13c 100644
--- a/src/sheet-view.c
+++ b/src/sheet-view.c
@@ -156,27 +156,22 @@ void
 gnm_sheet_view_attach_control (SheetView *sv, SheetControl *sc)
 {
        g_return_if_fail (GNM_IS_SHEET_VIEW (sv));
-       g_return_if_fail (GNM_IS_SC (sc));
+       g_return_if_fail (GNM_IS_SHEET_CONTROL (sc));
        g_return_if_fail (sc->view == NULL);
 
-       if (sv->controls == NULL)
-               sv->controls = g_ptr_array_new ();
        g_ptr_array_add (sv->controls, sc);
        sc->view  = sv;
        sv_init_sc (sv, sc);
 }
 
 void
-gnm_sheet_view_detach_control (SheetControl *sc)
+gnm_sheet_view_detach_control (SheetView *sv, SheetControl *sc)
 {
-       g_return_if_fail (GNM_IS_SC (sc));
-       g_return_if_fail (GNM_IS_SHEET_VIEW (sc->view));
+       g_return_if_fail (GNM_IS_SHEET_VIEW (sv));
+       g_return_if_fail (GNM_IS_SHEET_CONTROL (sc));
+       g_return_if_fail (sv == sc->view);
 
-       g_ptr_array_remove (sc->view->controls, sc);
-       if (sc->view->controls->len == 0) {
-               g_ptr_array_free (sc->view->controls, TRUE);
-               sc->view->controls = NULL;
-       }
+       g_ptr_array_remove (sv->controls, sc);
        sc->view = NULL;
 }
 
@@ -214,17 +209,24 @@ gnm_sheet_view_weak_unref (SheetView **ptr)
 }
 
 static void
+sv_finalize (GObject *object)
+{
+       SheetView *sv = GNM_SHEET_VIEW (object);
+       g_ptr_array_free (sv->controls, TRUE);
+       parent_class->finalize (object);
+}
+
+static void
 sv_real_dispose (GObject *object)
 {
        SheetView *sv = GNM_SHEET_VIEW (object);
 
-       if (sv->controls != NULL) {
-               SHEET_VIEW_FOREACH_CONTROL (sv, control, {
-                       gnm_sheet_view_detach_control (control);
-                       g_object_unref (control);
-               });
-               if (sv->controls != NULL)
-                       g_warning ("Unexpected left-over controls");
+       while (sv->controls->len > 0) {
+               SheetControl *control =
+                       g_ptr_array_index (sv->controls,
+                                          sv->controls->len - 10);
+               gnm_sheet_view_detach_control (sv, control);
+               g_object_unref (control);
        }
 
        if (sv->sheet) {
@@ -255,6 +257,7 @@ gnm_sheet_view_class_init (GObjectClass *klass)
 
        parent_class = g_type_class_peek_parent (klass);
        klass->dispose = sv_real_dispose;
+       klass->finalize = sv_finalize;
 }
 
 static void
@@ -282,6 +285,8 @@ gnm_sheet_view_init (GObject *object)
        sv->selection_mode = GNM_SELECTION_MODE_ADD;
        sv->selections_simplified = NULL;
        sv_selection_add_pos (sv, 0, 0, GNM_SELECTION_MODE_ADD);
+
+       sv->controls = g_ptr_array_new ();
 }
 
 GSF_CLASS (SheetView, gnm_sheet_view,
diff --git a/src/sheet-view.h b/src/sheet-view.h
index 8408424..a6a7bc4 100644
--- a/src/sheet-view.h
+++ b/src/sheet-view.h
@@ -74,7 +74,7 @@ typedef GObjectClass SheetViewClass;
 GType        gnm_sheet_view_get_type (void);
 SheetView    *gnm_sheet_view_new         (Sheet *sheet, WorkbookView *wbv);
 void         gnm_sheet_view_attach_control  (SheetView *sv, SheetControl *sc);
-void         gnm_sheet_view_detach_control  (SheetControl *sc);
+void         gnm_sheet_view_detach_control  (SheetView *sv, SheetControl *sc);
 void         gnm_sheet_view_weak_ref     (SheetView *sv, SheetView **ptr);
 void         gnm_sheet_view_weak_unref   (SheetView **ptr);
 void         gnm_sheet_view_update       (SheetView *sv);
@@ -123,16 +123,15 @@ void       gnm_sheet_view_panes_insdel_colrow (SheetView *sv, gboolean is_cols,
                                 gboolean is_insert, int start, int count);
 void    gnm_sheet_view_set_initial_top_left(SheetView *sv, int col, int row);
 
-#define SHEET_VIEW_FOREACH_CONTROL(sv, control, code)                          \
-do {                                                                           \
-       int j;                                                                  \
-       GPtrArray *controls = (sv)->controls;                                   \
-       if (controls != NULL) /* Reverse is important during destruction */     \
-               for (j = controls->len; j-- > 0 ;) {                            \
-                       SheetControl *control =                                 \
-                               g_ptr_array_index (controls, j);                \
-                       code                                                    \
-               }                                                               \
+#define SHEET_VIEW_FOREACH_CONTROL(sv, control, code)          \
+do {                                                           \
+       int ctrlno;                                             \
+       GPtrArray *controls = (sv)->controls;                   \
+       for (ctrlno = controls->len; ctrlno-- > 0 ;) {          \
+               SheetControl *control =                         \
+                       g_ptr_array_index (controls, ctrlno);   \
+               code                                            \
+       }                                                       \
 } while (0)
 
 G_END_DECLS
diff --git a/src/wbc-gtk-actions.c b/src/wbc-gtk-actions.c
index fac2e00..1fc9c01 100644
--- a/src/wbc-gtk-actions.c
+++ b/src/wbc-gtk-actions.c
@@ -1173,7 +1173,7 @@ static GNM_ACTION_DEF (cb_insert_image)
        }
 }
 
-static GNM_ACTION_DEF (cb_insert_hyperlink)    { dialog_hyperlink (wbcg, GNM_SC (wbcg_cur_scg (wbcg))); }
+static GNM_ACTION_DEF (cb_insert_hyperlink)    { dialog_hyperlink (wbcg, GNM_SHEET_CONTROL (wbcg_cur_scg 
(wbcg))); }
 static GNM_ACTION_DEF (cb_formula_guru)                { dialog_formula_guru (wbcg, NULL); }
 static GNM_ACTION_DEF (cb_insert_sort_ascending) { workbook_cmd_wrap_sort (GNM_WBC (wbcg), 1);}
 static GNM_ACTION_DEF (cb_insert_sort_descending){ workbook_cmd_wrap_sort (GNM_WBC (wbcg), 0);}
diff --git a/src/wbc-gtk-edit.c b/src/wbc-gtk-edit.c
index 33b786f..01cf18e 100644
--- a/src/wbc-gtk-edit.c
+++ b/src/wbc-gtk-edit.c
@@ -1044,7 +1044,7 @@ wbcg_insert_object (WBCGtk *wbcg, SheetObject *so)
                        scg_object_unselect (scg, NULL);
                        scg_cursor_visible (scg, FALSE);
                        scg_set_display_cursor (scg);
-                       sc_unant (GNM_SC (scg));
+                       sc_unant (GNM_SHEET_CONTROL (scg));
                }
        }
        /* we can't set wbcg->new_object before now because if one sheet has a
diff --git a/src/widgets/gnumeric-expr-entry.c b/src/widgets/gnumeric-expr-entry.c
index 65b02fd..6a58626 100644
--- a/src/widgets/gnumeric-expr-entry.c
+++ b/src/widgets/gnumeric-expr-entry.c
@@ -2339,7 +2339,7 @@ gnm_expr_entry_set_scg (GnmExprEntry *gee, SheetControlGUI *scg)
        if (scg) {
                g_object_weak_ref (G_OBJECT (gee->scg),
                                   (GWeakNotify) cb_scg_destroy, gee);
-               gee->sheet = sc_sheet (GNM_SC (scg));
+               gee->sheet = sc_sheet (GNM_SHEET_CONTROL (scg));
                parse_pos_init_editpos (&gee->pp, scg_view (gee->scg));
                gee->wbcg = scg_wbcg (gee->scg);
        } else
@@ -2657,7 +2657,7 @@ gnm_expr_entry_parse (GnmExprEntry *gee, GnmParsePos const *pp,
                SheetControlGUI *scg = wbcg_cur_scg (gee->wbcg);
                Rangesel const *rs = &gee->rangesel;
                if (gee == wbcg_get_entry_logical (gee->wbcg) &&
-                   start_sel && sc_sheet (GNM_SC (scg)) == rs->ref.a.sheet) {
+                   start_sel && sc_sheet (GNM_SHEET_CONTROL (scg)) == rs->ref.a.sheet) {
                        scg_rangesel_bound (scg,
                                rs->ref.a.col, rs->ref.a.row,
                                rs->ref.b.col, rs->ref.b.row);


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