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

/*
Copyright (C) 2014 Johan Mattsson

This library is free software; you can redistribute it and/or modify 
it under the terms of the GNU Lesser General Public License as 
published by the Free Software Foundation; either version 3 of the 
License, or (at your option) any later version.

This library 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 
Lesser General Public License for more details.
*/

#include "birdfont.h"
#include <gee.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.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

enum  {
	BIRD_FONT_SPACING_CLASS_TAB_0_PROPERTY,
	BIRD_FONT_SPACING_CLASS_TAB_NUM_PROPERTIES
};
static GParamSpec* bird_font_spacing_class_tab_properties[BIRD_FONT_SPACING_CLASS_TAB_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _BirdFontSpacingClassTabPrivate {
	GeeArrayList* rows;
};

static gint BirdFontSpacingClassTab_private_offset;
static gpointer bird_font_spacing_class_tab_parent_class = NULL;
gint bird_font_spacing_class_tab_NEW_CLASS = -1;
BirdFontSpacingClass* bird_font_spacing_class_tab_current_class = NULL;
gboolean bird_font_spacing_class_tab_current_class_first_element = FALSE;

static GeeArrayList* bird_font_spacing_class_tab_real_get_rows (BirdFontTable* base);
static void bird_font_spacing_class_tab_real_selected_row (BirdFontTable* base,
                                                    BirdFontRow* row,
                                                    gint column,
                                                    gboolean delete_button);
static void bird_font_spacing_class_tab_real_update_rows (BirdFontTable* base);
static gchar* bird_font_spacing_class_tab_real_get_label (BirdFontFontDisplay* base);
static gchar* bird_font_spacing_class_tab_real_get_name (BirdFontFontDisplay* base);
static void bird_font_spacing_class_tab_finalize (GObject * obj);
static GType bird_font_spacing_class_tab_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
bird_font_spacing_class_tab_get_instance_private (BirdFontSpacingClassTab* self)
{
	return G_STRUCT_MEMBER_P (self, BirdFontSpacingClassTab_private_offset);
}

BirdFontSpacingClassTab*
bird_font_spacing_class_tab_construct (GType object_type)
{
	BirdFontSpacingClassTab * self = NULL;
	BirdFontSpacingClass* _tmp0_;
	self = (BirdFontSpacingClassTab*) bird_font_table_construct (object_type);
	_tmp0_ = bird_font_spacingclass_new ("", "");
	_g_object_unref0 (bird_font_spacing_class_tab_current_class);
	bird_font_spacing_class_tab_current_class = _tmp0_;
	return self;
}

BirdFontSpacingClassTab*
bird_font_spacing_class_tab_new (void)
{
	return bird_font_spacing_class_tab_construct (BIRD_FONT_TYPE_SPACING_CLASS_TAB);
}

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

static GeeArrayList*
bird_font_spacing_class_tab_real_get_rows (BirdFontTable* base)
{
	BirdFontSpacingClassTab * self;
	GeeArrayList* _tmp0_;
	GeeArrayList* _tmp1_;
	GeeArrayList* result;
	self = (BirdFontSpacingClassTab*) base;
	_tmp0_ = self->priv->rows;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	result = _tmp1_;
	return result;
}

void
bird_font_spacing_class_tab_set_class (const gchar* glyph)
{
	BirdFontSpacingClassTab* _tmp4_;
	BirdFontSpacingClassTab* _tmp5_;
	g_return_if_fail (glyph != NULL);
	if (bird_font_spacing_class_tab_current_class_first_element) {
		BirdFontSpacingClass* _tmp0_;
		gchar* _tmp1_;
		_tmp0_ = bird_font_spacing_class_tab_current_class;
		_tmp1_ = g_strdup (glyph);
		_g_free0 (_tmp0_->first);
		_tmp0_->first = _tmp1_;
	} else {
		BirdFontSpacingClass* _tmp2_;
		gchar* _tmp3_;
		_tmp2_ = bird_font_spacing_class_tab_current_class;
		_tmp3_ = g_strdup (glyph);
		_g_free0 (_tmp2_->next);
		_tmp2_->next = _tmp3_;
	}
	_tmp4_ = bird_font_main_window_get_spacing_class_tab ();
	_tmp5_ = _tmp4_;
	bird_font_table_update_rows ((BirdFontTable*) _tmp5_);
	_g_object_unref0 (_tmp5_);
}

static void
bird_font_spacing_class_tab_real_selected_row (BirdFontTable* base,
                                               BirdFontRow* row,
                                               gint column,
                                               gboolean delete_button)
{
	BirdFontSpacingClassTab * self;
	BirdFontFont* font = NULL;
	BirdFontFont* _tmp0_;
	BirdFontSpacingData* spacing = NULL;
	BirdFontFont* _tmp1_;
	BirdFontSpacingData* _tmp2_;
	self = (BirdFontSpacingClassTab*) base;
	g_return_if_fail (row != NULL);
	_tmp0_ = bird_font_bird_font_get_current_font ();
	font = _tmp0_;
	_tmp1_ = font;
	_tmp2_ = bird_font_font_get_spacing (_tmp1_);
	spacing = _tmp2_;
	if (bird_font_row_get_index (row) == -1) {
		BirdFontSpacingData* _tmp3_;
		BirdFontFont* _tmp4_;
		_tmp3_ = spacing;
		bird_font_spacing_data_add_class (_tmp3_, "?", "?");
		bird_font_tab_content_hide_text_input ();
		bird_font_table_update_rows ((BirdFontTable*) self);
		bird_font_font_display_update_scrollbar ((BirdFontFontDisplay*) self);
		_tmp4_ = font;
		bird_font_font_touch (_tmp4_);
	} else {
		BirdFontSpacingData* _tmp5_;
		GeeArrayList* _tmp6_;
		gint _tmp7_;
		gint _tmp8_;
		_tmp5_ = spacing;
		_tmp6_ = _tmp5_->classes;
		_tmp7_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp6_);
		_tmp8_ = _tmp7_;
		if (_tmp8_ != 0) {
			if (delete_button) {
				BirdFontSpacingData* _tmp9_;
				GeeArrayList* _tmp10_;
				gint _tmp11_;
				gint _tmp12_;
				gint _tmp13_;
				BirdFontSpacingData* _tmp14_;
				GeeArrayList* _tmp15_;
				gpointer _tmp16_;
				BirdFontSpacingClass* _tmp17_;
				BirdFontFont* _tmp18_;
				_tmp9_ = spacing;
				_tmp10_ = _tmp9_->classes;
				_tmp11_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp10_);
				_tmp12_ = _tmp11_;
				_tmp13_ = bird_font_row_get_index (row);
				g_return_if_fail ((0 <= _tmp13_) && (_tmp13_ < _tmp12_));
				_tmp14_ = spacing;
				_tmp15_ = _tmp14_->classes;
				_tmp16_ = gee_abstract_list_remove_at ((GeeAbstractList*) _tmp15_, bird_font_row_get_index (row));
				_tmp17_ = (BirdFontSpacingClass*) _tmp16_;
				_g_object_unref0 (_tmp17_);
				bird_font_tab_content_hide_text_input ();
				bird_font_table_update_rows ((BirdFontTable*) self);
				bird_font_font_display_update_scrollbar ((BirdFontFontDisplay*) self);
				_tmp18_ = font;
				bird_font_font_touch (_tmp18_);
			} else {
				if (column == 0) {
					BirdFontSpacingData* _tmp19_;
					GeeArrayList* _tmp20_;
					gint _tmp21_;
					gint _tmp22_;
					gint _tmp23_;
					BirdFontSpacingData* _tmp34_;
					GeeArrayList* _tmp35_;
					gpointer _tmp36_;
					BirdFontSpacingClass* _tmp37_;
					BirdFontFont* _tmp38_;
					_tmp19_ = spacing;
					_tmp20_ = _tmp19_->classes;
					_tmp21_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp20_);
					_tmp22_ = _tmp21_;
					_tmp23_ = bird_font_row_get_index (row);
					if (!((0 <= _tmp23_) && (_tmp23_ < _tmp22_))) {
						gchar* _tmp24_;
						gchar* _tmp25_;
						BirdFontSpacingData* _tmp26_;
						GeeArrayList* _tmp27_;
						gint _tmp28_;
						gint _tmp29_;
						gchar* _tmp30_;
						gchar* _tmp31_;
						gchar* _tmp32_;
						gchar* _tmp33_;
						_tmp24_ = g_strdup_printf ("%i", bird_font_row_get_index (row));
						_tmp25_ = _tmp24_;
						_tmp26_ = spacing;
						_tmp27_ = _tmp26_->classes;
						_tmp28_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp27_);
						_tmp29_ = _tmp28_;
						_tmp30_ = g_strdup_printf ("%i", _tmp29_);
						_tmp31_ = _tmp30_;
						_tmp32_ = g_strconcat ("Index: ", _tmp25_, " classes.size: ", _tmp31_, NULL);
						_tmp33_ = _tmp32_;
						g_warning ("SpacingClassTab.vala:64: %s", _tmp33_);
						_g_free0 (_tmp33_);
						_g_free0 (_tmp31_);
						_g_free0 (_tmp25_);
						_g_object_unref0 (spacing);
						_g_object_unref0 (font);
						return;
					}
					_tmp34_ = spacing;
					_tmp35_ = _tmp34_->classes;
					_tmp36_ = gee_abstract_list_get ((GeeAbstractList*) _tmp35_, bird_font_row_get_index (row));
					_g_object_unref0 (bird_font_spacing_class_tab_current_class);
					bird_font_spacing_class_tab_current_class = (BirdFontSpacingClass*) _tmp36_;
					_tmp37_ = bird_font_spacing_class_tab_current_class;
					bird_font_spacingclass_set_first (_tmp37_);
					bird_font_spacing_class_tab_current_class_first_element = TRUE;
					_tmp38_ = font;
					bird_font_font_touch (_tmp38_);
				} else {
					if (column == 2) {
						BirdFontSpacingData* _tmp39_;
						GeeArrayList* _tmp40_;
						gint _tmp41_;
						gint _tmp42_;
						gint _tmp43_;
						BirdFontSpacingData* _tmp44_;
						GeeArrayList* _tmp45_;
						gpointer _tmp46_;
						BirdFontSpacingClass* _tmp47_;
						BirdFontFont* _tmp48_;
						_tmp39_ = spacing;
						_tmp40_ = _tmp39_->classes;
						_tmp41_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp40_);
						_tmp42_ = _tmp41_;
						_tmp43_ = bird_font_row_get_index (row);
						g_return_if_fail ((0 <= _tmp43_) && (_tmp43_ < _tmp42_));
						_tmp44_ = spacing;
						_tmp45_ = _tmp44_->classes;
						_tmp46_ = gee_abstract_list_get ((GeeAbstractList*) _tmp45_, bird_font_row_get_index (row));
						_g_object_unref0 (bird_font_spacing_class_tab_current_class);
						bird_font_spacing_class_tab_current_class = (BirdFontSpacingClass*) _tmp46_;
						_tmp47_ = bird_font_spacing_class_tab_current_class;
						bird_font_spacingclass_set_next (_tmp47_);
						bird_font_spacing_class_tab_current_class_first_element = FALSE;
						_tmp48_ = font;
						bird_font_font_touch (_tmp48_);
					}
				}
			}
		}
	}
	_g_object_unref0 (spacing);
	_g_object_unref0 (font);
}

