diff --git a/gtk/tools/gtk-builder-tool-simplify.c b/gtk/tools/gtk-builder-tool-simplify.c
index 92a126ca33..fdac7a93c0 100644
--- a/gtk/tools/gtk-builder-tool-simplify.c
+++ b/gtk/tools/gtk-builder-tool-simplify.c
@@ -1514,6 +1514,160 @@ rewrite_grid_layout (Element *element,
}
}
+
+static Element *
+write_box_prop (Element *element,
+ Element *parent,
+ const char *name,
+ const char *value)
+{
+
+ if (element)
+ g_free (element->data);
+ else
+ {
+ element = g_new0 (Element, 1);
+ element->parent = parent;
+ element->element_name = g_strdup ("property");
+ element->attribute_names = g_new0 (char *, 2);
+ element->attribute_names[0] = g_strdup ("name");
+ element->attribute_values = g_new0 (char *, 2);
+ element->attribute_values[0] = g_strdup (name);
+ parent->children = g_list_prepend (parent->children, element);
+ }
+ element->data = g_strdup (value);
+ return element;
+}
+
+static void
+rewrite_box (Element *element,
+ MyParserData *data)
+{
+ GList *l, *ll;
+ GtkOrientation orientation = GTK_ORIENTATION_HORIZONTAL;
+
+ if (g_str_equal (get_class_name (element), "GtkVBox"))
+ write_box_prop (NULL, element, "orientation", "vertical");
+
+ if (!g_str_equal (get_class_name (element), "GtkBox"))
+ set_attribute_value (element, "class", "GtkBox");
+
+ for (l = element->children; l; l = l->next)
+ {
+ Element *child = l->data;
+
+ if (g_str_equal (child->element_name, "property"))
+ {
+ if (has_attribute (child, "name", "orientation"))
+ {
+ GValue value = G_VALUE_INIT;
+
+ if (gtk_builder_value_from_string_type (data->builder,
+ GTK_TYPE_ORIENTATION,
+ child->data,
+ &value,
+ NULL))
+ orientation = g_value_get_enum (&value);
+ }
+ }
+ }
+
+ for (l = element->children; l; l = l->next)
+ {
+ Element *child = l->data;
+ if (g_str_equal (child->element_name, "child"))
+ {
+ Element *object = NULL;
+ Element *packing = NULL;
+
+ for (ll = child->children; ll; ll = ll->next)
+ {
+ Element *elt2 = ll->data;
+
+ if (g_str_equal (elt2->element_name, "object"))
+ object = elt2;
+
+ if (g_str_equal (elt2->element_name, "packing"))
+ packing = elt2;
+ }
+
+ if (object && packing)
+ {
+ Element *halign = NULL;
+ Element *hexpand = NULL;
+ Element *valign = NULL;
+ Element *vexpand = NULL;
+
+ gboolean expand = FALSE;
+ gboolean fill = TRUE;
+
+ for (ll = object->children; ll; ll = ll->next)
+ {
+ Element *elt = ll->data;
+ if (g_str_equal (elt->element_name, "property"))
+ {
+ if (has_attribute (elt, "name", "halign"))
+ halign = elt;
+ else if (has_attribute (elt, "name", "hexpand"))
+ hexpand = elt;
+ else if (has_attribute (elt, "name", "valign"))
+ valign = elt;
+ else if (has_attribute (elt, "name", "vexpand"))
+ vexpand = elt;
+ }
+ }
+
+ for (ll = packing->children; ll; ll = ll->next)
+ {
+ Element *elt = ll->data;
+
+ if (has_attribute (elt, "name", "expand"))
+ {
+ GValue value = G_VALUE_INIT;
+
+ if (gtk_builder_value_from_string_type (data->builder,
+ G_TYPE_BOOLEAN,
+ elt->data,
+ &value,
+ NULL))
+ expand = g_value_get_boolean (&value);
+ }
+
+ if (has_attribute (elt, "name", "fill"))
+ {
+ GValue value = G_VALUE_INIT;
+
+ if (gtk_builder_value_from_string_type (data->builder,
+ G_TYPE_BOOLEAN,
+ elt->data,
+ &value,
+ NULL))
+ fill = g_value_get_boolean (&value);
+ }
+ }
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ if (expand)
+ hexpand = write_box_prop (hexpand, object, "hexpand", "1");
+ if (!fill)
+ halign = write_box_prop (halign, object, "halign", "center");
+ }
+ else if (orientation == GTK_ORIENTATION_VERTICAL)
+ {
+ if (expand)
+ vexpand = write_box_prop (vexpand, object, "vexpand", "1");
+ if (!fill)
+ valign = write_box_prop (valign, object, "valign", "center");
+ }
+
+ child->children = g_list_remove (child->children, packing);
+ free_element (packing);
+ }
+ }
+ }
+}
+
static void
rewrite_bin_child (Element *element,
MyParserData *data)
@@ -1682,6 +1836,12 @@ rewrite_element (Element *element,
g_str_equal (get_class_name (element), "GtkGrid"))
rewrite_grid_layout (element, data);
+ if (element_is_object_or_template (element) &&
+ (g_str_equal (get_class_name (element), "GtkHBox") ||
+ g_str_equal (get_class_name (element), "GtkVBox") ||
+ g_str_equal (get_class_name (element), "GtkBox")))
+ rewrite_box (element, data);
+
if (element_is_object_or_template (element) &&
g_str_equal (get_class_name (element), "GtkFixed"))
rewrite_layout_props (element, data);
diff --git a/testsuite/tools/simplify-data-3to4/box.expected b/testsuite/tools/simplify-data-3to4/box.expected
new file mode 100644
index 0000000000..9f62a3b09e
--- /dev/null
+++ b/testsuite/tools/simplify-data-3to4/box.expected
@@ -0,0 +1,614 @@
+
+
+
+
+
diff --git a/testsuite/tools/simplify-data-3to4/box.ui b/testsuite/tools/simplify-data-3to4/box.ui
new file mode 100644
index 0000000000..fad61969e8
--- /dev/null
+++ b/testsuite/tools/simplify-data-3to4/box.ui
@@ -0,0 +1,1131 @@
+
+
+
+
+
+
+
+ True
+ False
+
+
+ True
+ False
+ vertical
+
+
+ True
+ False
+ center
+ True
+ False
+
+
+ _
+ True
+ True
+ True
+
+
+ False
+ False
+ 0
+
+
+
+
+ F
+ True
+ True
+ True
+
+
+ False
+ True
+ 1
+
+
+
+
+ E
+ True
+ True
+ True
+
+
+ True
+ False
+ 2
+
+
+
+
+ FE
+ True
+ True
+ True
+
+
+ True
+ True
+ 3
+
+
+
+
+ False
+ True
+ 0
+
+
+
+
+ True
+ False
+ center
+ True
+ False
+
+
+ _
+ True
+ True
+ True
+
+
+ False
+ False
+ 0
+
+
+
+
+ F
+ True
+ True
+ True
+
+
+ False
+ True
+ 1
+
+
+
+
+ E
+ True
+ True
+ True
+
+
+ True
+ False
+ 2
+
+
+
+
+ FE
+ True
+ True
+ True
+
+
+ True
+ True
+ 3
+
+
+
+
+ False
+ True
+ 1
+
+
+
+
+ True
+ True
+ 0
+
+
+
+
+ True
+ False
+ True
+
+
+ _
+ True
+ True
+ True
+
+
+ False
+ False
+ 0
+
+
+
+
+ F
+ True
+ True
+ True
+
+
+ False
+ True
+ 1
+
+
+
+
+ E
+ True
+ True
+ True
+
+
+ True
+ False
+ 2
+
+
+
+
+ FE
+ True
+ True
+ True
+
+
+ True
+ True
+ 3
+
+
+
+
+ False
+ False
+ 1
+
+
+
+
+ True
+ False
+ False
+ True
+ vertical
+
+
+ _I
+ True
+ True
+ True
+
+
+ False
+ False
+ 0
+
+
+
+
+ FI
+ True
+ True
+ True
+
+
+ False
+ True
+ 1
+
+
+
+
+ EI
+ True
+ True
+ True
+
+
+ True
+ False
+ 2
+
+
+
+
+ FEI
+ True
+ True
+ True
+
+
+ True
+ True
+ 3
+
+
+
+
+ _S
+ True
+ True
+ True
+ start
+
+
+ False
+ False
+ 4
+
+
+
+
+ FS
+ True
+ True
+ True
+ start
+
+
+ False
+ True
+ 5
+
+
+
+
+ ES
+ True
+ True
+ True
+ start
+
+
+ True
+ False
+ 6
+
+
+
+
+ FES
+ True
+ True
+ True
+ start
+
+
+ True
+ True
+ 7
+
+
+
+
+ _N
+ True
+ True
+ True
+ end
+
+
+ False
+ False
+ 8
+
+
+
+
+ FN
+ True
+ True
+ True
+ end
+
+
+ False
+ True
+ 9
+
+
+
+
+ EN
+ True
+ True
+ True
+ end
+
+
+ True
+ False
+ 10
+
+
+
+
+ FEN
+ True
+ True
+ True
+ end
+
+
+ True
+ True
+ 11
+
+
+
+
+ _C
+ True
+ True
+ True
+ center
+
+
+ False
+ False
+ 12
+
+
+
+
+ FC
+ True
+ True
+ True
+ center
+
+
+ False
+ True
+ 13
+
+
+
+
+ EC
+ True
+ True
+ True
+ center
+
+
+ True
+ False
+ 14
+
+
+
+
+ FEC
+ True
+ True
+ True
+ center
+
+
+ True
+ True
+ 15
+
+
+
+
+ _B
+ True
+ True
+ True
+ baseline
+
+
+ False
+ False
+ 16
+
+
+
+
+ FB
+ True
+ True
+ True
+ baseline
+
+
+ False
+ True
+ 17
+
+
+
+
+ EB
+ True
+ True
+ True
+ baseline
+
+
+ True
+ False
+ 18
+
+
+
+
+ FEB
+ True
+ True
+ True
+ baseline
+
+
+ True
+ True
+ 19
+
+
+
+
+ False
+ True
+ 2
+
+
+
+
+ True
+ False
+ False
+ True
+ vertical
+
+
+ _I
+ True
+ True
+ True
+ False
+
+
+ False
+ False
+ 0
+
+
+
+
+ FI
+ True
+ True
+ True
+ False
+
+
+ False
+ True
+ 1
+
+
+
+
+ EI
+ True
+ True
+ True
+ False
+
+
+ True
+ False
+ 2
+
+
+
+
+ FEI
+ True
+ True
+ True
+ False
+
+
+ True
+ True
+ 3
+
+
+
+
+ _S
+ True
+ True
+ True
+ start
+ False
+
+
+ False
+ False
+ 4
+
+
+
+
+ FS
+ True
+ True
+ True
+ start
+ False
+
+
+ False
+ True
+ 5
+
+
+
+
+ ES
+ True
+ True
+ True
+ start
+ False
+
+
+ True
+ False
+ 6
+
+
+
+
+ FES
+ True
+ True
+ True
+ start
+ False
+
+
+ True
+ True
+ 7
+
+
+
+
+ _N
+ True
+ True
+ True
+ end
+ False
+
+
+ False
+ False
+ 8
+
+
+
+
+ FN
+ True
+ True
+ True
+ end
+ False
+
+
+ False
+ True
+ 9
+
+
+
+
+ EN
+ True
+ True
+ True
+ end
+ False
+
+
+ True
+ False
+ 10
+
+
+
+
+ FEN
+ True
+ True
+ True
+ end
+ False
+
+
+ True
+ True
+ 11
+
+
+
+
+ _C
+ True
+ True
+ True
+ center
+ False
+
+
+ False
+ False
+ 12
+
+
+
+
+ FC
+ True
+ True
+ True
+ center
+ False
+
+
+ False
+ True
+ 13
+
+
+
+
+ EC
+ True
+ True
+ True
+ center
+ False
+
+
+ True
+ False
+ 14
+
+
+
+
+ FEC
+ True
+ True
+ True
+ center
+ False
+
+
+ True
+ True
+ 15
+
+
+
+
+ _B
+ True
+ True
+ True
+ baseline
+ False
+
+
+ False
+ False
+ 16
+
+
+
+
+ FB
+ True
+ True
+ True
+ baseline
+ False
+
+
+ False
+ True
+ 17
+
+
+
+
+ EB
+ True
+ True
+ True
+ baseline
+ False
+
+
+ True
+ False
+ 18
+
+
+
+
+ FEB
+ True
+ True
+ True
+ baseline
+ False
+
+
+ True
+ True
+ 19
+
+
+
+
+ False
+ True
+ 3
+
+
+
+
+ True
+ False
+ False
+ True
+ vertical
+
+
+ _I
+ True
+ True
+ True
+ True
+
+
+ False
+ False
+ 0
+
+
+
+
+ FI
+ True
+ True
+ True
+ True
+
+
+ False
+ True
+ 1
+
+
+
+
+ EI
+ True
+ True
+ True
+ True
+
+
+ True
+ False
+ 2
+
+
+
+
+ FEI
+ True
+ True
+ True
+ True
+
+
+ True
+ True
+ 3
+
+
+
+
+ _S
+ True
+ True
+ True
+ start
+ True
+
+
+ False
+ False
+ 4
+
+
+
+
+ FS
+ True
+ True
+ True
+ start
+ True
+
+
+ False
+ True
+ 5
+
+
+
+
+ ES
+ True
+ True
+ True
+ start
+ True
+
+
+ True
+ False
+ 6
+
+
+
+
+ FES
+ True
+ True
+ True
+ start
+ True
+
+
+ True
+ True
+ 7
+
+
+
+
+ _N
+ True
+ True
+ True
+ end
+ True
+
+
+ False
+ False
+ 8
+
+
+
+
+ FN
+ True
+ True
+ True
+ end
+ True
+
+
+ False
+ True
+ 9
+
+
+
+
+ EN
+ True
+ True
+ True
+ end
+ True
+
+
+ True
+ False
+ 10
+
+
+
+
+ FEN
+ True
+ True
+ True
+ end
+ True
+
+
+ True
+ True
+ 11
+
+
+
+
+ _C
+ True
+ True
+ True
+ center
+ True
+
+
+ False
+ False
+ 12
+
+
+
+
+ FC
+ True
+ True
+ True
+ center
+ True
+
+
+ False
+ True
+ 13
+
+
+
+
+ EC
+ True
+ True
+ True
+ center
+ True
+
+
+ True
+ False
+ 14
+
+
+
+
+ FEC
+ True
+ True
+ True
+ center
+ True
+
+
+ True
+ True
+ 15
+
+
+
+
+ _B
+ True
+ True
+ True
+ baseline
+ True
+
+
+ False
+ False
+ 16
+
+
+
+
+ FB
+ True
+ True
+ True
+ baseline
+ True
+
+
+ False
+ True
+ 17
+
+
+
+
+ EB
+ True
+ True
+ True
+ baseline
+ True
+
+
+ True
+ False
+ 18
+
+
+
+
+ FEB
+ True
+ True
+ True
+ baseline
+ True
+
+
+ True
+ True
+ 19
+
+
+
+
+ False
+ True
+ 4
+
+
+
+
+
+
diff --git a/testsuite/tools/simplify-data-3to4/gtkfilechooserdialog.expected b/testsuite/tools/simplify-data-3to4/gtkfilechooserdialog.expected
index 6e41177129..11a691763d 100644
--- a/testsuite/tools/simplify-data-3to4/gtkfilechooserdialog.expected
+++ b/testsuite/tools/simplify-data-3to4/gtkfilechooserdialog.expected
@@ -12,15 +12,13 @@
0
+ 1
vertical
-
- 1
-
diff --git a/testsuite/tools/simplify-data-3to4/office-runner.expected b/testsuite/tools/simplify-data-3to4/office-runner.expected
index adeca878bf..d6860d0fd7 100644
--- a/testsuite/tools/simplify-data-3to4/office-runner.expected
+++ b/testsuite/tools/simplify-data-3to4/office-runner.expected
@@ -144,10 +144,6 @@
-
- False
- True
-
@@ -157,10 +153,6 @@
1
1
-
- False
- True
-
@@ -170,10 +162,6 @@
1
1
-
- False
- True
-
1
@@ -191,10 +179,6 @@
-
- False
- True
-
@@ -211,10 +195,6 @@
-
- False
- True
-