/* ToolItem.c generated by valac 0.56.17, the Vala compiler
 * generated from ToolItem.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 <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_TOOL_ITEM_0_PROPERTY,
	BIRD_FONT_TOOL_ITEM_NUM_PROPERTIES
};
static GParamSpec* bird_font_tool_item_properties[BIRD_FONT_TOOL_ITEM_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block72Data Block72Data;
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _Block72Data {
	int _ref_count_;
	BirdFontToolItem* self;
	BirdFontTool* tool;
};

static gpointer bird_font_tool_item_parent_class = NULL;

static Block72Data* block72_data_ref (Block72Data* _data72_);
static void block72_data_unref (void * _userdata_);
static void __lambda147_ (Block72Data* _data72_);
static void ___lambda147__bird_font_menu_item_action (BirdFontMenuItem* _sender,
                                               gpointer self);
static void bird_font_tool_item_finalize (GObject * obj);
static GType bird_font_tool_item_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

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

static Block72Data*
block72_data_ref (Block72Data* _data72_)
{
	g_atomic_int_inc (&_data72_->_ref_count_);
	return _data72_;
}

static void
block72_data_unref (void * _userdata_)
{
	Block72Data* _data72_;
	_data72_ = (Block72Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data72_->_ref_count_)) {
		BirdFontToolItem* self;
		self = _data72_->self;
		_g_object_unref0 (_data72_->tool);
		_g_object_unref0 (self);
		g_slice_free (Block72Data, _data72_);
	}
}

static void
__lambda147_ (Block72Data* _data72_)
{
	BirdFontToolItem* self;
	self = _data72_->self;
	g_signal_emit_by_name (_data72_->tool, "select-action", _data72_->tool);
}

static void
___lambda147__bird_font_menu_item_action (BirdFontMenuItem* _sender,
                                          gpointer self)
{
	__lambda147_ (self);
}

BirdFontToolItem*
bird_font_tool_item_construct (GType object_type,
                               BirdFontTool* tool)
{
	BirdFontToolItem * self = NULL;
	Block72Data* _data72_;
	BirdFontTool* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	BirdFontTool* _tmp3_;
	g_return_val_if_fail (tool != NULL, NULL);
	_data72_ = g_slice_new0 (Block72Data);
	_data72_->_ref_count_ = 1;
	_tmp0_ = _g_object_ref0 (tool);
	_g_object_unref0 (_data72_->tool);
	_data72_->tool = _tmp0_;
	_tmp1_ = _data72_->tool->tip;
	_tmp2_ = _data72_->tool->name;
	self = (BirdFontToolItem*) bird_font_menu_item_construct (object_type, _tmp1_, _tmp2_);
	_data72_->self = g_object_ref (self);
	_tmp3_ = _g_object_ref0 (_data72_->tool);
	_g_object_unref0 (self->tool);
	self->tool = _tmp3_;
	g_signal_connect_data ((BirdFontMenuItem*) self, "action", (GCallback) ___lambda147__bird_font_menu_item_action, block72_data_ref (_data72_), (GClosureNotify) block72_data_unref, 0);
	block72_data_unref (_data72_);
	_data72_ = NULL;
	return self;
}

BirdFontToolItem*
bird_font_tool_item_new (BirdFontTool* tool)
{
	return bird_font_tool_item_construct (BIRD_FONT_TYPE_TOOL_ITEM, tool);
}

gchar*
bird_font_tool_item_get_key_binding (BirdFontToolItem* self)
{
	GString* sb = NULL;
	GString* _tmp0_;
	GString* _tmp12_;
	GString* _tmp13_;
	const gchar* _tmp14_;
	gchar* _tmp15_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_string_new ("");
	sb = _tmp0_;
	if (((BirdFontMenuItem*) self)->key == ((gunichar) '\0')) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup ("");
		result = _tmp1_;
		_g_string_free0 (sb);
		return result;
	}
	if ((((BirdFontMenuItem*) self)->modifiers & BIRD_FONT_CTRL) > ((guint) 0)) {
		GString* _tmp2_;
		GString* _tmp3_;
		_tmp2_ = sb;
		g_string_append (_tmp2_, "Ctrl");
		_tmp3_ = sb;
		g_string_append (_tmp3_, "+");
	}
	if ((((BirdFontMenuItem*) self)->modifiers & BIRD_FONT_SHIFT) > ((guint) 0)) {
		GString* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		GString* _tmp7_;
		_tmp4_ = sb;
		_tmp5_ = bird_font_t_ ("Shift");
		_tmp6_ = _tmp5_;
		g_string_append (_tmp4_, _tmp6_);
		_g_free0 (_tmp6_);
		_tmp7_ = sb;
		g_string_append (_tmp7_, "+");
	}
	if ((((BirdFontMenuItem*) self)->modifiers & BIRD_FONT_ALT) > ((guint) 0)) {
		GString* _tmp8_;
		GString* _tmp9_;
		_tmp8_ = sb;
		g_string_append (_tmp8_, "Alt");
		_tmp9_ = sb;
		g_string_append (_tmp9_, "+");
	}
	if ((((BirdFontMenuItem*) self)->modifiers & BIRD_FONT_LOGO) > ((guint) 0)) {
		GString* _tmp10_;
		GString* _tmp11_;
		_tmp10_ = sb;
		g_string_append (_tmp10_, "Super");
		_tmp11_ = sb;
		g_string_append (_tmp11_, "+");
	}
	_tmp12_ = sb;
	g_string_append_unichar (_tmp12_, ((BirdFontMenuItem*) self)->key);
	_tmp13_ = sb;
	_tmp14_ = _tmp13_->str;
	_tmp15_ = g_strdup (_tmp14_);
	result = _tmp15_;
	_g_string_free0 (sb);
	return result;
}

static void
bird_font_tool_item_class_init (BirdFontToolItemClass * klass,
                                gpointer klass_data)
{
	bird_font_tool_item_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = bird_font_tool_item_finalize;
}

static void
bird_font_tool_item_instance_init (BirdFontToolItem * self,
                                   gpointer klass)
{
}

static void
bird_font_tool_item_finalize (GObject * obj)
{
	BirdFontToolItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_TOOL_ITEM, BirdFontToolItem);
	_g_object_unref0 (self->tool);
	G_OBJECT_CLASS (bird_font_tool_item_parent_class)->finalize (obj);
}

static GType
bird_font_tool_item_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontToolItemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_tool_item_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontToolItem), 0, (GInstanceInitFunc) bird_font_tool_item_instance_init, NULL };
	GType bird_font_tool_item_type_id;
	bird_font_tool_item_type_id = g_type_register_static (BIRD_FONT_TYPE_MENU_ITEM, "BirdFontToolItem", &g_define_type_info, 0);
	return bird_font_tool_item_type_id;
}

GType
bird_font_tool_item_get_type (void)
{
	static volatile gsize bird_font_tool_item_type_id__once = 0;
	if (g_once_init_enter (&bird_font_tool_item_type_id__once)) {
		GType bird_font_tool_item_type_id;
		bird_font_tool_item_type_id = bird_font_tool_item_get_type_once ();
		g_once_init_leave (&bird_font_tool_item_type_id__once, bird_font_tool_item_type_id);
	}
	return bird_font_tool_item_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;
}