static const gchar*
string_to_string (const gchar* self)
{
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}

static void
bird_font_spacing_class_tab_real_update_rows (BirdFontTable* base)
{
	BirdFontSpacingClassTab * self;
	gint i = 0;
	BirdFontSpacingData* spacing = NULL;
	BirdFontFont* _tmp0_;
	BirdFontFont* _tmp1_;
	BirdFontSpacingData* _tmp2_;
	BirdFontSpacingData* _tmp3_;
	GeeArrayList* _tmp4_;
	GeeArrayList* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	BirdFontRow* _tmp8_;
	BirdFontRow* _tmp9_;
	self = (BirdFontSpacingClassTab*) base;
	i = 0;
	_tmp0_ = bird_font_bird_font_get_current_font ();
	_tmp1_ = _tmp0_;
	_tmp2_ = bird_font_font_get_spacing (_tmp1_);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp1_);
	spacing = _tmp3_;
	_tmp4_ = self->priv->rows;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp4_);
	_tmp5_ = self->priv->rows;
	_tmp6_ = bird_font_t_ ("New spacing class");
	_tmp7_ = _tmp6_;
	_tmp8_ = bird_font_row_new (_tmp7_, bird_font_spacing_class_tab_NEW_CLASS, FALSE);
	_tmp9_ = _tmp8_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp5_, _tmp9_);
	_g_object_unref0 (_tmp9_);
	_g_free0 (_tmp7_);
	{
		GeeArrayList* _c_list = NULL;
		BirdFontSpacingData* _tmp10_;
		GeeArrayList* _tmp11_;
		gint _c_size = 0;
		GeeArrayList* _tmp12_;
		gint _tmp13_;
		gint _tmp14_;
		gint _c_index = 0;
		_tmp10_ = spacing;
		_tmp11_ = _tmp10_->classes;
		_c_list = _tmp11_;
		_tmp12_ = _c_list;
		_tmp13_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp12_);
		_tmp14_ = _tmp13_;
		_c_size = _tmp14_;
		_c_index = -1;
		while (TRUE) {
			gint _tmp15_;
			gint _tmp16_;
			BirdFontSpacingClass* c = NULL;
			GeeArrayList* _tmp17_;
			gpointer _tmp18_;
			GeeArrayList* _tmp19_;
			BirdFontSpacingClass* _tmp20_;
			const gchar* _tmp21_;
			const gchar* _tmp22_;
			BirdFontSpacingClass* _tmp23_;
			const gchar* _tmp24_;
			const gchar* _tmp25_;
			BirdFontRow* _tmp26_;
			BirdFontRow* _tmp27_;
			gint _tmp28_;
			_c_index = _c_index + 1;
			_tmp15_ = _c_index;
			_tmp16_ = _c_size;
			if (!(_tmp15_ < _tmp16_)) {
				break;
			}
			_tmp17_ = _c_list;
			_tmp18_ = gee_abstract_list_get ((GeeAbstractList*) _tmp17_, _c_index);
			c = (BirdFontSpacingClass*) _tmp18_;
			_tmp19_ = self->priv->rows;
			_tmp20_ = c;
			_tmp21_ = _tmp20_->first;
			_tmp22_ = string_to_string (_tmp21_);
			_tmp23_ = c;
			_tmp24_ = _tmp23_->next;
			_tmp25_ = string_to_string (_tmp24_);
			_tmp26_ = bird_font_row_new_columns_3 (_tmp22_, "->", _tmp25_, i, TRUE);
			_tmp27_ = _tmp26_;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp19_, _tmp27_);
			_g_object_unref0 (_tmp27_);
			_tmp28_ = i;
			i = _tmp28_ + 1;
			_g_object_unref0 (c);
		}
	}
	bird_font_glyph_canvas_redraw ();
	_g_object_unref0 (spacing);
}

