Commit d5b2f223 authored by Morten Welinder's avatar Morten Welinder

Code cleanups.

parent 819a535b
......@@ -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;
}
......
......@@ -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);
......
......@@ -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
......
/* 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))
......@@ -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);
......
......@@ -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))
......
......@@ -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;
}
......@@ -213,18 +208,25 @@ 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,
......
......@@ -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
......
......@@ -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);}
......
......@@ -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
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment