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

/*
Copyright (C) 2013 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>
#include <float.h>
#include <math.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_LANGUAGE_SELECTION_TAB_0_PROPERTY,
	BIRD_FONT_LANGUAGE_SELECTION_TAB_NUM_PROPERTIES
};
static GParamSpec* bird_font_language_selection_tab_properties[BIRD_FONT_LANGUAGE_SELECTION_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))
#define _bird_font_glyph_range_unref0(var) ((var == NULL) ? NULL : (var = (bird_font_glyph_range_unref (var), NULL)))

static gpointer bird_font_language_selection_tab_parent_class = NULL;

static GeeArrayList* bird_font_language_selection_tab_real_get_rows (BirdFontTable* base);
static void bird_font_language_selection_tab_real_update_rows (BirdFontTable* base);
static void bird_font_language_selection_tab_real_selected_row (BirdFontTable* base,
                                                         BirdFontRow* row,
                                                         gint column,
                                                         gboolean delete_button);
static void bird_font_language_selection_tab_select_language (BirdFontLanguageSelectionTab* self,
                                                       gint row);
static gchar* bird_font_language_selection_tab_real_get_label (BirdFontFontDisplay* base);
static gchar* bird_font_language_selection_tab_real_get_name (BirdFontFontDisplay* base);
static GType bird_font_language_selection_tab_get_type_once (void);

BirdFontLanguageSelectionTab*
bird_font_language_selection_tab_construct (GType object_type)
{
	BirdFontLanguageSelectionTab * self = NULL;
	self = (BirdFontLanguageSelectionTab*) bird_font_table_construct (object_type);
	return self;
}

BirdFontLanguageSelectionTab*
bird_font_language_selection_tab_new (void)
{
	return bird_font_language_selection_tab_construct (BIRD_FONT_TYPE_LANGUAGE_SELECTION_TAB);
}

static GeeArrayList*
bird_font_language_selection_tab_real_get_rows (BirdFontTable* base)
{
	BirdFontLanguageSelectionTab * self;
	GeeArrayList* rows = NULL;
	GeeArrayList* _tmp0_;
	gint i = 0;
	GeeArrayList* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	BirdFontRow* _tmp4_;
	BirdFontRow* _tmp5_;
	GeeArrayList* result;
	self = (BirdFontLanguageSelectionTab*) base;
	_tmp0_ = gee_array_list_new (BIRD_FONT_TYPE_ROW, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	rows = _tmp0_;
	i = 0;
	_tmp1_ = rows;
	_tmp2_ = bird_font_t_ ("Character Sets");
	_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* _language_list = NULL;
		GeeArrayList* _tmp6_;
		gint _language_size = 0;
		GeeArrayList* _tmp7_;
		gint _tmp8_;
		gint _tmp9_;
		gint _language_index = 0;
		_tmp6_ = bird_font_default_languages_names;
		_language_list = _tmp6_;
		_tmp7_ = _language_list;
		_tmp8_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp7_);
		_tmp9_ = _tmp8_;
		_language_size = _tmp9_;
		_language_index = -1;
		while (TRUE) {
			gint _tmp10_;
			gint _tmp11_;
			gchar* language = NULL;
			GeeArrayList* _tmp12_;
			gpointer _tmp13_;
			BirdFontRow* r = NULL;
			const gchar* _tmp14_;
			BirdFontRow* _tmp15_;
			GeeArrayList* _tmp16_;
			BirdFontRow* _tmp17_;
			gint _tmp18_;
			_language_index = _language_index + 1;
			_tmp10_ = _language_index;
			_tmp11_ = _language_size;
			if (!(_tmp10_ < _tmp11_)) {
				break;
			}
			_tmp12_ = _language_list;
			_tmp13_ = gee_abstract_list_get ((GeeAbstractList*) _tmp12_, _language_index);
			language = (gchar*) _tmp13_;
			_tmp14_ = language;
			_tmp15_ = bird_font_row_new_columns_1 (_tmp14_, i, FALSE);
			r = _tmp15_;
			_tmp16_ = rows;
			_tmp17_ = r;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp16_, _tmp17_);
			_tmp18_ = i;
			i = _tmp18_ + 1;
			_g_object_unref0 (r);
			_g_free0 (language);
		}
	}
	result = rows;
	return result;
}

static void
bird_font_language_selection_tab_real_update_rows (BirdFontTable* base)
{
	BirdFontLanguageSelectionTab * self;
	BirdFontWidgetAllocation* _tmp0_;
	BirdFontWidgetAllocation* _tmp1_;
	self = (BirdFontLanguageSelectionTab*) base;
	_tmp0_ = ((BirdFontTable*) self)->allocation;
	_tmp1_ = ((BirdFontTable*) self)->allocation;
	g_signal_emit_by_name ((BirdFontFontDisplay*) self, "redraw-area", (gdouble) 0, (gdouble) 0, (gdouble) _tmp0_->width, (gdouble) _tmp1_->height);
}

static void
bird_font_language_selection_tab_real_selected_row (BirdFontTable* base,
                                                    BirdFontRow* row,
                                                    gint column,
                                                    gboolean delete_button)
{
	BirdFontLanguageSelectionTab * self;
	self = (BirdFontLanguageSelectionTab*) base;
	g_return_if_fail (row != NULL);
	bird_font_language_selection_tab_select_language (self, bird_font_row_get_index (row));
}

static void
bird_font_language_selection_tab_select_language (BirdFontLanguageSelectionTab* self,
                                                  gint row)
{
	gchar* iso_code = NULL;
	BirdFontOverview* overview = NULL;
	BirdFontGlyphRange* gr = NULL;
	BirdFontTabBar* tb = NULL;
	BirdFontTabBar* _tmp0_;
	GeeArrayList* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	GeeArrayList* _tmp5_;
	gpointer _tmp6_;
	BirdFontOverview* _tmp7_;
	BirdFontGlyphRange* _tmp8_;
	g_return_if_fail (self != NULL);
	_tmp0_ = bird_font_main_window_get_tab_bar ();
	tb = _tmp0_;
	_tmp1_ = bird_font_default_languages_codes;
	_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = row;
	g_return_if_fail ((0 <= _tmp4_) && (_tmp4_ < _tmp3_));
	_tmp5_ = bird_font_default_languages_codes;
	_tmp6_ = gee_abstract_list_get ((GeeAbstractList*) _tmp5_, row);
	_g_free0 (iso_code);
	iso_code = (gchar*) _tmp6_;
	bird_font_preferences_set ("language", iso_code);
	bird_font_tab_bar_close_display (tb, (BirdFontFontDisplay*) self);
	_tmp7_ = bird_font_main_window_get_overview ();
	_g_object_unref0 (overview);
	overview = _tmp7_;
	_tmp8_ = bird_font_glyph_range_new ();
	_bird_font_glyph_range_unref0 (gr);
	gr = _tmp8_;
	bird_font_default_character_set_use_default_range (gr);
	bird_font_overview_set_current_glyph_range (overview, gr);
	bird_font_overview_tools_update_overview_characterset (NULL);
	bird_font_font_display_dirty_scrollbar = TRUE;
	_g_object_unref0 (tb);
	_bird_font_glyph_range_unref0 (gr);
	_g_object_unref0 (overview);
	_g_free0 (iso_code);
}

static gchar*
bird_font_language_selection_tab_real_get_label (BirdFontFontDisplay* base)
{
	BirdFontLanguageSelectionTab * self;
	gchar* _tmp0_;
	gchar* result;
	self = (BirdFontLanguageSelectionTab*) base;
	_tmp0_ = bird_font_t_ ("Character Set");
	result = _tmp0_;
	return result;
}

static gchar*
bird_font_language_selection_tab_real_get_name (BirdFontFontDisplay* base)
{
	BirdFontLanguageSelectionTab * self;
	gchar* _tmp0_;
	gchar* result;
	self = (BirdFontLanguageSelectionTab*) base;
	_tmp0_ = g_strdup ("Character Set");
	result = _tmp0_;
	return result;
}

static void
bird_font_language_selection_tab_class_init (BirdFontLanguageSelectionTabClass * klass,
                                             gpointer klass_data)
{
	bird_font_language_selection_tab_parent_class = g_type_class_peek_parent (klass);
	((BirdFontTableClass *) klass)->get_rows = (GeeArrayList* (*) (BirdFontTable*)) bird_font_language_selection_tab_real_get_rows;
	((BirdFontTableClass *) klass)->update_rows = (void (*) (BirdFontTable*)) bird_font_language_selection_tab_real_update_rows;
	((BirdFontTableClass *) klass)->selected_row = (void (*) (BirdFontTable*, BirdFontRow*, gint, gboolean)) bird_font_language_selection_tab_real_selected_row;
	((BirdFontFontDisplayClass *) klass)->get_label = (gchar* (*) (BirdFontFontDisplay*)) bird_font_language_selection_tab_real_get_label;
	((BirdFontFontDisplayClass *) klass)->get_name = (gchar* (*) (BirdFontFontDisplay*)) bird_font_language_selection_tab_real_get_name;
}

static void
bird_font_language_selection_tab_instance_init (BirdFontLanguageSelectionTab * self,
                                                gpointer klass)
{
}

static GType
bird_font_language_selection_tab_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontLanguageSelectionTabClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_language_selection_tab_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontLanguageSelectionTab), 0, (GInstanceInitFunc) bird_font_language_selection_tab_instance_init, NULL };
	GType bird_font_language_selection_tab_type_id;
	bird_font_language_selection_tab_type_id = g_type_register_static (BIRD_FONT_TYPE_TABLE, "BirdFontLanguageSelectionTab", &g_define_type_info, 0);
	return bird_font_language_selection_tab_type_id;
}

GType
bird_font_language_selection_tab_get_type (void)
{
	static volatile gsize bird_font_language_selection_tab_type_id__once = 0;
	if (g_once_init_enter (&bird_font_language_selection_tab_type_id__once)) {
		GType bird_font_language_selection_tab_type_id;
		bird_font_language_selection_tab_type_id = bird_font_language_selection_tab_get_type_once ();
		g_once_init_leave (&bird_font_language_selection_tab_type_id__once, bird_font_language_selection_tab_type_id);
	}
	return bird_font_language_selection_tab_type_id__once;
}