static gchar*
bird_font_spacing_class_tab_real_get_label (BirdFontFontDisplay* base)
{
	BirdFontSpacingClassTab * self;
	gchar* _tmp0_;
	gchar* result;
	self = (BirdFontSpacingClassTab*) base;
	_tmp0_ = bird_font_t_ ("Spacing Classes");
	result = _tmp0_;
	return result;
}

static gchar*
bird_font_spacing_class_tab_real_get_name (BirdFontFontDisplay* base)
{
	BirdFontSpacingClassTab * self;
	gchar* _tmp0_;
	gchar* result;
	self = (BirdFontSpacingClassTab*) base;
	_tmp0_ = g_strdup ("SpacingClasses");
	result = _tmp0_;
	return result;
}

static void
bird_font_spacing_class_tab_class_init (BirdFontSpacingClassTabClass * klass,
                                        gpointer klass_data)
{
	bird_font_spacing_class_tab_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BirdFontSpacingClassTab_private_offset);
	((BirdFontTableClass *) klass)->get_rows = (GeeArrayList* (*) (BirdFontTable*)) bird_font_spacing_class_tab_real_get_rows;
	((BirdFontTableClass *) klass)->selected_row = (void (*) (BirdFontTable*, BirdFontRow*, gint, gboolean)) bird_font_spacing_class_tab_real_selected_row;
	((BirdFontTableClass *) klass)->update_rows = (void (*) (BirdFontTable*)) bird_font_spacing_class_tab_real_update_rows;
	((BirdFontFontDisplayClass *) klass)->get_label = (gchar* (*) (BirdFontFontDisplay*)) bird_font_spacing_class_tab_real_get_label;
	((BirdFontFontDisplayClass *) klass)->get_name = (gchar* (*) (BirdFontFontDisplay*)) bird_font_spacing_class_tab_real_get_name;
	G_OBJECT_CLASS (klass)->finalize = bird_font_spacing_class_tab_finalize;
}

