/* UndoNodeBalance.c generated by valac 0.56.19, the Vala compiler
 * generated from UndoNodeBalance.vala, do not modify */

/*
* Copyright (c) 2018-2026 (https://github.com/phase1geo/Minder)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* Authored by: Trevor Williams <phase1geo@gmail.com>
*/

#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <gobject/gvaluecollector.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define TYPE_UNDO_ITEM (undo_item_get_type ())
#define UNDO_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_UNDO_ITEM, UndoItem))
#define UNDO_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_UNDO_ITEM, UndoItemClass))
#define IS_UNDO_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_UNDO_ITEM))
#define IS_UNDO_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_UNDO_ITEM))
#define UNDO_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_UNDO_ITEM, UndoItemClass))

typedef struct _UndoItem UndoItem;
typedef struct _UndoItemClass UndoItemClass;
typedef struct _UndoItemPrivate UndoItemPrivate;

#define TYPE_MIND_MAP (mind_map_get_type ())
#define MIND_MAP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MIND_MAP, MindMap))
#define MIND_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MIND_MAP, MindMapClass))
#define IS_MIND_MAP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MIND_MAP))
#define IS_MIND_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MIND_MAP))
#define MIND_MAP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MIND_MAP, MindMapClass))

typedef struct _MindMap MindMap;
typedef struct _MindMapClass MindMapClass;

#define TYPE_UNDO_NODE_BALANCE (undo_node_balance_get_type ())
#define UNDO_NODE_BALANCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_UNDO_NODE_BALANCE, UndoNodeBalance))
#define UNDO_NODE_BALANCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_UNDO_NODE_BALANCE, UndoNodeBalanceClass))
#define IS_UNDO_NODE_BALANCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_UNDO_NODE_BALANCE))
#define IS_UNDO_NODE_BALANCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_UNDO_NODE_BALANCE))
#define UNDO_NODE_BALANCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_UNDO_NODE_BALANCE, UndoNodeBalanceClass))

typedef struct _UndoNodeBalance UndoNodeBalance;
typedef struct _UndoNodeBalanceClass UndoNodeBalanceClass;
typedef struct _UndoNodeBalancePrivate UndoNodeBalancePrivate;

#define UNDO_NODE_BALANCE_TYPE_BALANCE_NODES (undo_node_balance_balance_nodes_get_type ())
#define UNDO_NODE_BALANCE_BALANCE_NODES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), UNDO_NODE_BALANCE_TYPE_BALANCE_NODES, UndoNodeBalanceBalanceNodes))
#define UNDO_NODE_BALANCE_BALANCE_NODES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UNDO_NODE_BALANCE_TYPE_BALANCE_NODES, UndoNodeBalanceBalanceNodesClass))
#define UNDO_NODE_BALANCE_IS_BALANCE_NODES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UNDO_NODE_BALANCE_TYPE_BALANCE_NODES))
#define UNDO_NODE_BALANCE_IS_BALANCE_NODES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UNDO_NODE_BALANCE_TYPE_BALANCE_NODES))
#define UNDO_NODE_BALANCE_BALANCE_NODES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), UNDO_NODE_BALANCE_TYPE_BALANCE_NODES, UndoNodeBalanceBalanceNodesClass))

typedef struct _UndoNodeBalanceBalanceNodes UndoNodeBalanceBalanceNodes;
typedef struct _UndoNodeBalanceBalanceNodesClass UndoNodeBalanceBalanceNodesClass;

#define TYPE_NODE (node_get_type ())
#define NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_NODE, Node))
#define NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_NODE, NodeClass))
#define IS_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_NODE))
#define IS_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_NODE))
#define NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_NODE, NodeClass))

typedef struct _Node Node;
typedef struct _NodeClass NodeClass;
enum  {
	UNDO_NODE_BALANCE_0_PROPERTY,
	UNDO_NODE_BALANCE_NUM_PROPERTIES
};
static GParamSpec* undo_node_balance_properties[UNDO_NODE_BALANCE_NUM_PROPERTIES];
#define _g_array_unref0(var) ((var == NULL) ? NULL : (var = (g_array_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define TYPE_ANIMATOR (animator_get_type ())
#define ANIMATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ANIMATOR, Animator))
#define ANIMATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ANIMATOR, AnimatorClass))
#define IS_ANIMATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ANIMATOR))
#define IS_ANIMATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_ANIMATOR))
#define ANIMATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_ANIMATOR, AnimatorClass))

