/* MenuItem.c generated by valac 0.56.17, the Vala compiler
 * generated from MenuItem.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.h>
#include <gee.h>
#include <glib-object.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_MENU_ITEM_0_PROPERTY,
	BIRD_FONT_MENU_ITEM_NUM_PROPERTIES
};
static GParamSpec* bird_font_menu_item_properties[BIRD_FONT_MENU_ITEM_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))
enum  {
	BIRD_FONT_MENU_ITEM_ACTION_SIGNAL,
	BIRD_FONT_MENU_ITEM_NUM_SIGNALS
};
static guint bird_font_menu_item_signals[BIRD_FONT_MENU_ITEM_NUM_SIGNALS] = {0};

static gpointer bird_font_menu_item_parent_class = NULL;

static void bird_font_menu_item_finalize (GObject * obj);
static GType bird_font_menu_item_get_type_once (void);

BirdFontMenuItem*
bird_font_menu_item_construct (GType object_type,
                               const gchar* label,
                               const gchar* identifier)
{
	BirdFontMenuItem * self = NULL;
	BirdFontText* _tmp0_;
	BirdFontText* _tmp1_;
	gchar* _tmp2_;
	g_return_val_if_fail (label != NULL, NULL);
	g_return_val_if_fail (identifier != NULL, NULL);
	self = (BirdFontMenuItem*) g_object_new (object_type, NULL);
	_tmp0_ = bird_font_text_new ("", (gdouble) 17, (gdouble) 0);
	_g_object_unref0 (self->label);
	self->label = _tmp0_;
	_tmp1_ = self->label;
	bird_font_text_set_text (_tmp1_, label);
	_tmp2_ = g_strdup (identifier);
	_g_free0 (self->identifier);
	self->identifier = _tmp2_;
	self->y = (gdouble) 0;
	return self;
}

BirdFontMenuItem*
bird_font_menu_item_new (const gchar* label,
                         const gchar* identifier)
{
	return bird_font_menu_item_construct (BIRD_FONT_TYPE_MENU_ITEM, label, identifier);
}

void
bird_font_menu_item_add_display (BirdFontMenuItem* self,
                                 const gchar* d)
{
	GeeArrayList* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (d != NULL);
	_tmp0_ = self->displays;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp0_, d);
}

/** @return true if a key binding can be used in @param display. */
gboolean
bird_font_menu_item_in_display (BirdFontMenuItem* self,
                                const gchar* display)
{
	GeeArrayList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (display != NULL, FALSE);
	_tmp0_ = self->displays;
	_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_ == 0) {
		result = TRUE;
		return result;
	}
	{
		GeeArrayList* _d_list = NULL;
		GeeArrayList* _tmp3_;
		gint _d_size = 0;
		GeeArrayList* _tmp4_;
		gint _tmp5_;
		gint _tmp6_;
		gint _d_index = 0;
		_tmp3_ = self->displays;
		_d_list = _tmp3_;
		_tmp4_ = _d_list;
		_tmp5_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp4_);
		_tmp6_ = _tmp5_;
		_d_size = _tmp6_;
		_d_index = -1;
		while (TRUE) {
			gint _tmp7_;
			gint _tmp8_;
			gchar* d = NULL;
			GeeArrayList* _tmp9_;
			gpointer _tmp10_;
			const gchar* _tmp11_;
			_d_index = _d_index + 1;
			_tmp7_ = _d_index;
			_tmp8_ = _d_size;
			if (!(_tmp7_ < _tmp8_)) {
				break;
			}
			_tmp9_ = _d_list;
			_tmp10_ = gee_abstract_list_get ((GeeAbstractList*) _tmp9_, _d_index);
			d = (gchar*) _tmp10_;
			_tmp11_ = d;
			if (g_strcmp0 (_tmp11_, display) == 0) {
				result = TRUE;
				_g_free0 (d);
				return result;
			}
			_g_free0 (d);
		}
	}
	result = FALSE;
	return result;
}

static gchar*
g_unichar_to_string (gunichar self)
{
	gchar* str = NULL;
	gchar* _tmp0_;
	gchar* result;
	_tmp0_ = g_new0 (gchar, 7);
	str = (gchar*) _tmp0_;
	g_unichar_to_utf8 (self, str);
	result = str;
	return result;
}

