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

/*
Copyright (C) 2015 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_GUIDE_TAB_0_PROPERTY,
	BIRD_FONT_GUIDE_TAB_NUM_PROPERTIES
};
static GParamSpec* bird_font_guide_tab_properties[BIRD_FONT_GUIDE_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 _BirdFontGuideTabPrivate {
	GeeArrayList* rows;
};

static gint BirdFontGuideTab_private_offset;
static gpointer bird_font_guide_tab_parent_class = NULL;

static GeeArrayList* bird_font_guide_tab_real_get_rows (BirdFontTable* base);
static void bird_font_guide_tab_real_selected_row (BirdFontTable* base,
                                            BirdFontRow* row,
                                            gint column,
                                            gboolean delete_button);
static void bird_font_guide_tab_real_update_rows (BirdFontTable* base);
static gchar* bird_font_guide_tab_real_get_label (BirdFontFontDisplay* base);
static gchar* bird_font_guide_tab_real_get_name (BirdFontFontDisplay* base);
static void bird_font_guide_tab_finalize (GObject * obj);
static GType bird_font_guide_tab_get_type_once (void);

static inline gpointer
bird_font_guide_tab_get_instance_private (BirdFontGuideTab* self)
{
	return G_STRUCT_MEMBER_P (self, BirdFontGuideTab_private_offset);
}

BirdFontGuideTab*
bird_font_guide_tab_construct (GType object_type)
{
	BirdFontGuideTab * self = NULL;
	self = (BirdFontGuideTab*) bird_font_table_construct (object_type);
	return self;
}

BirdFontGuideTab*
bird_font_guide_tab_new (void)
{
	return bird_font_guide_tab_construct (BIRD_FONT_TYPE_GUIDE_TAB);
}

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

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

static void
bird_font_guide_tab_real_selected_row (BirdFontTable* base,
                                       BirdFontRow* row,
                                       gint column,
                                       gboolean delete_button)
{
	BirdFontGuideTab * self;
	BirdFontFont* font = NULL;
	BirdFontFont* _tmp0_;
	gint index = 0;
	self = (BirdFontGuideTab*) base;
	g_return_if_fail (row != NULL);
	_tmp0_ = bird_font_bird_font_get_current_font ();
	font = _tmp0_;
	index = bird_font_row_get_index (row);
	if (delete_button) {
		BirdFontFont* _tmp1_;
		GeeArrayList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		BirdFontFont* _tmp6_;
		BirdFontFont* _tmp7_;
		GeeArrayList* _tmp8_;
		gpointer _tmp9_;
		BirdFontLine* _tmp10_;
		_tmp1_ = font;
		_tmp2_ = _tmp1_->custom_guides;
		_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp2_);
		_tmp4_ = _tmp3_;
		_tmp5_ = index;
		g_return_if_fail ((0 <= _tmp5_) && (_tmp5_ < _tmp4_));
		_tmp6_ = bird_font_bird_font_get_current_font ();
		_tmp7_ = _tmp6_;
		_tmp8_ = _tmp7_->custom_guides;
		_tmp9_ = gee_abstract_list_remove_at ((GeeAbstractList*) _tmp8_, index);
		_tmp10_ = (BirdFontLine*) _tmp9_;
		_g_object_unref0 (_tmp10_);
		_g_object_unref0 (_tmp7_);
		bird_font_table_update_rows ((BirdFontTable*) self);
	}
	_g_object_unref0 (font);
}

static void
bird_font_guide_tab_real_update_rows (BirdFontTable* base)
{
	BirdFontGuideTab * self;
	gint i = 0;
	GeeArrayList* _tmp0_;
	GeeArrayList* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	BirdFontRow* _tmp4_;
	BirdFontRow* _tmp5_;
	self = (BirdFontGuideTab*) base;
	i = 0;
	_tmp0_ = self->priv->rows;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp0_);
	_tmp1_ = self->priv->rows;
	_tmp2_ = bird_font_t_ ("Guides");
	_tmp3_ = _tmp2_;
	_tmp4_ = bird_font_row_new_headline (_tmp3_);
	_tmp5_ = _tmp4_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp1_, _tmp5_);
	_g_object_unref0 (_tmp5_);
	_g_free0 (_tmp3_);
	{
		GeeArrayList* _guide_list = NULL;
		BirdFontFont* _tmp6_;
		BirdFontFont* _tmp7_;
		GeeArrayList* _tmp8_;
		GeeArrayList* _tmp9_;
		gint _guide_size = 0;
		GeeArrayList* _tmp10_;
		gint _tmp11_;
		gint _tmp12_;
		gint _guide_index = 0;
		_tmp6_ = bird_font_bird_font_get_current_font ();
		_tmp7_ = _tmp6_;
		_tmp8_ = _tmp7_->custom_guides;
		_tmp9_ = _tmp8_;
		_g_object_unref0 (_tmp7_);
		_guide_list = _tmp9_;
		_tmp10_ = _guide_list;
		_tmp11_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp10_);
		_tmp12_ = _tmp11_;
		_guide_size = _tmp12_;
		_guide_index = -1;
		while (TRUE) {
			gint _tmp13_;
			gint _tmp14_;
			BirdFontLine* guide = NULL;
			GeeArrayList* _tmp15_;
			gpointer _tmp16_;
			GeeArrayList* _tmp17_;
			BirdFontLine* _tmp18_;
			const gchar* _tmp19_;
			BirdFontRow* _tmp20_;
			BirdFontRow* _tmp21_;
			gint _tmp22_;
			_guide_index = _guide_index + 1;
			_tmp13_ = _guide_index;
			_tmp14_ = _guide_size;
			if (!(_tmp13_ < _tmp14_)) {
				break;
			}
			_tmp15_ = _guide_list;
			_tmp16_ = gee_abstract_list_get ((GeeAbstractList*) _tmp15_, _guide_index);
			guide = (BirdFontLine*) _tmp16_;
			_tmp17_ = self->priv->rows;
			_tmp18_ = guide;
			_tmp19_ = _tmp18_->label;
			_tmp20_ = bird_font_row_new_columns_1 (_tmp19_, i, TRUE);
			_tmp21_ = _tmp20_;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp17_, _tmp21_);
			_g_object_unref0 (_tmp21_);
			_tmp22_ = i;
			i = _tmp22_ + 1;
			_g_object_unref0 (guide);
		}
	}
	bird_font_glyph_canvas_redraw ();
}

static gchar*
bird_font_guide_tab_real_get_label (BirdFontFontDisplay* base)
{
	BirdFontGuideTab * self;
	gchar* _tmp0_;
	gchar* result;
	self = (BirdFontGuideTab*) base;
	_tmp0_ = bird_font_t_ ("Guides");
	result = _tmp0_;
	return result;
}

static gchar*
bird_font_guide_tab_real_get_name (BirdFontFontDisplay* base)
{
	BirdFontGuideTab * self;
	gchar* _tmp0_;
	gchar* result;
	self = (BirdFontGuideTab*) base;
	_tmp0_ = g_strdup ("Guides");
	result = _tmp0_;
	return result;
}

static void
bird_font_guide_tab_class_init (BirdFontGuideTabClass * klass,
                                gpointer klass_data)
{
	bird_font_guide_tab_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BirdFontGuideTab_private_offset);
	((BirdFontTableClass *) klass)->get_rows = (GeeArrayList* (*) (BirdFontTable*)) bird_font_guide_tab_real_get_rows;
	((BirdFontTableClass *) klass)->selected_row = (void (*) (BirdFontTable*, BirdFontRow*, gint, gboolean)) bird_font_guide_tab_real_selected_row;
	((BirdFontTableClass *) klass)->update_rows = (void (*) (BirdFontTable*)) bird_font_guide_tab_real_update_rows;
	((BirdFontFontDisplayClass *) klass)->get_label = (gchar* (*) (BirdFontFontDisplay*)) bird_font_guide_tab_real_get_label;
	((BirdFontFontDisplayClass *) klass)->get_name = (gchar* (*) (BirdFontFontDisplay*)) bird_font_guide_tab_real_get_name;
	G_OBJECT_CLASS (klass)->finalize = bird_font_guide_tab_finalize;
}

static void
bird_font_guide_tab_instance_init (BirdFontGuideTab * self,
                                   gpointer klass)
{
	GeeArrayList* _tmp0_;
	self->priv = bird_font_guide_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_guide_tab_finalize (GObject * obj)
{
	BirdFontGuideTab * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_GUIDE_TAB, BirdFontGuideTab);
	_g_object_unref0 (self->priv->rows);
	G_OBJECT_CLASS (bird_font_guide_tab_parent_class)->finalize (obj);
}

static GType
bird_font_guide_tab_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontGuideTabClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_guide_tab_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontGuideTab), 0, (GInstanceInitFunc) bird_font_guide_tab_instance_init, NULL };
	GType bird_font_guide_tab_type_id;
	bird_font_guide_tab_type_id = g_type_register_static (BIRD_FONT_TYPE_TABLE, "BirdFontGuideTab", &g_define_type_info, 0);
	BirdFontGuideTab_private_offset = g_type_add_instance_private (bird_font_guide_tab_type_id, sizeof (BirdFontGuideTabPrivate));
	return bird_font_guide_tab_type_id;
}

GType
bird_font_guide_tab_get_type (void)
{
	static volatile gsize bird_font_guide_tab_type_id__once = 0;
	if (g_once_init_enter (&bird_font_guide_tab_type_id__once)) {
		GType bird_font_guide_tab_type_id;
		bird_font_guide_tab_type_id = bird_font_guide_tab_get_type_once ();
		g_once_init_leave (&bird_font_guide_tab_type_id__once, bird_font_guide_tab_type_id);
	}
	return bird_font_guide_tab_type_id__once;
}