typedef struct _Animator Animator;
typedef struct _AnimatorClass AnimatorClass;
typedef struct _UndoNodeBalanceBalanceNodesPrivate UndoNodeBalanceBalanceNodesPrivate;
typedef enum  {
	NODE_SIDE_LEFT = 1,
	NODE_SIDE_TOP = 2,
	NODE_SIDE_RIGHT = 4,
	NODE_SIDE_BOTTOM = 8
} NodeSide;

#define TYPE_NODE_SIDE (node_side_get_type ())

#define TYPE_LAYOUT (layout_get_type ())
#define LAYOUT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_LAYOUT, Layout))
#define LAYOUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_LAYOUT, LayoutClass))
#define IS_LAYOUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_LAYOUT))
#define IS_LAYOUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_LAYOUT))
#define LAYOUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_LAYOUT, LayoutClass))

typedef struct _Layout Layout;
typedef struct _LayoutClass LayoutClass;
typedef struct _UndoNodeBalanceParamSpecBalanceNodes UndoNodeBalanceParamSpecBalanceNodes;

struct _UndoItem {
	GObject parent_instance;
	UndoItemPrivate * priv;
};

struct _UndoItemClass {
	GObjectClass parent_class;
	void (*undo) (UndoItem* self, MindMap* map);
	void (*redo) (UndoItem* self, MindMap* map);
	gboolean (*matches) (UndoItem* self, UndoItem* item);
	void (*replace_with_item) (UndoItem* self, UndoItem* item);
	gchar* (*to_string) (UndoItem* self);
};

struct _UndoNodeBalance {
	UndoItem parent_instance;
	UndoNodeBalancePrivate * priv;
};

struct _UndoNodeBalanceClass {
	UndoItemClass parent_class;
};

struct _UndoNodeBalancePrivate {
	GArray* _old;
	GArray* _new;
	Node* _root;
};

struct _UndoNodeBalanceBalanceNodes {
	GTypeInstance parent_instance;
	volatile int ref_count;
	UndoNodeBalanceBalanceNodesPrivate * priv;
};

struct _UndoNodeBalanceBalanceNodesClass {
	GTypeClass parent_class;
	void (*finalize) (UndoNodeBalanceBalanceNodes *self);
};

struct _UndoNodeBalanceBalanceNodesPrivate {
	GArray* _nodes;
	GArray* _sides;
};

struct _UndoNodeBalanceParamSpecBalanceNodes {
	GParamSpec parent_instance;
};

static gint UndoNodeBalance_private_offset;
static gpointer undo_node_balance_parent_class = NULL;
static gint UndoNodeBalanceBalanceNodes_private_offset;
static gpointer undo_node_balance_balance_nodes_parent_class = NULL;

VALA_EXTERN GType undo_item_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UndoItem, g_object_unref)
VALA_EXTERN gpointer mind_map_ref (gpointer instance);
VALA_EXTERN void mind_map_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_mind_map (const gchar* name,
                                 const gchar* nick,
                                 const gchar* blurb,
                                 GType object_type,
                                 GParamFlags flags);
VALA_EXTERN void value_set_mind_map (GValue* value,
                         gpointer v_object);
VALA_EXTERN void value_take_mind_map (GValue* value,
                          gpointer v_object);
VALA_EXTERN gpointer value_get_mind_map (const GValue* value);
VALA_EXTERN GType mind_map_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MindMap, mind_map_unref)
VALA_EXTERN GType undo_node_balance_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UndoNodeBalance, g_object_unref)
static gpointer undo_node_balance_balance_nodes_ref (gpointer instance);
static void undo_node_balance_balance_nodes_unref (gpointer instance);
static GParamSpec* undo_node_balance_param_spec_balance_nodes (const gchar* name,
                                                        const gchar* nick,
                                                        const gchar* blurb,
                                                        GType object_type,
                                                        GParamFlags flags) G_GNUC_UNUSED ;
static void undo_node_balance_value_set_balance_nodes (GValue* value,
                                                gpointer v_object) G_GNUC_UNUSED ;
static void undo_node_balance_value_take_balance_nodes (GValue* value,
                                                 gpointer v_object) G_GNUC_UNUSED ;
