Commit 6e4f42f9 authored by Benjamin Otte's avatar Benjamin Otte

cssnode: Change API of some functions

gtk_css_node_set_after/before() are now called
gtk_css_node_insert_after/before().

This brings them in line with other similar APIs (ie GtkListStore). And
it allows easier usage of the API (see changes to gtkbox.c).
parent 79f2400c
......@@ -1434,43 +1434,40 @@ gtk_box_buildable_init (GtkBuildableIface *iface)
iface->add_child = gtk_box_buildable_add_child;
}
static void
gtk_box_invalidate_order_foreach (GtkWidget *widget,
gpointer prev)
{
GtkCssNode **previous = prev;
GtkCssNode *cur = gtk_widget_get_css_node (widget);
if (*previous)
gtk_css_node_set_after (cur, *previous);
*previous = cur;
}
typedef struct {
GtkCssNode *parent;
GtkCssNode *previous;
gboolean reverse;
} InvalidateOrderData;
static void
gtk_box_invalidate_order_foreach_reverse (GtkWidget *widget,
gpointer prev)
gtk_box_invalidate_order_foreach (GtkWidget *widget,
gpointer datap)
{
GtkCssNode **previous = prev;
InvalidateOrderData *data = datap;
GtkCssNode *cur = gtk_widget_get_css_node (widget);
if (*previous)
gtk_css_node_set_before (cur, *previous);
if (data->reverse)
gtk_css_node_insert_before (data->parent, cur, data->previous);
else
gtk_css_node_insert_after (data->parent, cur, data->previous);
*previous = cur;
data->previous = cur;
}
static void
gtk_box_invalidate_order (GtkBox *box)
{
GtkCssNode *previous = NULL;
InvalidateOrderData data;
data.parent = gtk_widget_get_css_node (GTK_WIDGET (box));
data.previous = NULL;
data.reverse = box->priv->orientation == GTK_ORIENTATION_HORIZONTAL
&& gtk_widget_get_direction (GTK_WIDGET (box)) == GTK_TEXT_DIR_RTL;
gtk_container_foreach (GTK_CONTAINER (box),
(box->priv->orientation == GTK_ORIENTATION_HORIZONTAL
&& gtk_widget_get_direction (GTK_WIDGET (box)) == GTK_TEXT_DIR_RTL)
? gtk_box_invalidate_order_foreach_reverse
: gtk_box_invalidate_order_foreach,
&previous);
gtk_box_invalidate_order_foreach,
&data);
}
static void
......
......@@ -741,27 +741,35 @@ gtk_css_node_set_parent (GtkCssNode *node,
}
void
gtk_css_node_set_after (GtkCssNode *cssnode,
GtkCssNode *previous_sibling)
gtk_css_node_insert_after (GtkCssNode *parent,
GtkCssNode *cssnode,
GtkCssNode *previous_sibling)
{
if (cssnode->previous_sibling == previous_sibling)
g_return_if_fail (previous_sibling == NULL || previous_sibling->parent == parent);
if (cssnode->previous_sibling == previous_sibling &&
cssnode->parent == parent)
return;
gtk_css_node_reposition (cssnode,
previous_sibling->parent,
parent,
previous_sibling);
}
void
gtk_css_node_set_before (GtkCssNode *cssnode,
GtkCssNode *next_sibling)
gtk_css_node_insert_before (GtkCssNode *parent,
GtkCssNode *cssnode,
GtkCssNode *next_sibling)
{
if (cssnode->next_sibling == next_sibling)
g_return_if_fail (next_sibling == NULL || next_sibling->parent == parent);
if (cssnode->next_sibling == next_sibling &&
cssnode->parent == parent)
return;
gtk_css_node_reposition (cssnode,
next_sibling->parent,
next_sibling->previous_sibling);
parent,
next_sibling ? next_sibling->previous_sibling : parent->last_child);
}
GtkCssNode *
......
......@@ -95,9 +95,11 @@ GType gtk_css_node_get_type (void) G_GNUC_CONST;
void gtk_css_node_set_parent (GtkCssNode *cssnode,
GtkCssNode *parent);
void gtk_css_node_set_after (GtkCssNode *cssnode,
void gtk_css_node_insert_after (GtkCssNode *parent,
GtkCssNode *cssnode,
GtkCssNode *previous_sibling);
void gtk_css_node_set_before (GtkCssNode *cssnode,
void gtk_css_node_insert_before (GtkCssNode *parent,
GtkCssNode *cssnode,
GtkCssNode *next_sibling);
GtkCssNode * gtk_css_node_get_parent (GtkCssNode *cssnode);
GtkCssNode * gtk_css_node_get_first_child (GtkCssNode *cssnode);
......
......@@ -4013,18 +4013,16 @@ gtk_flow_box_insert_css_node (GtkFlowBox *box,
GSequenceIter *iter)
{
GSequenceIter *prev_iter;
GtkCssNode *child_node;
GtkCssNode *sibling_node;
GtkWidget *sibling;
child_node = gtk_widget_get_css_node (child);
prev_iter = g_sequence_iter_prev (iter);
if (prev_iter != iter)
{
sibling = g_sequence_get (prev_iter);
sibling_node = gtk_widget_get_css_node (sibling);
gtk_css_node_set_after (child_node, sibling_node);
gtk_css_node_insert_after (gtk_widget_get_css_node (GTK_WIDGET (box)),
gtk_widget_get_css_node (child),
gtk_widget_get_css_node (sibling));
}
}
......@@ -4843,7 +4841,9 @@ gtk_flow_box_css_node_foreach (gpointer data,
{
prev_node = gtk_widget_get_css_node (*previous);
row_node = gtk_widget_get_css_node (row);
gtk_css_node_set_after (row_node, prev_node);
gtk_css_node_insert_after (gtk_css_node_get_parent (row_node),
row_node,
prev_node);
}
*previous = row;
......
......@@ -1180,7 +1180,9 @@ gtk_list_box_css_node_foreach (gpointer data,
{
prev_node = gtk_widget_get_css_node (*previous);
row_node = gtk_widget_get_css_node (row);
gtk_css_node_set_after (row_node, prev_node);
gtk_css_node_insert_after (gtk_css_node_get_parent (row_node),
row_node,
prev_node);
}
*previous = row;
......@@ -2626,18 +2628,16 @@ gtk_list_box_insert_css_node (GtkListBox *box,
GSequenceIter *iter)
{
GSequenceIter *prev_iter;
GtkCssNode *child_node;
GtkCssNode *sibling_node;
GtkWidget *sibling;
child_node = gtk_widget_get_css_node (child);
prev_iter = g_sequence_iter_prev (iter);
if (prev_iter != iter)
{
sibling = g_sequence_get (prev_iter);
sibling_node = gtk_widget_get_css_node (sibling);
gtk_css_node_set_after (child_node, sibling_node);
gtk_css_node_insert_after (gtk_widget_get_css_node (GTK_WIDGET (box)),
gtk_widget_get_css_node (child),
gtk_widget_get_css_node (sibling));
}
}
......
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