static void
bird_font_spacing_class_tab_instance_init (BirdFontSpacingClassTab * self,
                                           gpointer klass)
{
	GeeArrayList* _tmp0_;
	self->priv = bird_font_spacing_class_tab_get_instance_private (self);
	_tmp0_ = gee_array_list_new (BIRD_FONT_TYPE_ROW, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->priv->rows = _tmp0_;
}

static void
bird_font_spacing_class_tab_finalize (GObject * obj)
{
	BirdFontSpacingClassTab * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_SPACING_CLASS_TAB, BirdFontSpacingClassTab);
	_g_object_unref0 (self->priv->rows);
	G_OBJECT_CLASS (bird_font_spacing_class_tab_parent_class)->finalize (obj);
}

static GType
bird_font_spacing_class_tab_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontSpacingClassTabClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_spacing_class_tab_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontSpacingClassTab), 0, (GInstanceInitFunc) bird_font_spacing_class_tab_instance_init, NULL };
	GType bird_font_spacing_class_tab_type_id;
	bird_font_spacing_class_tab_type_id = g_type_register_static (BIRD_FONT_TYPE_TABLE, "BirdFontSpacingClassTab", &g_define_type_info, 0);
	BirdFontSpacingClassTab_private_offset = g_type_add_instance_private (bird_font_spacing_class_tab_type_id, sizeof (BirdFontSpacingClassTabPrivate));
	return bird_font_spacing_class_tab_type_id;
}

GType
bird_font_spacing_class_tab_get_type (void)
{
	static volatile gsize bird_font_spacing_class_tab_type_id__once = 0;
	if (g_once_init_enter (&bird_font_spacing_class_tab_type_id__once)) {
		GType bird_font_spacing_class_tab_type_id;
		bird_font_spacing_class_tab_type_id = bird_font_spacing_class_tab_get_type_once ();
		g_once_init_leave (&bird_font_spacing_class_tab_type_id__once, bird_font_spacing_class_tab_type_id);
	}
	return bird_font_spacing_class_tab_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;
}