static gpointer undo_node_balance_value_get_balance_nodes (const GValue* value) G_GNUC_UNUSED ;
static GType undo_node_balance_balance_nodes_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UndoNodeBalanceBalanceNodes, undo_node_balance_balance_nodes_unref)
VALA_EXTERN GType node_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Node, g_object_unref)
VALA_EXTERN void undo_item_undo (UndoItem* self,
                     MindMap* map);
VALA_EXTERN void undo_item_redo (UndoItem* self,
                     MindMap* map);
VALA_EXTERN UndoNodeBalance* undo_node_balance_new (MindMap* map,
                                        Node* root_node);
VALA_EXTERN UndoNodeBalance* undo_node_balance_construct (GType object_type,
                                              MindMap* map,
                                              Node* root_node);
VALA_EXTERN UndoItem* undo_item_new (const gchar* name);
VALA_EXTERN UndoItem* undo_item_construct (GType object_type,
                               const gchar* name);
static void _undo_node_balance_balance_nodes_unref0_ (gpointer var);
static void _vala_UndoNodeBalanceBalanceNodes_free_function_content_of (gpointer data);
VALA_EXTERN GArray* mind_map_get_nodes (MindMap* self);
static UndoNodeBalanceBalanceNodes* undo_node_balance_balance_nodes_new (Node* n);
static UndoNodeBalanceBalanceNodes* undo_node_balance_balance_nodes_construct (GType object_type,
                                                                        Node* n);
static void undo_node_balance_change (UndoNodeBalance* self,
                               MindMap* map,
                               GArray* nodes);
VALA_EXTERN GType animator_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Animator, g_object_unref)
VALA_EXTERN Animator* mind_map_get_animator (MindMap* self);
VALA_EXTERN void animator_add_nodes (Animator* self,
                         GArray* n,
                         gboolean exclude_selected,
                         const gchar* name);
static void undo_node_balance_balance_nodes_change (UndoNodeBalanceBalanceNodes* self,
                                             Node* parent);
VALA_EXTERN void animator_animate (Animator* self);
static void undo_node_balance_real_undo (UndoItem* base,
                                  MindMap* map);
static void undo_node_balance_real_redo (UndoItem* base,
                                  MindMap* map);
VALA_EXTERN GType node_side_get_type (void) G_GNUC_CONST ;
static void _g_object_unref0_ (gpointer var);
static void _vala_Node_free_function_content_of (gpointer data);
VALA_EXTERN GArray* node_children (Node* self);
VALA_EXTERN NodeSide node_get_side (Node* self);
VALA_EXTERN void node_detach (Node* self,
                  NodeSide side);
VALA_EXTERN void node_set_side (Node* self,
                    NodeSide value);
VALA_EXTERN GType layout_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Layout, g_object_unref)
VALA_EXTERN Layout* node_get_layout (Node* self);
VALA_EXTERN void layout_propagate_side (Layout* self,
                            Node* parent,
                            NodeSide side);
VALA_EXTERN void node_attach_init (Node* self,
                       Node* parent,
                       gint index);
static void undo_node_balance_balance_nodes_finalize (UndoNodeBalanceBalanceNodes * obj);
static GType undo_node_balance_balance_nodes_get_type_once (void);
static void undo_node_balance_finalize (GObject * obj);
static GType undo_node_balance_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
undo_node_balance_get_instance_private (UndoNodeBalance* self)
{
	return G_STRUCT_MEMBER_P (self, UndoNodeBalance_private_offset);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static void
_undo_node_balance_balance_nodes_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (undo_node_balance_balance_nodes_unref (var), NULL));
}

static void
_vala_UndoNodeBalanceBalanceNodes_free_function_content_of (gpointer data)
{
	UndoNodeBalanceBalanceNodes* self;
	self = *((UndoNodeBalanceBalanceNodes**) data);
	_undo_node_balance_balance_nodes_unref0_ (self);
}

