grid: Drop priv pointer

This commit is contained in:
Timm Bäder 2017-10-08 10:40:48 +02:00
parent a4deb7e7b4
commit b994cac6dd
2 changed files with 46 additions and 78 deletions

View File

@ -114,6 +114,7 @@ struct _GtkGridPrivate
GtkGridLineData linedata[2]; GtkGridLineData linedata[2];
}; };
typedef struct _GtkGridPrivate GtkGridPrivate;
#define ROWS(priv) (&(priv)->linedata[GTK_ORIENTATION_HORIZONTAL]) #define ROWS(priv) (&(priv)->linedata[GTK_ORIENTATION_HORIZONTAL])
#define COLUMNS(priv) (&(priv)->linedata[GTK_ORIENTATION_VERTICAL]) #define COLUMNS(priv) (&(priv)->linedata[GTK_ORIENTATION_VERTICAL])
@ -192,7 +193,7 @@ gtk_grid_get_property (GObject *object,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GtkGrid *grid = GTK_GRID (object); GtkGrid *grid = GTK_GRID (object);
GtkGridPrivate *priv = grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
switch (prop_id) switch (prop_id)
{ {
@ -230,7 +231,7 @@ static void
gtk_grid_set_orientation (GtkGrid *grid, gtk_grid_set_orientation (GtkGrid *grid,
GtkOrientation orientation) GtkOrientation orientation)
{ {
GtkGridPrivate *priv = grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
if (priv->orientation != orientation) if (priv->orientation != orientation)
{ {
@ -285,7 +286,7 @@ static GtkGridChild *
find_grid_child (GtkGrid *grid, find_grid_child (GtkGrid *grid,
GtkWidget *widget) GtkWidget *widget)
{ {
GtkGridPrivate *priv = grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
GtkGridChild *child; GtkGridChild *child;
GList *list; GList *list;
@ -392,7 +393,7 @@ static void
gtk_grid_finalize (GObject *object) gtk_grid_finalize (GObject *object)
{ {
GtkGrid *grid = GTK_GRID (object); GtkGrid *grid = GTK_GRID (object);
GtkGridPrivate *priv = grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
g_list_free_full (priv->row_properties, (GDestroyNotify)gtk_grid_row_properties_free); g_list_free_full (priv->row_properties, (GDestroyNotify)gtk_grid_row_properties_free);
@ -407,7 +408,7 @@ grid_attach (GtkGrid *grid,
gint width, gint width,
gint height) gint height)
{ {
GtkGridPrivate *priv = grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
GtkGridChild *child; GtkGridChild *child;
child = g_slice_new (GtkGridChild); child = g_slice_new (GtkGridChild);
@ -436,7 +437,7 @@ find_attach_position (GtkGrid *grid,
gint op_span, gint op_span,
gboolean max) gboolean max)
{ {
GtkGridPrivate *priv = grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
GtkGridChild *grid_child; GtkGridChild *grid_child;
GtkGridChildAttach *attach; GtkGridChildAttach *attach;
GtkGridChildAttach *opposite; GtkGridChildAttach *opposite;
@ -481,7 +482,7 @@ gtk_grid_add (GtkContainer *container,
GtkWidget *child) GtkWidget *child)
{ {
GtkGrid *grid = GTK_GRID (container); GtkGrid *grid = GTK_GRID (container);
GtkGridPrivate *priv = grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
gint pos[2] = { 0, 0 }; gint pos[2] = { 0, 0 };
pos[priv->orientation] = find_attach_position (grid, priv->orientation, 0, 1, TRUE); pos[priv->orientation] = find_attach_position (grid, priv->orientation, 0, 1, TRUE);
@ -493,7 +494,7 @@ gtk_grid_remove (GtkContainer *container,
GtkWidget *child) GtkWidget *child)
{ {
GtkGrid *grid = GTK_GRID (container); GtkGrid *grid = GTK_GRID (container);
GtkGridPrivate *priv = grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
GtkGridChild *grid_child; GtkGridChild *grid_child;
GList *list; GList *list;
@ -525,7 +526,7 @@ gtk_grid_forall (GtkContainer *container,
gpointer callback_data) gpointer callback_data)
{ {
GtkGrid *grid = GTK_GRID (container); GtkGrid *grid = GTK_GRID (container);
GtkGridPrivate *priv = grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
GtkGridChild *child; GtkGridChild *child;
GList *list; GList *list;
@ -549,7 +550,7 @@ static int
get_spacing (GtkGrid *grid, get_spacing (GtkGrid *grid,
GtkOrientation orientation) GtkOrientation orientation)
{ {
GtkGridPrivate *priv = grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
GtkCssValue *border_spacing; GtkCssValue *border_spacing;
gint css_spacing; gint css_spacing;
@ -567,7 +568,7 @@ get_spacing (GtkGrid *grid,
static void static void
gtk_grid_request_count_lines (GtkGridRequest *request) gtk_grid_request_count_lines (GtkGridRequest *request)
{ {
GtkGridPrivate *priv = request->grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (request->grid);
GtkGridChild *child; GtkGridChild *child;
GtkGridChildAttach *attach; GtkGridChildAttach *attach;
GList *list; GList *list;
@ -601,7 +602,7 @@ static void
gtk_grid_request_init (GtkGridRequest *request, gtk_grid_request_init (GtkGridRequest *request,
GtkOrientation orientation) GtkOrientation orientation)
{ {
GtkGridPrivate *priv = request->grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (request->grid);
GtkGridChild *child; GtkGridChild *child;
GtkGridChildAttach *attach; GtkGridChildAttach *attach;
GtkGridLines *lines; GtkGridLines *lines;
@ -704,7 +705,7 @@ gtk_grid_request_non_spanning (GtkGridRequest *request,
GtkOrientation orientation, GtkOrientation orientation,
gboolean contextual) gboolean contextual)
{ {
GtkGridPrivate *priv = request->grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (request->grid);
GtkGridChild *child; GtkGridChild *child;
GtkGridChildAttach *attach; GtkGridChildAttach *attach;
GtkGridLines *lines; GtkGridLines *lines;
@ -790,7 +791,7 @@ static void
gtk_grid_request_homogeneous (GtkGridRequest *request, gtk_grid_request_homogeneous (GtkGridRequest *request,
GtkOrientation orientation) GtkOrientation orientation)
{ {
GtkGridPrivate *priv = request->grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (request->grid);
GtkGridLineData *linedata; GtkGridLineData *linedata;
GtkGridLines *lines; GtkGridLines *lines;
gint minimum, natural; gint minimum, natural;
@ -830,7 +831,7 @@ gtk_grid_request_spanning (GtkGridRequest *request,
GtkOrientation orientation, GtkOrientation orientation,
gboolean contextual) gboolean contextual)
{ {
GtkGridPrivate *priv = request->grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (request->grid);
GList *list; GList *list;
GtkGridChild *child; GtkGridChild *child;
GtkGridChildAttach *attach; GtkGridChildAttach *attach;
@ -970,7 +971,7 @@ gtk_grid_request_compute_expand (GtkGridRequest *request,
gint *nonempty_lines, gint *nonempty_lines,
gint *expand_lines) gint *expand_lines)
{ {
GtkGridPrivate *priv = request->grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (request->grid);
GtkGridChild *child; GtkGridChild *child;
GtkGridChildAttach *attach; GtkGridChildAttach *attach;
GList *list; GList *list;
@ -1084,7 +1085,7 @@ gtk_grid_request_sum (GtkGridRequest *request,
gint *minimum_baseline, gint *minimum_baseline,
gint *natural_baseline) gint *natural_baseline)
{ {
GtkGridPrivate *priv = request->grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (request->grid);
GtkGridLines *lines; GtkGridLines *lines;
gint i; gint i;
gint min, nat; gint min, nat;
@ -1227,7 +1228,7 @@ gtk_grid_request_allocate (GtkGridRequest *request,
GtkOrientation orientation, GtkOrientation orientation,
gint total_size) gint total_size)
{ {
GtkGridPrivate *priv = request->grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (request->grid);
GtkGridLineData *linedata; GtkGridLineData *linedata;
GtkGridLines *lines; GtkGridLines *lines;
GtkGridLine *line; GtkGridLine *line;
@ -1374,7 +1375,7 @@ static void
gtk_grid_request_position (GtkGridRequest *request, gtk_grid_request_position (GtkGridRequest *request,
GtkOrientation orientation) GtkOrientation orientation)
{ {
GtkGridPrivate *priv = request->grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (request->grid);
GtkGridLines *lines; GtkGridLines *lines;
GtkGridLine *line; GtkGridLine *line;
gint position, old_position; gint position, old_position;
@ -1430,6 +1431,7 @@ gtk_grid_get_size (GtkGrid *grid,
gint *minimum_baseline, gint *minimum_baseline,
gint *natural_baseline) gint *natural_baseline)
{ {
GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
GtkGridRequest request; GtkGridRequest request;
GtkGridLines *lines; GtkGridLines *lines;
@ -1442,7 +1444,7 @@ gtk_grid_get_size (GtkGrid *grid,
if (natural_baseline) if (natural_baseline)
*natural_baseline = -1; *natural_baseline = -1;
if (grid->priv->children == NULL) if (priv->children == NULL)
return; return;
request.grid = grid; request.grid = grid;
@ -1465,6 +1467,7 @@ gtk_grid_get_size_for_size (GtkGrid *grid,
gint *minimum_baseline, gint *minimum_baseline,
gint *natural_baseline) gint *natural_baseline)
{ {
GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
GtkGridRequest request; GtkGridRequest request;
GtkGridLines *lines; GtkGridLines *lines;
gint min_size, nat_size; gint min_size, nat_size;
@ -1478,7 +1481,7 @@ gtk_grid_get_size_for_size (GtkGrid *grid,
if (natural_baseline) if (natural_baseline)
*natural_baseline = -1; *natural_baseline = -1;
if (grid->priv->children == NULL) if (priv->children == NULL)
return; return;
request.grid = grid; request.grid = grid;
@ -1553,7 +1556,7 @@ gtk_grid_request_allocate_children (GtkGridRequest *request,
const GtkAllocation *allocation, const GtkAllocation *allocation,
GtkAllocation *out_clip) GtkAllocation *out_clip)
{ {
GtkGridPrivate *priv = request->grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (request->grid);
GList *list; GList *list;
GtkGridChild *child; GtkGridChild *child;
GtkAllocation child_allocation; GtkAllocation child_allocation;
@ -1593,7 +1596,7 @@ gtk_grid_size_allocate (GtkWidget *widget,
GtkAllocation *out_clip) GtkAllocation *out_clip)
{ {
GtkGrid *grid = GTK_GRID (widget); GtkGrid *grid = GTK_GRID (widget);
GtkGridPrivate *priv = grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
GtkGridRequest request; GtkGridRequest request;
GtkGridLines *lines; GtkGridLines *lines;
GtkOrientation orientation; GtkOrientation orientation;
@ -1725,10 +1728,7 @@ gtk_grid_class_init (GtkGridClass *class)
static void static void
gtk_grid_init (GtkGrid *grid) gtk_grid_init (GtkGrid *grid)
{ {
GtkGridPrivate *priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
grid->priv = gtk_grid_get_instance_private (grid);
priv = grid->priv;
gtk_widget_set_has_window (GTK_WIDGET (grid), FALSE); gtk_widget_set_has_window (GTK_WIDGET (grid), FALSE);
@ -1902,14 +1902,12 @@ gtk_grid_get_child_at (GtkGrid *grid,
gint left, gint left,
gint top) gint top)
{ {
GtkGridPrivate *priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
GtkGridChild *child; GtkGridChild *child;
GList *list; GList *list;
g_return_val_if_fail (GTK_IS_GRID (grid), NULL); g_return_val_if_fail (GTK_IS_GRID (grid), NULL);
priv = grid->priv;
for (list = priv->children; list; list = list->next) for (list = priv->children; list; list = list->next)
{ {
child = list->data; child = list->data;
@ -1941,15 +1939,13 @@ void
gtk_grid_insert_row (GtkGrid *grid, gtk_grid_insert_row (GtkGrid *grid,
gint position) gint position)
{ {
GtkGridPrivate *priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
GtkGridChild *child; GtkGridChild *child;
GList *list; GList *list;
gint top, height; gint top, height;
g_return_if_fail (GTK_IS_GRID (grid)); g_return_if_fail (GTK_IS_GRID (grid));
priv = grid->priv;
for (list = priv->children; list; list = list->next) for (list = priv->children; list; list = list->next)
{ {
child = list->data; child = list->data;
@ -2000,15 +1996,13 @@ void
gtk_grid_remove_row (GtkGrid *grid, gtk_grid_remove_row (GtkGrid *grid,
gint position) gint position)
{ {
GtkGridPrivate *priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
GtkGridChild *child; GtkGridChild *child;
GList *list; GList *list;
gint top, height; gint top, height;
g_return_if_fail (GTK_IS_GRID (grid)); g_return_if_fail (GTK_IS_GRID (grid));
priv = grid->priv;
list = priv->children; list = priv->children;
while (list) while (list)
{ {
@ -2050,15 +2044,13 @@ void
gtk_grid_insert_column (GtkGrid *grid, gtk_grid_insert_column (GtkGrid *grid,
gint position) gint position)
{ {
GtkGridPrivate *priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
GtkGridChild *child; GtkGridChild *child;
GList *list; GList *list;
gint left, width; gint left, width;
g_return_if_fail (GTK_IS_GRID (grid)); g_return_if_fail (GTK_IS_GRID (grid));
priv = grid->priv;
for (list = priv->children; list; list = list->next) for (list = priv->children; list; list = list->next)
{ {
child = list->data; child = list->data;
@ -2101,15 +2093,13 @@ void
gtk_grid_remove_column (GtkGrid *grid, gtk_grid_remove_column (GtkGrid *grid,
gint position) gint position)
{ {
GtkGridPrivate *priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
GtkGridChild *child; GtkGridChild *child;
GList *list; GList *list;
gint left, width; gint left, width;
g_return_if_fail (GTK_IS_GRID (grid)); g_return_if_fail (GTK_IS_GRID (grid));
priv = grid->priv;
list = priv->children; list = priv->children;
while (list) while (list)
{ {
@ -2193,11 +2183,9 @@ void
gtk_grid_set_row_homogeneous (GtkGrid *grid, gtk_grid_set_row_homogeneous (GtkGrid *grid,
gboolean homogeneous) gboolean homogeneous)
{ {
GtkGridPrivate *priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
g_return_if_fail (GTK_IS_GRID (grid)); g_return_if_fail (GTK_IS_GRID (grid));
priv = grid->priv;
/* Yes, homogeneous rows means all the columns have the same size */ /* Yes, homogeneous rows means all the columns have the same size */
if (COLUMNS (priv)->homogeneous != homogeneous) if (COLUMNS (priv)->homogeneous != homogeneous)
{ {
@ -2221,11 +2209,9 @@ gtk_grid_set_row_homogeneous (GtkGrid *grid,
gboolean gboolean
gtk_grid_get_row_homogeneous (GtkGrid *grid) gtk_grid_get_row_homogeneous (GtkGrid *grid)
{ {
GtkGridPrivate *priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
g_return_val_if_fail (GTK_IS_GRID (grid), FALSE); g_return_val_if_fail (GTK_IS_GRID (grid), FALSE);
priv = grid->priv;
return COLUMNS (priv)->homogeneous; return COLUMNS (priv)->homogeneous;
} }
@ -2240,11 +2226,9 @@ void
gtk_grid_set_column_homogeneous (GtkGrid *grid, gtk_grid_set_column_homogeneous (GtkGrid *grid,
gboolean homogeneous) gboolean homogeneous)
{ {
GtkGridPrivate *priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
g_return_if_fail (GTK_IS_GRID (grid)); g_return_if_fail (GTK_IS_GRID (grid));
priv = grid->priv;
/* Yes, homogeneous columns means all the rows have the same size */ /* Yes, homogeneous columns means all the rows have the same size */
if (ROWS (priv)->homogeneous != homogeneous) if (ROWS (priv)->homogeneous != homogeneous)
{ {
@ -2268,11 +2252,9 @@ gtk_grid_set_column_homogeneous (GtkGrid *grid,
gboolean gboolean
gtk_grid_get_column_homogeneous (GtkGrid *grid) gtk_grid_get_column_homogeneous (GtkGrid *grid)
{ {
GtkGridPrivate *priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
g_return_val_if_fail (GTK_IS_GRID (grid), FALSE); g_return_val_if_fail (GTK_IS_GRID (grid), FALSE);
priv = grid->priv;
return ROWS (priv)->homogeneous; return ROWS (priv)->homogeneous;
} }
@ -2287,12 +2269,10 @@ void
gtk_grid_set_row_spacing (GtkGrid *grid, gtk_grid_set_row_spacing (GtkGrid *grid,
guint spacing) guint spacing)
{ {
GtkGridPrivate *priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
g_return_if_fail (GTK_IS_GRID (grid)); g_return_if_fail (GTK_IS_GRID (grid));
g_return_if_fail (spacing <= G_MAXINT16); g_return_if_fail (spacing <= G_MAXINT16);
priv = grid->priv;
if (COLUMNS (priv)->spacing != spacing) if (COLUMNS (priv)->spacing != spacing)
{ {
COLUMNS (priv)->spacing = spacing; COLUMNS (priv)->spacing = spacing;
@ -2315,11 +2295,9 @@ gtk_grid_set_row_spacing (GtkGrid *grid,
guint guint
gtk_grid_get_row_spacing (GtkGrid *grid) gtk_grid_get_row_spacing (GtkGrid *grid)
{ {
GtkGridPrivate *priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
g_return_val_if_fail (GTK_IS_GRID (grid), 0); g_return_val_if_fail (GTK_IS_GRID (grid), 0);
priv = grid->priv;
return COLUMNS (priv)->spacing; return COLUMNS (priv)->spacing;
} }
@ -2334,12 +2312,10 @@ void
gtk_grid_set_column_spacing (GtkGrid *grid, gtk_grid_set_column_spacing (GtkGrid *grid,
guint spacing) guint spacing)
{ {
GtkGridPrivate *priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
g_return_if_fail (GTK_IS_GRID (grid)); g_return_if_fail (GTK_IS_GRID (grid));
g_return_if_fail (spacing <= G_MAXINT16); g_return_if_fail (spacing <= G_MAXINT16);
priv = grid->priv;
if (ROWS (priv)->spacing != spacing) if (ROWS (priv)->spacing != spacing)
{ {
ROWS (priv)->spacing = spacing; ROWS (priv)->spacing = spacing;
@ -2362,12 +2338,10 @@ gtk_grid_set_column_spacing (GtkGrid *grid,
guint guint
gtk_grid_get_column_spacing (GtkGrid *grid) gtk_grid_get_column_spacing (GtkGrid *grid)
{ {
GtkGridPrivate *priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
g_return_val_if_fail (GTK_IS_GRID (grid), 0); g_return_val_if_fail (GTK_IS_GRID (grid), 0);
priv = grid->priv;
return ROWS (priv)->spacing; return ROWS (priv)->spacing;
} }
@ -2375,9 +2349,10 @@ static GtkGridRowProperties *
find_row_properties (GtkGrid *grid, find_row_properties (GtkGrid *grid,
gint row) gint row)
{ {
GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
GList *l; GList *l;
for (l = grid->priv->row_properties; l != NULL; l = l->next) for (l = priv->row_properties; l != NULL; l = l->next)
{ {
GtkGridRowProperties *prop = l->data; GtkGridRowProperties *prop = l->data;
if (prop->row == row) if (prop->row == row)
@ -2398,7 +2373,7 @@ get_row_properties_or_create (GtkGrid *grid,
gint row) gint row)
{ {
GtkGridRowProperties *props; GtkGridRowProperties *props;
GtkGridPrivate *priv = grid->priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
props = find_row_properties (grid, row); props = find_row_properties (grid, row);
if (props) if (props)
@ -2499,12 +2474,10 @@ void
gtk_grid_set_baseline_row (GtkGrid *grid, gtk_grid_set_baseline_row (GtkGrid *grid,
gint row) gint row)
{ {
GtkGridPrivate *priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
g_return_if_fail (GTK_IS_GRID (grid)); g_return_if_fail (GTK_IS_GRID (grid));
priv = grid->priv;
if (priv->baseline_row != row) if (priv->baseline_row != row)
{ {
priv->baseline_row = row; priv->baseline_row = row;
@ -2528,11 +2501,9 @@ gtk_grid_set_baseline_row (GtkGrid *grid,
gint gint
gtk_grid_get_baseline_row (GtkGrid *grid) gtk_grid_get_baseline_row (GtkGrid *grid)
{ {
GtkGridPrivate *priv; GtkGridPrivate *priv = gtk_grid_get_instance_private (grid);
g_return_val_if_fail (GTK_IS_GRID (grid), 0); g_return_val_if_fail (GTK_IS_GRID (grid), 0);
priv = grid->priv;
return priv->baseline_row; return priv->baseline_row;
} }

View File

@ -38,15 +38,12 @@ G_BEGIN_DECLS
typedef struct _GtkGrid GtkGrid; typedef struct _GtkGrid GtkGrid;
typedef struct _GtkGridPrivate GtkGridPrivate;
typedef struct _GtkGridClass GtkGridClass; typedef struct _GtkGridClass GtkGridClass;
struct _GtkGrid struct _GtkGrid
{ {
/*< private >*/ /*< private >*/
GtkContainer container; GtkContainer parent_instance;
GtkGridPrivate *priv;
}; };
/** /**