/* UndoNodeSummaryFromNode.c generated by valac 0.56.19, the Vala compiler
 * generated from UndoNodeSummaryFromNode.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>

#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_SUMMARY_FROM_NODE (undo_node_summary_from_node_get_type ())
#define UNDO_NODE_SUMMARY_FROM_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_UNDO_NODE_SUMMARY_FROM_NODE, UndoNodeSummaryFromNode))
#define UNDO_NODE_SUMMARY_FROM_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_UNDO_NODE_SUMMARY_FROM_NODE, UndoNodeSummaryFromNodeClass))
#define IS_UNDO_NODE_SUMMARY_FROM_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_UNDO_NODE_SUMMARY_FROM_NODE))
#define IS_UNDO_NODE_SUMMARY_FROM_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_UNDO_NODE_SUMMARY_FROM_NODE))
#define UNDO_NODE_SUMMARY_FROM_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_UNDO_NODE_SUMMARY_FROM_NODE, UndoNodeSummaryFromNodeClass))

typedef struct _UndoNodeSummaryFromNode UndoNodeSummaryFromNode;
typedef struct _UndoNodeSummaryFromNodeClass UndoNodeSummaryFromNodeClass;
typedef struct _UndoNodeSummaryFromNodePrivate UndoNodeSummaryFromNodePrivate;

#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;

#define TYPE_SUMMARY_NODE (summary_node_get_type ())
#define SUMMARY_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SUMMARY_NODE, SummaryNode))
#define SUMMARY_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SUMMARY_NODE, SummaryNodeClass))
#define IS_SUMMARY_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SUMMARY_NODE))
#define IS_SUMMARY_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SUMMARY_NODE))
#define SUMMARY_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SUMMARY_NODE, SummaryNodeClass))

typedef struct _SummaryNode SummaryNode;
typedef struct _SummaryNodeClass SummaryNodeClass;
enum  {
	UNDO_NODE_SUMMARY_FROM_NODE_0_PROPERTY,
	UNDO_NODE_SUMMARY_FROM_NODE_NUM_PROPERTIES
};
static GParamSpec* undo_node_summary_from_node_properties[UNDO_NODE_SUMMARY_FROM_NODE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define TYPE_THEME (theme_get_type ())
#define THEME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_THEME, Theme))
#define THEME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_THEME, ThemeClass))
#define IS_THEME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_THEME))
#define IS_THEME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_THEME))
#define THEME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_THEME, ThemeClass))

typedef struct _Theme Theme;
typedef struct _ThemeClass ThemeClass;
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 ())

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 _UndoNodeSummaryFromNode {
	UndoItem parent_instance;
	UndoNodeSummaryFromNodePrivate * priv;
};

struct _UndoNodeSummaryFromNodeClass {
	UndoItemClass parent_class;
};

struct _UndoNodeSummaryFromNodePrivate {
	Node* _n;
	SummaryNode* _sn;
};

static gint UndoNodeSummaryFromNode_private_offset;
static gpointer undo_node_summary_from_node_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_summary_from_node_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UndoNodeSummaryFromNode, g_object_unref)
VALA_EXTERN GType node_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Node, g_object_unref)
VALA_EXTERN GType summary_node_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SummaryNode, 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 UndoNodeSummaryFromNode* undo_node_summary_from_node_new (Node* n,
                                                          SummaryNode* sn);
VALA_EXTERN UndoNodeSummaryFromNode* undo_node_summary_from_node_construct (GType object_type,
                                                                Node* n,
                                                                SummaryNode* sn);
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_summary_from_node_real_undo (UndoItem* base,
                                            MindMap* map);
VALA_EXTERN Node* summary_node_last_node (SummaryNode* self);
VALA_EXTERN Node* node_get_parent (Node* self);
VALA_EXTERN gint node_index (Node* self);
VALA_EXTERN void summary_node_detach_all (SummaryNode* self);
VALA_EXTERN GType theme_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Theme, g_object_unref)
VALA_EXTERN void node_attach (Node* self,
                  Node* parent,
                  gint idx,
                  Theme* theme,
                  gboolean set_side);
VALA_EXTERN void mind_map_set_current_node (MindMap* self,
                                Node* n);
VALA_EXTERN void mind_map_queue_draw (MindMap* self);
VALA_EXTERN void mind_map_auto_save (MindMap* self);
static void undo_node_summary_from_node_real_redo (UndoItem* base,
                                            MindMap* map);
VALA_EXTERN GType node_side_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void node_detach (Node* self,
                  NodeSide side);
VALA_EXTERN NodeSide node_get_side (Node* self);
VALA_EXTERN void summary_node_attach_all (SummaryNode* self);
static void undo_node_summary_from_node_finalize (GObject * obj);
static GType undo_node_summary_from_node_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
undo_node_summary_from_node_get_instance_private (UndoNodeSummaryFromNode* self)
{
	return G_STRUCT_MEMBER_P (self, UndoNodeSummaryFromNode_private_offset);
}

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

UndoNodeSummaryFromNode*
undo_node_summary_from_node_construct (GType object_type,
                                       Node* n,
                                       SummaryNode* sn)
{
	UndoNodeSummaryFromNode * self = NULL;
	Node* _tmp0_;
	SummaryNode* _tmp1_;
	g_return_val_if_fail (n != NULL, NULL);
	g_return_val_if_fail (sn != NULL, NULL);
	self = (UndoNodeSummaryFromNode*) undo_item_construct (object_type, _ ("convert to summary node"));
	_tmp0_ = _g_object_ref0 (n);
	_g_object_unref0 (self->priv->_n);
	self->priv->_n = _tmp0_;
	_tmp1_ = _g_object_ref0 (sn);
	_g_object_unref0 (self->priv->_sn);
	self->priv->_sn = _tmp1_;
	return self;
}

UndoNodeSummaryFromNode*
undo_node_summary_from_node_new (Node* n,
                                 SummaryNode* sn)
{
	return undo_node_summary_from_node_construct (TYPE_UNDO_NODE_SUMMARY_FROM_NODE, n, sn);
}

static void
undo_node_summary_from_node_real_undo (UndoItem* base,
                                       MindMap* map)
{
	UndoNodeSummaryFromNode * self;
	Node* parent = NULL;
	SummaryNode* _tmp0_;
	Node* _tmp1_;
	Node* _tmp2_;
	Node* _tmp3_;
	Node* _tmp4_;
	Node* _tmp5_;
	Node* _tmp6_;
	gint index = 0;
	SummaryNode* _tmp7_;
	Node* _tmp8_;
	Node* _tmp9_;
	gint _tmp10_;
	SummaryNode* _tmp11_;
	Node* _tmp12_;
	Node* _tmp13_;
	self = (UndoNodeSummaryFromNode*) base;
	g_return_if_fail (map != NULL);
	_tmp0_ = self->priv->_sn;
	_tmp1_ = summary_node_last_node (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = node_get_parent (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = _g_object_ref0 (_tmp4_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp2_);
	parent = _tmp6_;
	_tmp7_ = self->priv->_sn;
	_tmp8_ = summary_node_last_node (_tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = node_index (_tmp9_) + 1;
	_g_object_unref0 (_tmp9_);
	index = _tmp10_;
	_tmp11_ = self->priv->_sn;
	summary_node_detach_all (_tmp11_);
	_tmp12_ = self->priv->_n;
	node_attach (_tmp12_, parent, index, NULL, FALSE);
	_tmp13_ = self->priv->_n;
	mind_map_set_current_node (map, _tmp13_);
	mind_map_queue_draw (map);
	mind_map_auto_save (map);
	_g_object_unref0 (parent);
}

static void
undo_node_summary_from_node_real_redo (UndoItem* base,
                                       MindMap* map)
{
	UndoNodeSummaryFromNode * self;
	Node* _tmp0_;
	Node* _tmp1_;
	NodeSide _tmp2_;
	NodeSide _tmp3_;
	SummaryNode* _tmp4_;
	SummaryNode* _tmp5_;
	self = (UndoNodeSummaryFromNode*) base;
	g_return_if_fail (map != NULL);
	_tmp0_ = self->priv->_n;
	_tmp1_ = self->priv->_n;
	_tmp2_ = node_get_side (_tmp1_);
	_tmp3_ = _tmp2_;
	node_detach (_tmp0_, _tmp3_);
	_tmp4_ = self->priv->_sn;
	summary_node_attach_all (_tmp4_);
	_tmp5_ = self->priv->_sn;
	mind_map_set_current_node (map, (Node*) _tmp5_);
	mind_map_queue_draw (map);
	mind_map_auto_save (map);
}

static void
undo_node_summary_from_node_class_init (UndoNodeSummaryFromNodeClass * klass,
                                        gpointer klass_data)
{
	undo_node_summary_from_node_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &UndoNodeSummaryFromNode_private_offset);
	((UndoItemClass *) klass)->undo = (void (*) (UndoItem*, MindMap*)) undo_node_summary_from_node_real_undo;
	((UndoItemClass *) klass)->redo = (void (*) (UndoItem*, MindMap*)) undo_node_summary_from_node_real_redo;
	G_OBJECT_CLASS (klass)->finalize = undo_node_summary_from_node_finalize;
}

static void
undo_node_summary_from_node_instance_init (UndoNodeSummaryFromNode * self,
                                           gpointer klass)
{
	self->priv = undo_node_summary_from_node_get_instance_private (self);
}

static void
undo_node_summary_from_node_finalize (GObject * obj)
{
	UndoNodeSummaryFromNode * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_UNDO_NODE_SUMMARY_FROM_NODE, UndoNodeSummaryFromNode);
	_g_object_unref0 (self->priv->_n);
	_g_object_unref0 (self->priv->_sn);
	G_OBJECT_CLASS (undo_node_summary_from_node_parent_class)->finalize (obj);
}

static GType
undo_node_summary_from_node_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (UndoNodeSummaryFromNodeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) undo_node_summary_from_node_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UndoNodeSummaryFromNode), 0, (GInstanceInitFunc) undo_node_summary_from_node_instance_init, NULL };
	GType undo_node_summary_from_node_type_id;
	undo_node_summary_from_node_type_id = g_type_register_static (TYPE_UNDO_ITEM, "UndoNodeSummaryFromNode", &g_define_type_info, 0);
	UndoNodeSummaryFromNode_private_offset = g_type_add_instance_private (undo_node_summary_from_node_type_id, sizeof (UndoNodeSummaryFromNodePrivate));
	return undo_node_summary_from_node_type_id;
}

GType
undo_node_summary_from_node_get_type (void)
{
	static volatile gsize undo_node_summary_from_node_type_id__once = 0;
	if (g_once_init_enter (&undo_node_summary_from_node_type_id__once)) {
		GType undo_node_summary_from_node_type_id;
		undo_node_summary_from_node_type_id = undo_node_summary_from_node_get_type_once ();
		g_once_init_leave (&undo_node_summary_from_node_type_id__once, undo_node_summary_from_node_type_id);
	}
	return undo_node_summary_from_node_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;
}