UndoNodeBalance*
undo_node_balance_construct (GType object_type,
                             MindMap* map,
                             Node* root_node)
{
	UndoNodeBalance * self = NULL;
	Node* _tmp0_;
	GArray* _tmp1_;
	g_return_val_if_fail (map != NULL, NULL);
	self = (UndoNodeBalance*) undo_item_construct (object_type, _ ("balance nodes"));
	_tmp0_ = _g_object_ref0 (root_node);
	_g_object_unref0 (self->priv->_root);
	self->priv->_root = _tmp0_;
	_tmp1_ = g_array_new (TRUE, TRUE, sizeof (UndoNodeBalanceBalanceNodes*));
	g_array_set_clear_func (_tmp1_, (GDestroyNotify) _vala_UndoNodeBalanceBalanceNodes_free_function_content_of);
	_g_array_unref0 (self->priv->_old);
	self->priv->_old = _tmp1_;
	if (root_node == NULL) {
		{
			gint i = 0;
			i = 0;
			{
				gboolean _tmp2_ = FALSE;
				_tmp2_ = TRUE;
				while (TRUE) {
					GArray* _tmp4_;
					GArray* _tmp5_;
					gboolean _tmp6_;
					GArray* _tmp7_;
					GArray* _tmp8_;
					GArray* _tmp9_;
					Node* _tmp10_;
					UndoNodeBalanceBalanceNodes* _tmp11_;
					if (!_tmp2_) {
						gint _tmp3_;
						_tmp3_ = i;
						i = _tmp3_ + 1;
					}
					_tmp2_ = FALSE;
					_tmp4_ = mind_map_get_nodes (map);
					_tmp5_ = _tmp4_;
					_tmp6_ = !(((guint) i) < _tmp5_->len);
					_g_array_unref0 (_tmp5_);
					if (_tmp6_) {
						break;
					}
					_tmp7_ = self->priv->_old;
					_tmp8_ = mind_map_get_nodes (map);
					_tmp9_ = _tmp8_;
					_tmp10_ = g_array_index (_tmp9_, Node*, (guint) i);
					_tmp11_ = undo_node_balance_balance_nodes_new (_tmp10_);
					g_array_append_val (_tmp7_, _tmp11_);
					_g_array_unref0 (_tmp9_);
				}
			}
		}
	} else {
		GArray* _tmp12_;
		UndoNodeBalanceBalanceNodes* _tmp13_;
		_tmp12_ = self->priv->_old;
		_tmp13_ = undo_node_balance_balance_nodes_new (root_node);
		g_array_append_val (_tmp12_, _tmp13_);
	}
	return self;
}

UndoNodeBalance*
undo_node_balance_new (MindMap* map,
                       Node* root_node)
{
	return undo_node_balance_construct (TYPE_UNDO_NODE_BALANCE, map, root_node);
}

static void
undo_node_balance_change (UndoNodeBalance* self,
                          MindMap* map,
                          GArray* nodes)
{
	Animator* _tmp0_;
	Animator* _tmp1_;
	GArray* _tmp2_;
	GArray* _tmp3_;
	Node* _tmp4_;
	Animator* _tmp16_;
	Animator* _tmp17_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (map != NULL);
	g_return_if_fail (nodes != NULL);
	_tmp0_ = mind_map_get_animator (map);
	_tmp1_ = _tmp0_;
	_tmp2_ = mind_map_get_nodes (map);
	_tmp3_ = _tmp2_;
	animator_add_nodes (_tmp1_, _tmp3_, FALSE, "undo balance nodes");
	_g_array_unref0 (_tmp3_);
	_tmp4_ = self->priv->_root;
	if (_tmp4_ == NULL) {
		{
			gint i = 0;
			i = 0;
			{
				gboolean _tmp5_ = FALSE;
				_tmp5_ = TRUE;
				while (TRUE) {
					GArray* _tmp7_;
					GArray* _tmp8_;
					gboolean _tmp9_;
					UndoNodeBalanceBalanceNodes* _tmp10_;
					GArray* _tmp11_;
					GArray* _tmp12_;
					Node* _tmp13_;
					if (!_tmp5_) {
						gint _tmp6_;
						_tmp6_ = i;
						i = _tmp6_ + 1;
					}
					_tmp5_ = FALSE;
					_tmp7_ = mind_map_get_nodes (map);
					_tmp8_ = _tmp7_;
					_tmp9_ = !(((guint) i) < _tmp8_->len);
					_g_array_unref0 (_tmp8_);
					if (_tmp9_) {
						break;
					}
					_tmp10_ = g_array_index (nodes, UndoNodeBalanceBalanceNodes*, (guint) i);
					_tmp11_ = mind_map_get_nodes (map);
					_tmp12_ = _tmp11_;
					_tmp13_ = g_array_index (_tmp12_, Node*, (guint) i);
					undo_node_balance_balance_nodes_change (_tmp10_, _tmp13_);
					_g_array_unref0 (_tmp12_);
				}
			}
		}
	} else {
		UndoNodeBalanceBalanceNodes* _tmp14_;
		Node* _tmp15_;
		_tmp14_ = g_array_index (nodes, UndoNodeBalanceBalanceNodes*, (guint) 0);
		_tmp15_ = self->priv->_root;
		undo_node_balance_balance_nodes_change (_tmp14_, _tmp15_);
	}
	_tmp16_ = mind_map_get_animator (map);
	_tmp17_ = _tmp16_;
	animator_animate (_tmp17_);
}

