[gnumeric] SheetObjectView: localize access to GocGroup::children
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] SheetObjectView: localize access to GocGroup::children
- Date: Thu, 4 Jun 2020 01:18:19 +0000 (UTC)
commit 698ded84b9ae2a271dbc593b9b503d586987ed48
Author: Morten Welinder <terra gnome org>
Date: Wed Jun 3 21:17:15 2020 -0400
SheetObjectView: localize access to GocGroup::children
Direct access is a bit dirty, but with this it is at least in one
place.
ChangeLog | 5 +++++
src/gnm-so-line.c | 5 +++--
src/gnm-so-polygon.c | 10 +++++-----
src/sheet-object-cell-comment.c | 2 +-
src/sheet-object-component.c | 12 ++++++------
src/sheet-object-graph.c | 13 +++++++------
src/sheet-object-image.c | 16 ++++++++--------
src/sheet-object-impl.h | 1 +
src/sheet-object-widget.c | 12 ++++--------
src/sheet-object.c | 17 +++++++++++++++++
src/widgets/gnm-filter-combo-view.c | 2 +-
src/widgets/gnm-sheet-slicer-combo-view.c | 2 +-
src/widgets/gnm-validation-combo-view.c | 2 +-
13 files changed, 60 insertions(+), 39 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index fe2d28003..c20c99c14 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2020-06-03 Morten Welinder <terra gnome org>
+
+ * src/sheet-object.c (sheet_object_view_get_item): New function
+ localizing our access to GocGroup::children
+
2020-05-31 Morten Welinder <terra gnome org>
* src/sheet-filter.c (gnm_filter_new): New argument attach. All
diff --git a/src/gnm-so-line.c b/src/gnm-so-line.c
index 88a5d9107..9abad0ab1 100644
--- a/src/gnm-so-line.c
+++ b/src/gnm-so-line.c
@@ -59,7 +59,8 @@ static SheetObjectClass *gnm_so_line_parent_class;
static void
so_line_view_set_bounds (SheetObjectView *sov, double const *coords, gboolean visible)
{
- GocItem *view = GOC_ITEM (sov), *item = GOC_ITEM (GOC_GROUP (view)->children->data);
+ GocItem *view = GOC_ITEM (sov);
+ GocItem *item = sheet_object_view_get_item (sov);
SheetObject *so = sheet_object_view_get_so (sov);
GOStyleLine const *style = &GNM_SO_LINE (so)->style->line;
double scale = goc_canvas_get_pixels_per_unit (view->canvas);
@@ -128,7 +129,7 @@ cb_gnm_so_line_changed (GnmSOLine const *sol,
G_GNUC_UNUSED GParamSpec *pspec,
GocItem *item)
{
- item = GOC_ITEM (GOC_GROUP (item)->children->data);
+ item = sheet_object_view_get_item (GNM_SO_VIEW (item));
goc_item_set (item,
"start-arrow", &sol->start_arrow,
"end-arrow", &sol->end_arrow,
diff --git a/src/gnm-so-polygon.c b/src/gnm-so-polygon.c
index b488c1ef9..8c87937d5 100644
--- a/src/gnm-so-polygon.c
+++ b/src/gnm-so-polygon.c
@@ -48,7 +48,7 @@ typedef SheetObjectClass GnmSOPolygonClass;
static void
so_polygon_view_set_bounds (SheetObjectView *sov, double const *coords, gboolean visible)
{
- GocItem *view = GOC_ITEM (sov->base.children->data);
+ GocItem *item = sheet_object_view_get_item (sov);
if (visible) {
SheetObject *so = sheet_object_view_get_so (sov);
@@ -77,11 +77,11 @@ so_polygon_view_set_bounds (SheetObjectView *sov, double const *coords, gboolean
pts->points[i].y = y_translate + y_scale * src[1];
}
- goc_item_set (view, "points", pts, NULL);
+ goc_item_set (item, "points", pts, NULL);
goc_points_unref (pts);
- goc_item_show (GOC_ITEM (view));
+ goc_item_show (item);
} else
- goc_item_hide (GOC_ITEM (view));
+ goc_item_hide (item);
}
static void
@@ -129,7 +129,7 @@ sop_default_style (void)
static void
cb_gnm_so_polygon_style_changed (GocItem *view, GnmSOPolygon const *sop)
{
- GocItem *item = GOC_ITEM (GOC_GROUP (view)->children->data);
+ GocItem *item = sheet_object_view_get_item (GNM_SO_VIEW (view));
GOStyle const *style = sop->style;
goc_item_set (item, "style", style, NULL);
}
diff --git a/src/sheet-object-cell-comment.c b/src/sheet-object-cell-comment.c
index cd5917271..0bb57fbd1 100644
--- a/src/sheet-object-cell-comment.c
+++ b/src/sheet-object-cell-comment.c
@@ -84,7 +84,7 @@ comment_view_set_bounds (SheetObjectView *sov, double const *coords, gboolean vi
{
CommentView *cv = (CommentView *)sov;
GocPoints *points = goc_points_new (3);
- GocItem *item = GOC_ITEM (GOC_GROUP (sov)->children->data);
+ GocItem *item = sheet_object_view_get_item (sov);
if (visible) {
SheetObject *so = sheet_object_view_get_so (sov);
SheetControlGUI const *scg = GNM_SIMPLE_CANVAS (item->canvas)->scg;
diff --git a/src/sheet-object-component.c b/src/sheet-object-component.c
index dec086972..d02171447 100644
--- a/src/sheet-object-component.c
+++ b/src/sheet-object-component.c
@@ -37,8 +37,8 @@
static void
so_component_view_set_bounds (SheetObjectView *sov, double const *coords, gboolean visible)
{
- GocItem *view = GOC_ITEM (GOC_GROUP (sov)->children->data);
- double scale = goc_canvas_get_pixels_per_unit (view->canvas);
+ GocItem *item = sheet_object_view_get_item (sov);
+ double scale = goc_canvas_get_pixels_per_unit (item->canvas);
if (visible) {
GOComponent *component = sheet_object_component_get_component (sheet_object_view_get_so
(sov));
@@ -50,19 +50,19 @@ so_component_view_set_bounds (SheetObjectView *sov, double const *coords, gboole
if (component && ! go_component_is_resizable (component)) {
go_component_get_size (component, &width, &height);
- goc_item_set (view,
+ goc_item_set (item,
"width", width * gnm_app_display_dpi_get (TRUE),
"height", height * gnm_app_display_dpi_get (FALSE),
NULL);
} else
- goc_item_set (view,
+ goc_item_set (item,
"width", (fabs (coords [2] - coords [0]) + 1.) / scale,
"height", (fabs (coords [3] - coords [1]) + 1.) / scale,
NULL);
- goc_item_show (view);
+ goc_item_show (item);
} else
- goc_item_hide (view);
+ goc_item_hide (item);
}
typedef SheetObjectView SOComponentGocView;
diff --git a/src/sheet-object-graph.c b/src/sheet-object-graph.c
index 3e73bcc88..ee171aab6 100644
--- a/src/sheet-object-graph.c
+++ b/src/sheet-object-graph.c
@@ -55,22 +55,22 @@
static void
so_graph_view_set_bounds (SheetObjectView *sov, double const *coords, gboolean visible)
{
- GocItem *view = GOC_ITEM (GOC_GROUP (sov)->children->data);
- double scale = goc_canvas_get_pixels_per_unit (view->canvas);
+ GocItem *item = sheet_object_view_get_item (sov);
+ double scale = goc_canvas_get_pixels_per_unit (item->canvas);
if (visible) {
goc_item_set (GOC_ITEM (sov),
"x", MIN (coords [0], coords[2]) / scale,
"y", MIN (coords [3], coords[1]) / scale,
NULL);
- goc_item_set (view,
+ goc_item_set (item,
"width", (fabs (coords [2] - coords [0]) + 1.) / scale,
"height", (fabs (coords [3] - coords [1]) + 1.) / scale,
NULL);
- goc_item_show (view);
+ goc_item_show (item);
} else
- goc_item_hide (view);
+ goc_item_hide (item);
}
static void
@@ -818,7 +818,8 @@ sheet_object_graph_ensure_size (SheetObject *sog)
{
GList *ptr = sog->realized_list;
while (ptr) {
- cb_post_new_view (GOC_ITEM (GOC_GROUP (ptr->data)->children->data));
+ SheetObjectView *sov = ptr->data;
+ cb_post_new_view (sheet_object_view_get_item (sov));
ptr = ptr->next;
}
}
diff --git a/src/sheet-object-image.c b/src/sheet-object-image.c
index e23fefe7b..1406c7929 100644
--- a/src/sheet-object-image.c
+++ b/src/sheet-object-image.c
@@ -46,21 +46,21 @@ attr_eq (const xmlChar *a, const char *s)
static void
so_image_view_set_bounds (SheetObjectView *sov, double const *coords, gboolean visible)
{
- GocItem *view = GOC_ITEM (GOC_GROUP (sov)->children->data);
- double scale = goc_canvas_get_pixels_per_unit (view->canvas);
+ GocItem *item = sheet_object_view_get_item (sov);
+ double scale = goc_canvas_get_pixels_per_unit (item->canvas);
if (visible) {
double x, y, width, height;
double old_x1, old_y1, old_x2, old_y2, old_width, old_height;
- GdkPixbuf *placeholder = g_object_get_data (G_OBJECT (view), "tile");
+ GdkPixbuf *placeholder = g_object_get_data (G_OBJECT (item), "tile");
x = MIN (coords [0], coords [2]) / scale;
y = MIN (coords [1], coords [3]) / scale;
width = fabs (coords [2] - coords [0]) / scale;
height = fabs (coords [3] - coords [1]) / scale;
- goc_item_get_bounds (view, &old_x1, &old_y1, &old_x2, &old_y2);
- goc_item_set (view,
+ goc_item_get_bounds (item, &old_x1, &old_y1, &old_x2, &old_y2);
+ goc_item_set (item,
"x", x, "y", y,
"width", width, "height", height,
NULL);
@@ -72,13 +72,13 @@ so_image_view_set_bounds (SheetObjectView *sov, double const *coords, gboolean v
(fabs (width - old_width) > 0.5 || fabs (height - old_height) > 0.5)) {
GdkPixbuf *newimage = go_gdk_pixbuf_tile (placeholder,
(guint)width, (guint)height);
- goc_item_set (view, "pixbuf", newimage, NULL);
+ goc_item_set (item, "pixbuf", newimage, NULL);
g_object_unref (newimage);
}
- goc_item_show (view);
+ goc_item_show (item);
} else
- goc_item_hide (view);
+ goc_item_hide (item);
}
static void
diff --git a/src/sheet-object-impl.h b/src/sheet-object-impl.h
index ab06616cb..1bcea0b89 100644
--- a/src/sheet-object-impl.h
+++ b/src/sheet-object-impl.h
@@ -133,6 +133,7 @@ SheetObject *sheet_object_view_get_so (SheetObjectView *sov);
void sheet_object_view_set_bounds (SheetObjectView *sov,
double const *coords,
gboolean visible);
+GocItem *sheet_object_view_get_item (SheetObjectView *sov);
/***************************************************************************/
diff --git a/src/sheet-object-widget.c b/src/sheet-object-widget.c
index 75df289d9..905b953dc 100644
--- a/src/sheet-object-widget.c
+++ b/src/sheet-object-widget.c
@@ -122,12 +122,8 @@ so_clear_sheet (SheetObject *so)
static GocWidget *
get_goc_widget (SheetObjectView *view)
{
- GocGroup *group = GOC_GROUP (view);
-
- if (group == NULL || group->children == NULL)
- return NULL;
-
- return GOC_WIDGET (group->children->data);
+ GocItem *item = sheet_object_view_get_item (view);
+ return item ? GOC_WIDGET (item) : NULL;
}
static void
@@ -156,8 +152,8 @@ so_widget_view_set_bounds (SheetObjectView *sov, double const *coords, gboolean
static GdkWindow *
so_widget_view_get_window (GocItem *item)
{
- GocGroup *group = GOC_GROUP (item);
- return goc_item_get_window (GOC_ITEM (group->children->data));
+ GocItem *item0 = sheet_object_view_get_item (GNM_SO_VIEW (item));
+ return goc_item_get_window (item0);
}
static void
diff --git a/src/sheet-object.c b/src/sheet-object.c
index 4d370d16e..5c07c46c7 100644
--- a/src/sheet-object.c
+++ b/src/sheet-object.c
@@ -1504,6 +1504,23 @@ sheet_object_view_set_bounds (SheetObjectView *sov,
(klass->set_bounds) (sov, coords, visible);
}
+/**
+ * sheet_object_view_get_item:
+ * @sov: #SheetObjectView
+ *
+ * Returns: (transfer none): the #GocItem implementing @sov
+ **/
+GocItem *
+sheet_object_view_get_item (SheetObjectView *sov)
+{
+ g_return_val_if_fail (GNM_IS_SO_VIEW (sov), NULL);
+
+ if (sov->base.children == NULL)
+ return NULL;
+ return GOC_ITEM (sov->base.children->data);
+}
+
+
/**
* sheet_object_view_get_so:
* @sov: #SheetObjectView
diff --git a/src/widgets/gnm-filter-combo-view.c b/src/widgets/gnm-filter-combo-view.c
index 6a201659b..87f3d1ade 100644
--- a/src/widgets/gnm-filter-combo-view.c
+++ b/src/widgets/gnm-filter-combo-view.c
@@ -333,7 +333,7 @@ filter_view_set_bounds (SheetObjectView *sov, double const *coords, gboolean vis
if (h > 20.) /* clip vertically */
h = 20.;
h /= scale;
- goc_item_set (GOC_ITEM (view->children->data),
+ goc_item_set (sheet_object_view_get_item (sov),
/* put it inside the cell */
"x", ((coords[2] >= 0.) ? (coords[2] / scale - h + 1) : coords[0] / scale),
"y", coords [3] / scale - h + 1.,
diff --git a/src/widgets/gnm-sheet-slicer-combo-view.c b/src/widgets/gnm-sheet-slicer-combo-view.c
index 70dfabbde..8ba43d1c0 100644
--- a/src/widgets/gnm-sheet-slicer-combo-view.c
+++ b/src/widgets/gnm-sheet-slicer-combo-view.c
@@ -166,7 +166,7 @@ sscombo_set_bounds (SheetObjectView *sov, double const *coords, gboolean visible
if (h > 20.) /* clip vertically */
h = 20.;
h /= scale;
- goc_item_set (GOC_ITEM (view->children->data),
+ goc_item_set (sheet_object_view_get_item (sov),
/* put it outside the cell */
"x", ((coords[2] >= 0.) ? coords[2] / scale : (coords[0] / scale - h + 1.)),
"y", coords [3] / scale - h + 1.,
diff --git a/src/widgets/gnm-validation-combo-view.c b/src/widgets/gnm-validation-combo-view.c
index ac16d0042..c02265b3f 100644
--- a/src/widgets/gnm-validation-combo-view.c
+++ b/src/widgets/gnm-validation-combo-view.c
@@ -189,7 +189,7 @@ vcombo_set_bounds (SheetObjectView *sov, double const *coords, gboolean visible)
if (h > 20.) /* clip vertically */
h = 20.;
h /= scale;
- goc_item_set (GOC_ITEM (view->children->data),
+ goc_item_set (sheet_object_view_get_item (sov),
/* put it outside the cell */
"x", ((coords[2] >= 0.)? coords[2] / scale: (coords[0] / scale - h + 1.)),
"y", coords [3] / scale - h + 1.,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]