/* SpacingTools.c generated by valac 0.56.17, the Vala compiler
 * generated from SpacingTools.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 <stdlib.h>
#include <string.h>
#include <glib.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_SPACING_TOOLS_0_PROPERTY,
	BIRD_FONT_SPACING_TOOLS_NUM_PROPERTIES
};
static GParamSpec* bird_font_spacing_tools_properties[BIRD_FONT_SPACING_TOOLS_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))
typedef struct _Block61Data Block61Data;

struct _Block61Data {
	int _ref_count_;
	BirdFontSpacingTools* self;
	BirdFontSpacingTab* d;
};

static gpointer bird_font_spacing_tools_parent_class = NULL;
GeeArrayList* bird_font_spacing_tools_expanders = NULL;
BirdFontZoomBar* bird_font_spacing_tools_zoom_bar = NULL;

static void __lambda232_ (BirdFontSpacingTools* self,
                   gdouble z);
static void ___lambda232__bird_font_zoom_bar_new_zoom (BirdFontZoomBar* _sender,
                                                gdouble zoom_level,
                                                gpointer self);
static void __lambda233_ (BirdFontSpacingTools* self,
                   BirdFontTool* _self_);
static Block61Data* block61_data_ref (Block61Data* _data61_);
static void block61_data_unref (void * _userdata_);
static void __lambda238_ (Block61Data* _data61_,
                   BirdFontGlyphCollection* gc);
static void ___lambda238__bird_font_glyph_selection_selected_glyph (BirdFontGlyphSelection* _sender,
                                                             BirdFontGlyphCollection* gc,
                                                             gpointer self);
static void ___lambda233__bird_font_tool_select_action (BirdFontTool* _sender,
                                                 BirdFontTool* selected,
                                                 gpointer self);
static void __lambda239_ (BirdFontSpacingTools* self,
                   BirdFontTool* _self_);
static void ___lambda239__bird_font_tool_select_action (BirdFontTool* _sender,
                                                 BirdFontTool* selected,
                                                 gpointer self);
static GeeArrayList* bird_font_spacing_tools_real_get_displays (BirdFontToolCollection* base);
static GeeArrayList* bird_font_spacing_tools_real_get_expanders (BirdFontToolCollection* base);
static void bird_font_spacing_tools_finalize (GObject * obj);
static GType bird_font_spacing_tools_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static gchar*
double_to_string (gdouble self)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint _tmp1__length1;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* result;
	_tmp0_ = g_new0 (gchar, G_ASCII_DTOSTR_BUF_SIZE);
	_tmp1_ = _tmp0_;
	_tmp1__length1 = G_ASCII_DTOSTR_BUF_SIZE;
	_tmp2_ = g_ascii_dtostr (_tmp1_, (gint) G_ASCII_DTOSTR_BUF_SIZE, self);
	_tmp3_ = g_strdup (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp1_ = (g_free (_tmp1_), NULL);
	result = _tmp4_;
	return result;
}

static void
__lambda232_ (BirdFontSpacingTools* self,
              gdouble z)
{
	BirdFontFont* f = NULL;
	BirdFontFont* _tmp0_;
	BirdFontFontSettings* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	bird_font_kerning_tools_font_size = 3 * z;
	if (bird_font_kerning_tools_font_size < 0.1) {
		bird_font_kerning_tools_font_size = 0.1;
	}
	_tmp0_ = bird_font_bird_font_get_current_font ();
	_g_object_unref0 (f);
	f = _tmp0_;
	_tmp1_ = f->settings;
	_tmp2_ = double_to_string (z);
	_tmp3_ = _tmp2_;
	bird_font_font_settings_set_setting (_tmp1_, "spacing_zoom", _tmp3_);
	_g_free0 (_tmp3_);
	bird_font_glyph_canvas_redraw ();
	_g_object_unref0 (f);
}

static void
___lambda232__bird_font_zoom_bar_new_zoom (BirdFontZoomBar* _sender,
                                           gdouble zoom_level,
                                           gpointer self)
{
	__lambda232_ ((BirdFontSpacingTools*) self, zoom_level);
}

static Block61Data*
block61_data_ref (Block61Data* _data61_)
{
	g_atomic_int_inc (&_data61_->_ref_count_);
	return _data61_;
}

static void
block61_data_unref (void * _userdata_)
{
	Block61Data* _data61_;
	_data61_ = (Block61Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data61_->_ref_count_)) {
		BirdFontSpacingTools* self;
		self = _data61_->self;
		_g_object_unref0 (_data61_->d);
		_g_object_unref0 (self);
		g_slice_free (Block61Data, _data61_);
	}
}

static void
__lambda238_ (Block61Data* _data61_,
              BirdFontGlyphCollection* gc)
{
	BirdFontSpacingTools* self;
	BirdFontGlyph* _tmp0_;
	BirdFontGlyph* _tmp1_;
	BirdFontTabBar* _tmp2_;
	BirdFontTabBar* _tmp3_;
	self = _data61_->self;
	g_return_if_fail (gc != NULL);
	_tmp0_ = bird_font_glyph_collection_get_current (gc);
	_tmp1_ = _tmp0_;
	bird_font_kerning_display_inser_glyph ((BirdFontKerningDisplay*) _data61_->d, _tmp1_);
	_g_object_unref0 (_tmp1_);
	_tmp2_ = bird_font_main_window_get_tab_bar ();
	_tmp3_ = _tmp2_;
	bird_font_tab_bar_select_tab_name (_tmp3_, "Spacing");
	_g_object_unref0 (_tmp3_);
}

static void
___lambda238__bird_font_glyph_selection_selected_glyph (BirdFontGlyphSelection* _sender,
                                                        BirdFontGlyphCollection* gc,
                                                        gpointer self)
{
	__lambda238_ (self, gc);
}

static void
__lambda233_ (BirdFontSpacingTools* self,
              BirdFontTool* _self_)
{
	Block61Data* _data61_;
	BirdFontSpacingTab* _tmp0_;
	BirdFontGlyphSelection* gs = NULL;
	BirdFontGlyphSelection* _tmp1_;
	g_return_if_fail (_self_ != NULL);
	_data61_ = g_slice_new0 (Block61Data);
	_data61_->_ref_count_ = 1;
	_data61_->self = g_object_ref (self);
	_tmp0_ = bird_font_main_window_get_spacing_tab ();
	_data61_->d = _tmp0_;
	_tmp1_ = bird_font_glyph_selection_new ();
	gs = _tmp1_;
	g_signal_connect_data (gs, "selected-glyph", (GCallback) ___lambda238__bird_font_glyph_selection_selected_glyph, block61_data_ref (_data61_), (GClosureNotify) block61_data_unref, 0);
	bird_font_glyph_canvas_set_display ((BirdFontFontDisplay*) gs);
	bird_font_tool_set_selected (_self_, FALSE);
	_g_object_unref0 (gs);
	block61_data_unref (_data61_);
	_data61_ = NULL;
}

static void
___lambda233__bird_font_tool_select_action (BirdFontTool* _sender,
                                            BirdFontTool* selected,
                                            gpointer self)
{
	__lambda233_ ((BirdFontSpacingTools*) self, selected);
}

static void
__lambda239_ (BirdFontSpacingTools* self,
              BirdFontTool* _self_)
{
	BirdFontSpacingTab* d = NULL;
	BirdFontSpacingTab* _tmp0_;
	g_return_if_fail (_self_ != NULL);
	_tmp0_ = bird_font_main_window_get_spacing_tab ();
	d = _tmp0_;
	bird_font_kerning_display_insert_unichar ((BirdFontKerningDisplay*) d);
	bird_font_tool_set_selected (_self_, FALSE);
	_g_object_unref0 (d);
}

static void
___lambda239__bird_font_tool_select_action (BirdFontTool* _sender,
                                            BirdFontTool* selected,
                                            gpointer self)
{
	__lambda239_ ((BirdFontSpacingTools*) self, selected);
}

BirdFontSpacingTools*
bird_font_spacing_tools_construct (GType object_type)
{
	BirdFontSpacingTools * self = NULL;
	GeeArrayList* _tmp0_;
	BirdFontExpander* font_name = NULL;
	BirdFontExpander* _tmp1_;
	BirdFontFontName* _tmp2_;
	BirdFontFontName* _tmp3_;
	BirdFontExpander* zoom_expander = NULL;
	gchar* _tmp4_;
	gchar* _tmp5_;
	BirdFontExpander* _tmp6_;
	BirdFontExpander* _tmp7_;
	BirdFontZoomBar* _tmp8_;
	BirdFontZoomBar* _tmp9_;
	BirdFontZoomBar* _tmp10_;
	BirdFontExpander* spacing_tools_expander = NULL;
	BirdFontExpander* _tmp11_;
	BirdFontTool* insert_last = NULL;
	gchar* _tmp12_;
	gchar* _tmp13_;
	BirdFontTool* _tmp14_;
	BirdFontTool* _tmp15_;
	BirdFontTool* insert_unicode = NULL;
	gchar* _tmp16_;
	gchar* _tmp17_;
	BirdFontTool* _tmp18_;
	BirdFontTool* _tmp19_;
	BirdFontTool* _tmp20_;
	BirdFontTool* _tmp21_;
	GeeArrayList* _tmp22_;
	GeeArrayList* _tmp23_;
	GeeArrayList* _tmp24_;
	self = (BirdFontSpacingTools*) bird_font_tool_collection_construct (object_type);
	_tmp0_ = gee_array_list_new (BIRD_FONT_TYPE_EXPANDER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (bird_font_spacing_tools_expanders);
	bird_font_spacing_tools_expanders = _tmp0_;
	_tmp1_ = bird_font_expander_new (NULL);
	font_name = _tmp1_;
	_tmp2_ = bird_font_font_name_new (NULL, "");
	_tmp3_ = _tmp2_;
	bird_font_expander_add_tool (font_name, (BirdFontTool*) _tmp3_, -1);
	_g_object_unref0 (_tmp3_);
	_tmp4_ = bird_font_t_ ("Font Size");
	_tmp5_ = _tmp4_;
	_tmp6_ = bird_font_expander_new (_tmp5_);
	_tmp7_ = _tmp6_;
	_g_free0 (_tmp5_);
	zoom_expander = _tmp7_;
	_tmp8_ = bird_font_zoom_bar_new ();
	_g_object_unref0 (bird_font_spacing_tools_zoom_bar);
	bird_font_spacing_tools_zoom_bar = _tmp8_;
	_tmp9_ = bird_font_spacing_tools_zoom_bar;
	g_signal_connect_object (_tmp9_, "new-zoom", (GCallback) ___lambda232__bird_font_zoom_bar_new_zoom, self, 0);
	_tmp10_ = bird_font_spacing_tools_zoom_bar;
	bird_font_expander_add_tool (zoom_expander, (BirdFontTool*) _tmp10_, -1);
	_tmp11_ = bird_font_expander_new (NULL);
	spacing_tools_expander = _tmp11_;
	_tmp12_ = bird_font_t_ ("Insert glyph from overview");
	_tmp13_ = _tmp12_;
	_tmp14_ = bird_font_tool_new ("insert_glyph_from_overview", _tmp13_);
	_tmp15_ = _tmp14_;
	_g_free0 (_tmp13_);
	insert_last = _tmp15_;
	g_signal_connect_object (insert_last, "select-action", (GCallback) ___lambda233__bird_font_tool_select_action, self, 0);
	bird_font_expander_add_tool (spacing_tools_expander, insert_last, -1);
	_tmp16_ = bird_font_t_ ("Insert character by unicode value");
	_tmp17_ = _tmp16_;
	_tmp18_ = bird_font_tool_new ("insert_unichar", _tmp17_);
	_tmp19_ = _tmp18_;
	_g_free0 (_tmp17_);
	insert_unicode = _tmp19_;
	g_signal_connect_object (insert_unicode, "select-action", (GCallback) ___lambda239__bird_font_tool_select_action, self, 0);
	bird_font_expander_add_tool (spacing_tools_expander, insert_unicode, -1);
	_tmp20_ = bird_font_kerning_tools_previous_kerning_string;
	bird_font_expander_add_tool (spacing_tools_expander, _tmp20_, -1);
	_tmp21_ = bird_font_kerning_tools_next_kerning_string;
	bird_font_expander_add_tool (spacing_tools_expander, _tmp21_, -1);
	_tmp22_ = bird_font_spacing_tools_expanders;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp22_, font_name);
	_tmp23_ = bird_font_spacing_tools_expanders;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp23_, zoom_expander);
	_tmp24_ = bird_font_spacing_tools_expanders;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp24_, spacing_tools_expander);
	_g_object_unref0 (insert_unicode);
	_g_object_unref0 (insert_last);
	_g_object_unref0 (spacing_tools_expander);
	_g_object_unref0 (zoom_expander);
	_g_object_unref0 (font_name);
	return self;
}

BirdFontSpacingTools*
bird_font_spacing_tools_new (void)
{
	return bird_font_spacing_tools_construct (BIRD_FONT_TYPE_SPACING_TOOLS);
}

static GeeArrayList*
bird_font_spacing_tools_real_get_displays (BirdFontToolCollection* base)
{
	BirdFontSpacingTools * self;
	GeeArrayList* d = NULL;
	GeeArrayList* _tmp0_;
	GeeArrayList* result;
	self = (BirdFontSpacingTools*) base;
	_tmp0_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
	d = _tmp0_;
	gee_abstract_collection_add ((GeeAbstractCollection*) d, "Spacing");
	result = d;
	return result;
}

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

static GeeArrayList*
bird_font_spacing_tools_real_get_expanders (BirdFontToolCollection* base)
{
	BirdFontSpacingTools * self;
	GeeArrayList* _tmp0_;
	GeeArrayList* _tmp1_;
	GeeArrayList* result;
	self = (BirdFontSpacingTools*) base;
	_tmp0_ = bird_font_spacing_tools_expanders;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	result = _tmp1_;
	return result;
}

static void
bird_font_spacing_tools_class_init (BirdFontSpacingToolsClass * klass,
                                    gpointer klass_data)
{
	bird_font_spacing_tools_parent_class = g_type_class_peek_parent (klass);
	((BirdFontToolCollectionClass *) klass)->get_displays = (GeeArrayList* (*) (BirdFontToolCollection*)) bird_font_spacing_tools_real_get_displays;
	((BirdFontToolCollectionClass *) klass)->get_expanders = (GeeArrayList* (*) (BirdFontToolCollection*)) bird_font_spacing_tools_real_get_expanders;
	G_OBJECT_CLASS (klass)->finalize = bird_font_spacing_tools_finalize;
}

static void
bird_font_spacing_tools_instance_init (BirdFontSpacingTools * self,
                                       gpointer klass)
{
}

static void
bird_font_spacing_tools_finalize (GObject * obj)
{
	BirdFontSpacingTools * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_SPACING_TOOLS, BirdFontSpacingTools);
	G_OBJECT_CLASS (bird_font_spacing_tools_parent_class)->finalize (obj);
}

static GType
bird_font_spacing_tools_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontSpacingToolsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_spacing_tools_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontSpacingTools), 0, (GInstanceInitFunc) bird_font_spacing_tools_instance_init, NULL };
	GType bird_font_spacing_tools_type_id;
	bird_font_spacing_tools_type_id = g_type_register_static (BIRD_FONT_TYPE_TOOL_COLLECTION, "BirdFontSpacingTools", &g_define_type_info, 0);
	return bird_font_spacing_tools_type_id;
}

GType
bird_font_spacing_tools_get_type (void)
{
	static volatile gsize bird_font_spacing_tools_type_id__once = 0;
	if (g_once_init_enter (&bird_font_spacing_tools_type_id__once)) {
		GType bird_font_spacing_tools_type_id;
		bird_font_spacing_tools_type_id = bird_font_spacing_tools_get_type_once ();
		g_once_init_leave (&bird_font_spacing_tools_type_id__once, bird_font_spacing_tools_type_id);
	}
	return bird_font_spacing_tools_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;
}