static void
undo_node_balance_real_undo (UndoItem* base,
                             MindMap* map)
{
	UndoNodeBalance * self;
	GArray* _tmp0_;
	GArray* _tmp12_;
	self = (UndoNodeBalance*) base;
	g_return_if_fail (map != NULL);
	_tmp0_ = self->priv->_new;
	if (_tmp0_ == NULL) {
		GArray* _tmp1_;
		_tmp1_ = g_array_new (TRUE, TRUE, sizeof (UndoNodeBalanceBalanceNodes*));
		g_array_set_clear_func (_tmp1_, (GDestroyNotify) _vala_UndoNodeBalanceBalanceNodes_free_function_content_of);
		_g_array_unref0 (self->priv->_new);
		self->priv->_new = _tmp1_;
		{
			gint i = 0;
			i = 0;
			{
				gboolean _tmp2_ = FALSE;
				_tmp2_ = TRUE;
				while (TRUE) {
					GArray* _tmp4_;
					GArray* _tmp5_;
					gboolean _tmp6_;
					GArray* _tmp7_;
					GArray* _tmp8_;
					GArray* _tmp9_;
					Node* _tmp10_;
					UndoNodeBalanceBalanceNodes* _tmp11_;
					if (!_tmp2_) {
						gint _tmp3_;
						_tmp3_ = i;
						i = _tmp3_ + 1;
					}
					_tmp2_ = FALSE;
					_tmp4_ = mind_map_get_nodes (map);
					_tmp5_ = _tmp4_;
					_tmp6_ = !(((guint) i) < _tmp5_->len);
					_g_array_unref0 (_tmp5_);
					if (_tmp6_) {
						break;
					}
					_tmp7_ = self->priv->_new;
					_tmp8_ = mind_map_get_nodes (map);
					_tmp9_ = _tmp8_;
					_tmp10_ = g_array_index (_tmp9_, Node*, (guint) i);
					_tmp11_ = undo_node_balance_balance_nodes_new (_tmp10_);
					g_array_append_val (_tmp7_, _tmp11_);
					_g_array_unref0 (_tmp9_);
				}
			}
		}
	}
	_tmp12_ = self->priv->_old;
	undo_node_balance_change (self, map, _tmp12_);
}

static void
undo_node_balance_real_redo (UndoItem* base,
                             MindMap* map)
{
	UndoNodeBalance * self;
	GArray* _tmp0_;
	self = (UndoNodeBalance*) base;
	g_return_if_fail (map != NULL);
	_tmp0_ = self->priv->_new;
	undo_node_balance_change (self, map, _tmp0_);
}