gchar*
bird_font_menu_item_get_key_bindings (BirdFontMenuItem* self)
{
	gchar* key_binding = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup ("");
	key_binding = _tmp0_;
	if (self->key != ((gunichar) '\0')) {
		const gchar* _tmp1_;
		gchar* _tmp2_;
		const gchar* _tmp31_;
		gchar* _tmp32_;
		_tmp1_ = key_binding;
		_tmp2_ = g_strconcat (_tmp1_, "(", NULL);
		_g_free0 (key_binding);
		key_binding = _tmp2_;
		if ((self->modifiers & BIRD_FONT_CTRL) > ((guint) 0)) {
			const gchar* _tmp3_;
			gchar* _tmp4_;
			_tmp3_ = key_binding;
			_tmp4_ = g_strconcat (_tmp3_, "Ctrl+", NULL);
			_g_free0 (key_binding);
			key_binding = _tmp4_;
		}
		if ((self->modifiers & BIRD_FONT_ALT) > ((guint) 0)) {
			const gchar* _tmp5_;
			gchar* _tmp6_;
			_tmp5_ = key_binding;
			_tmp6_ = g_strconcat (_tmp5_, "Alt+", NULL);
			_g_free0 (key_binding);
			key_binding = _tmp6_;
		}
		if ((self->modifiers & BIRD_FONT_LOGO) > ((guint) 0)) {
			const gchar* _tmp7_;
			gchar* _tmp8_;
			_tmp7_ = key_binding;
			_tmp8_ = g_strconcat (_tmp7_, "Command+", NULL);
			_g_free0 (key_binding);
			key_binding = _tmp8_;
		}
		if ((self->modifiers & BIRD_FONT_SHIFT) > ((guint) 0)) {
			const gchar* _tmp9_;
			gchar* _tmp10_;
			_tmp9_ = key_binding;
			_tmp10_ = g_strconcat (_tmp9_, "Shift+", NULL);
			_g_free0 (key_binding);
			key_binding = _tmp10_;
		}
		switch (self->key) {
			case BIRD_FONT_KEY_UP:
			{
				const gchar* _tmp11_;
				gchar* _tmp12_;
				gchar* _tmp13_;
				gchar* _tmp14_;
				_tmp11_ = key_binding;
				_tmp12_ = bird_font_t_ ("UP");
				_tmp13_ = _tmp12_;
				_tmp14_ = g_strconcat (_tmp11_, _tmp13_, NULL);
				_g_free0 (key_binding);
				key_binding = _tmp14_;
				_g_free0 (_tmp13_);
				break;
			}
			case BIRD_FONT_KEY_DOWN:
			{
				const gchar* _tmp15_;
				gchar* _tmp16_;
				gchar* _tmp17_;
				gchar* _tmp18_;
				_tmp15_ = key_binding;
				_tmp16_ = bird_font_t_ ("DOWN");
				_tmp17_ = _tmp16_;
				_tmp18_ = g_strconcat (_tmp15_, _tmp17_, NULL);
				_g_free0 (key_binding);
				key_binding = _tmp18_;
				_g_free0 (_tmp17_);
				break;
			}
			case BIRD_FONT_KEY_LEFT:
			{
				const gchar* _tmp19_;
				gchar* _tmp20_;
				gchar* _tmp21_;
				gchar* _tmp22_;
				_tmp19_ = key_binding;
				_tmp20_ = bird_font_t_ ("LEFT");
				_tmp21_ = _tmp20_;
				_tmp22_ = g_strconcat (_tmp19_, _tmp21_, NULL);
				_g_free0 (key_binding);
				key_binding = _tmp22_;
				_g_free0 (_tmp21_);
				break;
			}
			case BIRD_FONT_KEY_RIGHT:
			{
				const gchar* _tmp23_;
				gchar* _tmp24_;
				gchar* _tmp25_;
				gchar* _tmp26_;
				_tmp23_ = key_binding;
				_tmp24_ = bird_font_t_ ("RIGHT");
				_tmp25_ = _tmp24_;
				_tmp26_ = g_strconcat (_tmp23_, _tmp25_, NULL);
				_g_free0 (key_binding);
				key_binding = _tmp26_;
				_g_free0 (_tmp25_);
				break;
			}
			default:
			{
				const gchar* _tmp27_;
				gchar* _tmp28_;
				gchar* _tmp29_;
				gchar* _tmp30_;
				_tmp27_ = key_binding;
				_tmp28_ = g_unichar_to_string (self->key);
				_tmp29_ = (gchar*) _tmp28_;
				_tmp30_ = g_strconcat (_tmp27_, _tmp29_, NULL);
				_g_free0 (key_binding);
				key_binding = _tmp30_;
				_g_free0 (_tmp29_);
				break;
			}
		}
		_tmp31_ = key_binding;
		_tmp32_ = g_strconcat (_tmp31_, ")", NULL);
		_g_free0 (key_binding);
		key_binding = _tmp32_;
	}
	result = key_binding;
	return result;
}

static void
bird_font_menu_item_class_init (BirdFontMenuItemClass * klass,
                                gpointer klass_data)
{
	bird_font_menu_item_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = bird_font_menu_item_finalize;
	bird_font_menu_item_signals[BIRD_FONT_MENU_ITEM_ACTION_SIGNAL] = g_signal_new ("action", BIRD_FONT_TYPE_MENU_ITEM, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
bird_font_menu_item_instance_init (BirdFontMenuItem * self,
                                   gpointer klass)
{
	GeeArrayList* _tmp0_;
	self->modifiers = BIRD_FONT_NONE;
	self->key = (gunichar) '\0';
	_tmp0_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
	self->displays = _tmp0_;
}

static void
bird_font_menu_item_finalize (GObject * obj)
{
	BirdFontMenuItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_MENU_ITEM, BirdFontMenuItem);
	_g_object_unref0 (self->label);
	_g_free0 (self->identifier);
	_g_object_unref0 (self->displays);
	G_OBJECT_CLASS (bird_font_menu_item_parent_class)->finalize (obj);
}

static GType
bird_font_menu_item_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontMenuItemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_menu_item_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontMenuItem), 0, (GInstanceInitFunc) bird_font_menu_item_instance_init, NULL };
	GType bird_font_menu_item_type_id;
	bird_font_menu_item_type_id = g_type_register_static (G_TYPE_OBJECT, "BirdFontMenuItem", &g_define_type_info, 0);
	return bird_font_menu_item_type_id;
}

GType
bird_font_menu_item_get_type (void)
{
	static volatile gsize bird_font_menu_item_type_id__once = 0;
	if (g_once_init_enter (&bird_font_menu_item_type_id__once)) {
		GType bird_font_menu_item_type_id;
		bird_font_menu_item_type_id = bird_font_menu_item_get_type_once ();
		g_once_init_leave (&bird_font_menu_item_type_id__once, bird_font_menu_item_type_id);
	}
	return bird_font_menu_item_type_id__once;
}

