/* UndoNodesLinkColor.c generated by valac 0.56.19, the Vala compiler
 * generated from UndoNodesLinkColor.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 <gdk/gdk.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_NODES_LINK_COLOR (undo_nodes_link_color_get_type ())
#define UNDO_NODES_LINK_COLOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_UNDO_NODES_LINK_COLOR, UndoNodesLinkColor))
#define UNDO_NODES_LINK_COLOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_UNDO_NODES_LINK_COLOR, UndoNodesLinkColorClass))
#define IS_UNDO_NODES_LINK_COLOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_UNDO_NODES_LINK_COLOR))
#define IS_UNDO_NODES_LINK_COLOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_UNDO_NODES_LINK_COLOR))
#define UNDO_NODES_LINK_COLOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_UNDO_NODES_LINK_COLOR, UndoNodesLinkColorClass))

typedef struct _UndoNodesLinkColor UndoNodesLinkColor;
typedef struct _UndoNodesLinkColorClass UndoNodesLinkColorClass;
typedef struct _UndoNodesLinkColorPrivate UndoNodesLinkColorPrivate;

#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_NODES_LINK_COLOR_0_PROPERTY,
	UNDO_NODES_LINK_COLOR_NUM_PROPERTIES
};
static GParamSpec* undo_nodes_link_color_properties[UNDO_NODES_LINK_COLOR_NUM_PROPERTIES];
#define _g_array_unref0(var) ((var == NULL) ? NULL : (var = (g_array_unref (var), NULL)))

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 _UndoNodesLinkColor {
	UndoItem parent_instance;
	UndoNodesLinkColorPrivate * priv;
};

struct _UndoNodesLinkColorClass {
	UndoItemClass parent_class;
};

struct _UndoNodesLinkColorPrivate {
	GArray* _nodes;
	GArray* _old_colors;
	GdkRGBA _new_color;
};

static gint UndoNodesLinkColor_private_offset;
static gpointer undo_nodes_link_color_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_nodes_link_color_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UndoNodesLinkColor, g_object_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 UndoNodesLinkColor* undo_nodes_link_color_new (GArray* nodes,
                                               GdkRGBA* new_color);
VALA_EXTERN UndoNodesLinkColor* undo_nodes_link_color_construct (GType object_type,
                                                     GArray* nodes,
                                                     GdkRGBA* new_color);
VALA_EXTERN UndoItem* undo_item_new (const gchar* name);
VALA_EXTERN UndoItem* undo_item_construct (GType object_type,
                               const gchar* name);
static void _g_object_unref0_ (gpointer var);
static void _vala_Node_free_function_content_of (gpointer data);
static void _vala_GdkRGBA_free (GdkRGBA* self);
static void __vala_GdkRGBA_free0_ (gpointer var);
static void _vala_GdkRGBA_free_function_content_of (gpointer data);
VALA_EXTERN GdkRGBA* node_get_link_color (Node* self);
static GdkRGBA* _vala_GdkRGBA_copy (GdkRGBA* self);
static void undo_nodes_link_color_real_undo (UndoItem* base,
                                      MindMap* map);
VALA_EXTERN void node_set_link_color (Node* self,
                          GdkRGBA* value);
VALA_EXTERN void mind_map_queue_draw (MindMap* self);
VALA_EXTERN void mind_map_auto_save (MindMap* self);
static void undo_nodes_link_color_real_redo (UndoItem* base,
                                      MindMap* map);
static void undo_nodes_link_color_finalize (GObject * obj);
static GType undo_nodes_link_color_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
undo_nodes_link_color_get_instance_private (UndoNodesLinkColor* self)
{
	return G_STRUCT_MEMBER_P (self, UndoNodesLinkColor_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 void
_vala_GdkRGBA_free (GdkRGBA* self)
{
	g_boxed_free (gdk_rgba_get_type (), self);
}

static void
__vala_GdkRGBA_free0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (_vala_GdkRGBA_free (var), NULL));
}

static void
_vala_GdkRGBA_free_function_content_of (gpointer data)
{
	GdkRGBA* self;
	self = *((GdkRGBA**) data);
	__vala_GdkRGBA_free0_ (self);
}

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

static GdkRGBA*
_vala_GdkRGBA_copy (GdkRGBA* self)
{
	return g_boxed_copy (gdk_rgba_get_type (), self);
}

static gpointer
__vala_GdkRGBA_copy0 (gpointer self)
{
	return self ? _vala_GdkRGBA_copy (self) : NULL;
}

UndoNodesLinkColor*
undo_nodes_link_color_construct (GType object_type,
                                 GArray* nodes,
                                 GdkRGBA* new_color)
{
	UndoNodesLinkColor * self = NULL;
	GArray* _tmp0_;
	GArray* _tmp1_;
	GdkRGBA _tmp12_;
	g_return_val_if_fail (nodes != NULL, NULL);
	g_return_val_if_fail (new_color != NULL, NULL);
	self = (UndoNodesLinkColor*) undo_item_construct (object_type, _ ("node link color changes"));
	_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 (GdkRGBA*));
	g_array_set_clear_func (_tmp1_, (GDestroyNotify) _vala_GdkRGBA_free_function_content_of);
	_g_array_unref0 (self->priv->_old_colors);
	self->priv->_old_colors = _tmp1_;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp2_ = FALSE;
			_tmp2_ = TRUE;
			while (TRUE) {
				GArray* _tmp4_;
				Node* _tmp5_;
				Node* _tmp6_;
				GArray* _tmp7_;
				Node* _tmp8_;
				GdkRGBA* _tmp9_;
				GdkRGBA* _tmp10_;
				GdkRGBA* _tmp11_;
				if (!_tmp2_) {
					gint _tmp3_;
					_tmp3_ = i;
					i = _tmp3_ + 1;
				}
				_tmp2_ = FALSE;
				if (!(((guint) i) < nodes->len)) {
					break;
				}
				_tmp4_ = self->priv->_nodes;
				_tmp5_ = g_array_index (nodes, Node*, (guint) i);
				_tmp6_ = _g_object_ref0 (_tmp5_);
				g_array_append_val (_tmp4_, _tmp6_);
				_tmp7_ = self->priv->_old_colors;
				_tmp8_ = g_array_index (nodes, Node*, (guint) i);
				_tmp9_ = node_get_link_color (_tmp8_);
				_tmp10_ = _tmp9_;
				_tmp11_ = __vala_GdkRGBA_copy0 (_tmp10_);
				g_array_append_val (_tmp7_, _tmp11_);
			}
		}
	}
	_tmp12_ = *new_color;
	self->priv->_new_color = _tmp12_;
	return self;
}

UndoNodesLinkColor*
undo_nodes_link_color_new (GArray* nodes,
                           GdkRGBA* new_color)
{
	return undo_nodes_link_color_construct (TYPE_UNDO_NODES_LINK_COLOR, nodes, new_color);
}

static void
undo_nodes_link_color_real_undo (UndoItem* base,
                                 MindMap* map)
{
	UndoNodesLinkColor * self;
	self = (UndoNodesLinkColor*) base;
	g_return_if_fail (map != NULL);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				GArray* _tmp2_;
				GArray* _tmp3_;
				Node* _tmp4_;
				GArray* _tmp5_;
				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_ = self->priv->_old_colors;
				node_set_link_color (_tmp4_, g_array_index (_tmp5_, GdkRGBA*, (guint) i));
			}
		}
	}
	mind_map_queue_draw (map);
	mind_map_auto_save (map);
}

static void
undo_nodes_link_color_real_redo (UndoItem* base,
                                 MindMap* map)
{
	UndoNodesLinkColor * self;
	self = (UndoNodesLinkColor*) base;
	g_return_if_fail (map != NULL);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				GArray* _tmp2_;
				GArray* _tmp3_;
				Node* _tmp4_;
				GdkRGBA _tmp5_;
				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_ = self->priv->_new_color;
				node_set_link_color (_tmp4_, &_tmp5_);
			}
		}
	}
	mind_map_queue_draw (map);
	mind_map_auto_save (map);
}

static void
undo_nodes_link_color_class_init (UndoNodesLinkColorClass * klass,
                                  gpointer klass_data)
{
	undo_nodes_link_color_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &UndoNodesLinkColor_private_offset);
	((UndoItemClass *) klass)->undo = (void (*) (UndoItem*, MindMap*)) undo_nodes_link_color_real_undo;
	((UndoItemClass *) klass)->redo = (void (*) (UndoItem*, MindMap*)) undo_nodes_link_color_real_redo;
	G_OBJECT_CLASS (klass)->finalize = undo_nodes_link_color_finalize;
}

static void
undo_nodes_link_color_instance_init (UndoNodesLinkColor * self,
                                     gpointer klass)
{
	self->priv = undo_nodes_link_color_get_instance_private (self);
}

static void
undo_nodes_link_color_finalize (GObject * obj)
{
	UndoNodesLinkColor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_UNDO_NODES_LINK_COLOR, UndoNodesLinkColor);
	_g_array_unref0 (self->priv->_nodes);
	_g_array_unref0 (self->priv->_old_colors);
	G_OBJECT_CLASS (undo_nodes_link_color_parent_class)->finalize (obj);
}

static GType
undo_nodes_link_color_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (UndoNodesLinkColorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) undo_nodes_link_color_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UndoNodesLinkColor), 0, (GInstanceInitFunc) undo_nodes_link_color_instance_init, NULL };
	GType undo_nodes_link_color_type_id;
	undo_nodes_link_color_type_id = g_type_register_static (TYPE_UNDO_ITEM, "UndoNodesLinkColor", &g_define_type_info, 0);
	UndoNodesLinkColor_private_offset = g_type_add_instance_private (undo_nodes_link_color_type_id, sizeof (UndoNodesLinkColorPrivate));
	return undo_nodes_link_color_type_id;
}

GType
undo_nodes_link_color_get_type (void)
{
	static volatile gsize undo_nodes_link_color_type_id__once = 0;
	if (g_once_init_enter (&undo_nodes_link_color_type_id__once)) {
		GType undo_nodes_link_color_type_id;
		undo_nodes_link_color_type_id = undo_nodes_link_color_get_type_once ();
		g_once_init_leave (&undo_nodes_link_color_type_id__once, undo_nodes_link_color_type_id);
	}
	return undo_nodes_link_color_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;
}