static inline gpointer
undo_node_balance_balance_nodes_get_instance_private (UndoNodeBalanceBalanceNodes* self)
{
	return G_STRUCT_MEMBER_P (self, UndoNodeBalanceBalanceNodes_private_offset);
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

static void
_vala_Node_free_function_content_of (gpointer data)
{
	Node* self;
	self = *((Node**) data);
	_g_object_unref0_ (self);
}

static UndoNodeBalanceBalanceNodes*
undo_node_balance_balance_nodes_construct (GType object_type,
                                           Node* n)
{
	UndoNodeBalanceBalanceNodes* self = NULL;
	GArray* _tmp0_;
	GArray* _tmp1_;
	g_return_val_if_fail (n != NULL, NULL);
	self = (UndoNodeBalanceBalanceNodes*) g_type_create_instance (object_type);
	_tmp0_ = g_array_new (TRUE, TRUE, sizeof (Node*));
	g_array_set_clear_func (_tmp0_, (GDestroyNotify) _vala_Node_free_function_content_of);
	_g_array_unref0 (self->priv->_nodes);
	self->priv->_nodes = _tmp0_;
	_tmp1_ = g_array_new (TRUE, TRUE, sizeof (NodeSide));
	_g_array_unref0 (self->priv->_sides);
	self->priv->_sides = _tmp1_;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp2_ = FALSE;
			_tmp2_ = TRUE;
			while (TRUE) {
				GArray* _tmp4_;
				GArray* _tmp5_;
				gboolean _tmp6_;
				GArray* _tmp7_;
				GArray* _tmp8_;
				GArray* _tmp9_;
				Node* _tmp10_;
				Node* _tmp11_;
				GArray* _tmp12_;
				GArray* _tmp13_;
				GArray* _tmp14_;
				Node* _tmp15_;
				NodeSide _tmp16_;
				NodeSide _tmp17_;
				if (!_tmp2_) {
					gint _tmp3_;
					_tmp3_ = i;
					i = _tmp3_ + 1;
				}
				_tmp2_ = FALSE;
				_tmp4_ = node_children (n);
				_tmp5_ = _tmp4_;
				_tmp6_ = !(((guint) i) < _tmp5_->len);
				_g_array_unref0 (_tmp5_);
				if (_tmp6_) {
					break;
				}
				_tmp7_ = self->priv->_nodes;
				_tmp8_ = node_children (n);
				_tmp9_ = _tmp8_;
				_tmp10_ = g_array_index (_tmp9_, Node*, (guint) i);
				_tmp11_ = _g_object_ref0 (_tmp10_);
				g_array_append_val (_tmp7_, _tmp11_);
				_g_array_unref0 (_tmp9_);
				_tmp12_ = self->priv->_sides;
				_tmp13_ = node_children (n);
				_tmp14_ = _tmp13_;
				_tmp15_ = g_array_index (_tmp14_, Node*, (guint) i);
				_tmp16_ = node_get_side (_tmp15_);
				_tmp17_ = _tmp16_;
				g_array_append_val (_tmp12_, _tmp17_);
				_g_array_unref0 (_tmp14_);
			}
		}
	}
	return self;
}

static UndoNodeBalanceBalanceNodes*
undo_node_balance_balance_nodes_new (Node* n)
{
	return undo_node_balance_balance_nodes_construct (UNDO_NODE_BALANCE_TYPE_BALANCE_NODES, n);
}

static void
undo_node_balance_balance_nodes_change (UndoNodeBalanceBalanceNodes* self,
                                        Node* parent)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (parent != NULL);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				GArray* _tmp2_;
				Node* n = NULL;
				GArray* _tmp3_;
				Node* _tmp4_;
				Node* _tmp5_;
				Node* _tmp6_;
				Node* _tmp7_;
				NodeSide _tmp8_;
				NodeSide _tmp9_;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				_tmp2_ = self->priv->_nodes;
				if (!(((guint) i) < _tmp2_->len)) {
					break;
				}
				_tmp3_ = self->priv->_nodes;
				_tmp4_ = g_array_index (_tmp3_, Node*, (guint) i);
				_tmp5_ = _g_object_ref0 (_tmp4_);
				n = _tmp5_;
				_tmp6_ = n;
				_tmp7_ = n;
				_tmp8_ = node_get_side (_tmp7_);
				_tmp9_ = _tmp8_;
				node_detach (_tmp6_, _tmp9_);
				_g_object_unref0 (n);
			}
		}
	}
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp10_ = FALSE;
			_tmp10_ = TRUE;
			while (TRUE) {
				GArray* _tmp12_;
				Node* n = NULL;
				GArray* _tmp13_;
				Node* _tmp14_;
				Node* _tmp15_;
				Node* _tmp16_;
				GArray* _tmp17_;
				Node* _tmp18_;
				Layout* _tmp19_;
				Layout* _tmp20_;
				Node* _tmp21_;
				Node* _tmp22_;
				NodeSide _tmp23_;
				NodeSide _tmp24_;
				Node* _tmp25_;
				if (!_tmp10_) {
					gint _tmp11_;
					_tmp11_ = i;
					i = _tmp11_ + 1;
				}
				_tmp10_ = FALSE;
				_tmp12_ = self->priv->_nodes;
				if (!(((guint) i) < _tmp12_->len)) {
					break;
				}
				_tmp13_ = self->priv->_nodes;
				_tmp14_ = g_array_index (_tmp13_, Node*, (guint) i);
				_tmp15_ = _g_object_ref0 (_tmp14_);
				n = _tmp15_;
				_tmp16_ = n;
				_tmp17_ = self->priv->_sides;
				node_set_side (_tmp16_, g_array_index (_tmp17_, NodeSide, (guint) i));
				_tmp18_ = n;
				_tmp19_ = node_get_layout (_tmp18_);
				_tmp20_ = _tmp19_;
				_tmp21_ = n;
				_tmp22_ = n;
				_tmp23_ = node_get_side (_tmp22_);
				_tmp24_ = _tmp23_;
				layout_propagate_side (_tmp20_, _tmp21_, _tmp24_);
				_tmp25_ = n;
				node_attach_init (_tmp25_, parent, -1);
				_g_object_unref0 (n);
			}
		}
	}
}

static void
undo_node_balance_value_balance_nodes_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
undo_node_balance_value_balance_nodes_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		undo_node_balance_balance_nodes_unref (value->data[0].v_pointer);
	}
}

static void
undo_node_balance_value_balance_nodes_copy_value (const GValue* src_value,
                                                  GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = undo_node_balance_balance_nodes_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
undo_node_balance_value_balance_nodes_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
undo_node_balance_value_balance_nodes_collect_value (GValue* value,
                                                     guint n_collect_values,
                                                     GTypeCValue* collect_values,
                                                     guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		UndoNodeBalanceBalanceNodes * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = undo_node_balance_balance_nodes_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
undo_node_balance_value_balance_nodes_lcopy_value (const GValue* value,
                                                   guint n_collect_values,
                                                   GTypeCValue* collect_values,
                                                   guint collect_flags)
{
	UndoNodeBalanceBalanceNodes ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = undo_node_balance_balance_nodes_ref (value->data[0].v_pointer);
	}
	return NULL;
}

static GParamSpec*
undo_node_balance_param_spec_balance_nodes (const gchar* name,
                                            const gchar* nick,
                                            const gchar* blurb,
                                            GType object_type,
                                            GParamFlags flags)
{
	UndoNodeBalanceParamSpecBalanceNodes* spec;
	g_return_val_if_fail (g_type_is_a (object_type, UNDO_NODE_BALANCE_TYPE_BALANCE_NODES), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

static gpointer
undo_node_balance_value_get_balance_nodes (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, UNDO_NODE_BALANCE_TYPE_BALANCE_NODES), NULL);
	return value->data[0].v_pointer;
}

static void
undo_node_balance_value_set_balance_nodes (GValue* value,
                                           gpointer v_object)
{
	UndoNodeBalanceBalanceNodes * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, UNDO_NODE_BALANCE_TYPE_BALANCE_NODES));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, UNDO_NODE_BALANCE_TYPE_BALANCE_NODES));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		undo_node_balance_balance_nodes_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		undo_node_balance_balance_nodes_unref (old);
	}
}

static void
undo_node_balance_value_take_balance_nodes (GValue* value,
                                            gpointer v_object)
{
	UndoNodeBalanceBalanceNodes * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, UNDO_NODE_BALANCE_TYPE_BALANCE_NODES));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, UNDO_NODE_BALANCE_TYPE_BALANCE_NODES));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		undo_node_balance_balance_nodes_unref (old);
	}
}

static void
undo_node_balance_balance_nodes_class_init (UndoNodeBalanceBalanceNodesClass * klass,
                                            gpointer klass_data)
{
	undo_node_balance_balance_nodes_parent_class = g_type_class_peek_parent (klass);
	((UndoNodeBalanceBalanceNodesClass *) klass)->finalize = undo_node_balance_balance_nodes_finalize;
	g_type_class_adjust_private_offset (klass, &UndoNodeBalanceBalanceNodes_private_offset);
}

static void
undo_node_balance_balance_nodes_instance_init (UndoNodeBalanceBalanceNodes * self,
                                               gpointer klass)
{
	self->priv = undo_node_balance_balance_nodes_get_instance_private (self);
	self->ref_count = 1;
}

static void
undo_node_balance_balance_nodes_finalize (UndoNodeBalanceBalanceNodes * obj)
{
	UndoNodeBalanceBalanceNodes * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, UNDO_NODE_BALANCE_TYPE_BALANCE_NODES, UndoNodeBalanceBalanceNodes);
	g_signal_handlers_destroy (self);
	_g_array_unref0 (self->priv->_nodes);
	_g_array_unref0 (self->priv->_sides);
}

static GType
undo_node_balance_balance_nodes_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { undo_node_balance_value_balance_nodes_init, undo_node_balance_value_balance_nodes_free_value, undo_node_balance_value_balance_nodes_copy_value, undo_node_balance_value_balance_nodes_peek_pointer, "p", undo_node_balance_value_balance_nodes_collect_value, "p", undo_node_balance_value_balance_nodes_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (UndoNodeBalanceBalanceNodesClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) undo_node_balance_balance_nodes_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UndoNodeBalanceBalanceNodes), 0, (GInstanceInitFunc) undo_node_balance_balance_nodes_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType undo_node_balance_balance_nodes_type_id;
	undo_node_balance_balance_nodes_type_id = g_type_register_fundamental (g_type_fundamental_next (), "UndoNodeBalanceBalanceNodes", &g_define_type_info, &g_define_type_fundamental_info, 0);
	UndoNodeBalanceBalanceNodes_private_offset = g_type_add_instance_private (undo_node_balance_balance_nodes_type_id, sizeof (UndoNodeBalanceBalanceNodesPrivate));
	return undo_node_balance_balance_nodes_type_id;
}

static GType
undo_node_balance_balance_nodes_get_type (void)
{
	static volatile gsize undo_node_balance_balance_nodes_type_id__once = 0;
	if (g_once_init_enter (&undo_node_balance_balance_nodes_type_id__once)) {
		GType undo_node_balance_balance_nodes_type_id;
		undo_node_balance_balance_nodes_type_id = undo_node_balance_balance_nodes_get_type_once ();
		g_once_init_leave (&undo_node_balance_balance_nodes_type_id__once, undo_node_balance_balance_nodes_type_id);
	}
	return undo_node_balance_balance_nodes_type_id__once;
}

static gpointer
undo_node_balance_balance_nodes_ref (gpointer instance)
{
	UndoNodeBalanceBalanceNodes * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

static void
undo_node_balance_balance_nodes_unref (gpointer instance)
{
	UndoNodeBalanceBalanceNodes * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		UNDO_NODE_BALANCE_BALANCE_NODES_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static void
undo_node_balance_class_init (UndoNodeBalanceClass * klass,
                              gpointer klass_data)
{
	undo_node_balance_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &UndoNodeBalance_private_offset);
	((UndoItemClass *) klass)->undo = (void (*) (UndoItem*, MindMap*)) undo_node_balance_real_undo;
	((UndoItemClass *) klass)->redo = (void (*) (UndoItem*, MindMap*)) undo_node_balance_real_redo;
	G_OBJECT_CLASS (klass)->finalize = undo_node_balance_finalize;
}

static void
undo_node_balance_instance_init (UndoNodeBalance * self,
                                 gpointer klass)
{
	self->priv = undo_node_balance_get_instance_private (self);
	self->priv->_new = NULL;
	self->priv->_root = NULL;
}

static void
undo_node_balance_finalize (GObject * obj)
{
	UndoNodeBalance * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_UNDO_NODE_BALANCE, UndoNodeBalance);
	_g_array_unref0 (self->priv->_old);
	_g_array_unref0 (self->priv->_new);
	_g_object_unref0 (self->priv->_root);
	G_OBJECT_CLASS (undo_node_balance_parent_class)->finalize (obj);
}

static GType
undo_node_balance_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (UndoNodeBalanceClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) undo_node_balance_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UndoNodeBalance), 0, (GInstanceInitFunc) undo_node_balance_instance_init, NULL };
	GType undo_node_balance_type_id;
	undo_node_balance_type_id = g_type_register_static (TYPE_UNDO_ITEM, "UndoNodeBalance", &g_define_type_info, 0);
	UndoNodeBalance_private_offset = g_type_add_instance_private (undo_node_balance_type_id, sizeof (UndoNodeBalancePrivate));
	return undo_node_balance_type_id;
}

GType
undo_node_balance_get_type (void)
{
	static volatile gsize undo_node_balance_type_id__once = 0;
	if (g_once_init_enter (&undo_node_balance_type_id__once)) {
		GType undo_node_balance_type_id;
		undo_node_balance_type_id = undo_node_balance_get_type_once ();
		g_once_init_leave (&undo_node_balance_type_id__once, undo_node_balance_type_id);
	}
	return undo_node_balance_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

