/* SettingsItem.c generated by valac 0.56.17, the Vala compiler
 * generated from SettingsItem.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 <float.h>
#include <math.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <cairo-gobject.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_SETTINGS_ITEM_0_PROPERTY,
	BIRD_FONT_SETTINGS_ITEM_NUM_PROPERTIES
};
static GParamSpec* bird_font_settings_item_properties[BIRD_FONT_SETTINGS_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))
typedef struct _Block57Data Block57Data;
#define _bird_font_color_unref0(var) ((var == NULL) ? NULL : (var = (bird_font_color_unref (var), NULL)))

struct _BirdFontSettingsItemPrivate {
	BirdFontText* label;
};

struct _Block57Data {
	int _ref_count_;
	BirdFontSettingsItem* self;
	BirdFontColorTool* cb;
	gchar* color;
};

static gint BirdFontSettingsItem_private_offset;
static gpointer bird_font_settings_item_parent_class = NULL;

static Block57Data* block57_data_ref (Block57Data* _data57_);
static void block57_data_unref (void * _userdata_);
static void __lambda275_ (Block57Data* _data57_);
static void ___lambda275__bird_font_color_tool_color_updated (BirdFontColorTool* _sender,
                                                       gpointer self);
static void bird_font_settings_item_finalize (GObject * obj);
static GType bird_font_settings_item_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
bird_font_settings_item_get_instance_private (BirdFontSettingsItem* self)
{
	return G_STRUCT_MEMBER_P (self, BirdFontSettingsItem_private_offset);
}

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

BirdFontSettingsItem*
bird_font_settings_item_construct (GType object_type,
                                   BirdFontTool* tool,
                                   const gchar* description)
{
	BirdFontSettingsItem * self = NULL;
	BirdFontTool* _tmp0_;
	BirdFontText* _tmp1_;
	BirdFontText* _tmp2_;
	g_return_val_if_fail (tool != NULL, NULL);
	g_return_val_if_fail (description != NULL, NULL);
	self = (BirdFontSettingsItem*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (tool);
	_g_object_unref0 (self->button);
	self->button = _tmp0_;
	_tmp1_ = bird_font_text_new ("", (gdouble) 17, (gdouble) 0);
	_g_object_unref0 (self->priv->label);
	self->priv->label = _tmp1_;
	_tmp2_ = self->priv->label;
	bird_font_text_set_text (_tmp2_, description);
	self->handle_events = TRUE;
	return self;
}

BirdFontSettingsItem*
bird_font_settings_item_new (BirdFontTool* tool,
                             const gchar* description)
{
	return bird_font_settings_item_construct (BIRD_FONT_TYPE_SETTINGS_ITEM, tool, description);
}

BirdFontSettingsItem*
bird_font_settings_item_construct_key_binding (GType object_type,
                                               BirdFontMenuItem* item)
{
	BirdFontSettingsItem * self = NULL;
	BirdFontText* _tmp2_;
	BirdFontText* _tmp3_;
	BirdFontMenuItem* _tmp4_;
	g_return_val_if_fail (item != NULL, NULL);
	self = (BirdFontSettingsItem*) g_object_new (object_type, NULL);
	if (BIRD_FONT_IS_TOOL_ITEM (item)) {
		BirdFontTool* _tmp0_;
		BirdFontTool* _tmp1_;
		_tmp0_ = G_TYPE_CHECK_INSTANCE_CAST (item, BIRD_FONT_TYPE_TOOL_ITEM, BirdFontToolItem)->tool;
		_tmp1_ = _g_object_ref0 (_tmp0_);
		_g_object_unref0 (self->button);
		self->button = _tmp1_;
	}
	_tmp2_ = item->label;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	_g_object_unref0 (self->priv->label);
	self->priv->label = _tmp3_;
	self->handle_events = FALSE;
	self->key_bindings = TRUE;
	_tmp4_ = _g_object_ref0 (item);
	_g_object_unref0 (self->menu_item);
	self->menu_item = _tmp4_;
	return self;
}

BirdFontSettingsItem*
bird_font_settings_item_new_key_binding (BirdFontMenuItem* item)
{
	return bird_font_settings_item_construct_key_binding (BIRD_FONT_TYPE_SETTINGS_ITEM, item);
}

BirdFontSettingsItem*
bird_font_settings_item_construct_head_line (GType object_type,
                                             const gchar* label)
{
	BirdFontSettingsItem * self = NULL;
	BirdFontText* _tmp0_;
	BirdFontText* _tmp1_;
	g_return_val_if_fail (label != NULL, NULL);
	self = (BirdFontSettingsItem*) g_object_new (object_type, NULL);
	_tmp0_ = bird_font_text_new ("", (gdouble) 17, (gdouble) 0);
	_g_object_unref0 (self->priv->label);
	self->priv->label = _tmp0_;
	_tmp1_ = self->priv->label;
	bird_font_text_set_text (_tmp1_, label);
	self->handle_events = FALSE;
	self->headline = TRUE;
	return self;
}

BirdFontSettingsItem*
bird_font_settings_item_new_head_line (const gchar* label)
{
	return bird_font_settings_item_construct_head_line (BIRD_FONT_TYPE_SETTINGS_ITEM, label);
}

static Block57Data*
block57_data_ref (Block57Data* _data57_)
{
	g_atomic_int_inc (&_data57_->_ref_count_);
	return _data57_;
}

static void
block57_data_unref (void * _userdata_)
{
	Block57Data* _data57_;
	_data57_ = (Block57Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data57_->_ref_count_)) {
		BirdFontSettingsItem* self;
		self = _data57_->self;
		_g_object_unref0 (_data57_->cb);
		_g_free0 (_data57_->color);
		_g_object_unref0 (self);
		g_slice_free (Block57Data, _data57_);
	}
}

static void
__lambda275_ (Block57Data* _data57_)
{
	BirdFontSettingsItem* self;
	BirdFontTabBar* tab_bar = NULL;
	BirdFontTabBar* _tmp0_;
	self = _data57_->self;
	bird_font_theme_save_color (_data57_->color, _data57_->cb->color_r, _data57_->cb->color_g, _data57_->cb->color_b, _data57_->cb->color_a);
	_tmp0_ = bird_font_main_window_get_tab_bar ();
	_g_object_unref0 (tab_bar);
	tab_bar = _tmp0_;
	bird_font_tab_bar_redraw (tab_bar, 0, 0, tab_bar->width, tab_bar->height);
	bird_font_glyph_canvas_redraw ();
	bird_font_toolbox_redraw_tool_box ();
	_g_object_unref0 (tab_bar);
}

static void
___lambda275__bird_font_color_tool_color_updated (BirdFontColorTool* _sender,
                                                  gpointer self)
{
	__lambda275_ (self);
}

BirdFontSettingsItem*
bird_font_settings_item_construct_color (GType object_type,
                                         const gchar* color)
{
	BirdFontSettingsItem * self = NULL;
	Block57Data* _data57_;
	gchar* _tmp0_;
	BirdFontColor* c = NULL;
	BirdFontColor* _tmp1_;
	BirdFontText* _tmp2_;
	BirdFontText* _tmp3_;
	BirdFontColorTool* _tmp4_;
	BirdFontTool* _tmp5_;
	g_return_val_if_fail (color != NULL, NULL);
	_data57_ = g_slice_new0 (Block57Data);
	_data57_->_ref_count_ = 1;
	_tmp0_ = g_strdup (color);
	_g_free0 (_data57_->color);
	_data57_->color = _tmp0_;
	self = (BirdFontSettingsItem*) g_object_new (object_type, NULL);
	_data57_->self = g_object_ref (self);
	_tmp1_ = bird_font_theme_get_color (_data57_->color);
	_bird_font_color_unref0 (c);
	c = _tmp1_;
	_tmp2_ = bird_font_text_new ("", (gdouble) 17, (gdouble) 0);
	_g_object_unref0 (self->priv->label);
	self->priv->label = _tmp2_;
	_tmp3_ = self->priv->label;
	bird_font_text_set_text (_tmp3_, _data57_->color);
	self->handle_events = TRUE;
	_tmp4_ = bird_font_color_tool_new (_data57_->color);
	_g_object_unref0 (_data57_->cb);
	_data57_->cb = _tmp4_;
	bird_font_color_tool_set_r (_data57_->cb, c->r);
	bird_font_color_tool_set_g (_data57_->cb, c->g);
	bird_font_color_tool_set_b (_data57_->cb, c->b);
	bird_font_color_tool_set_a (_data57_->cb, c->a);
	g_signal_connect_data (_data57_->cb, "color-updated", (GCallback) ___lambda275__bird_font_color_tool_color_updated, block57_data_ref (_data57_), (GClosureNotify) block57_data_unref, 0);
	_tmp5_ = _g_object_ref0 ((BirdFontTool*) _data57_->cb);
	_g_object_unref0 (self->button);
	self->button = _tmp5_;
	_bird_font_color_unref0 (c);
	block57_data_unref (_data57_);
	_data57_ = NULL;
	return self;
}

BirdFontSettingsItem*
bird_font_settings_item_new_color (const gchar* color)
{
	return bird_font_settings_item_construct_color (BIRD_FONT_TYPE_SETTINGS_ITEM, color);
}

void
bird_font_settings_item_draw (BirdFontSettingsItem* self,
                              BirdFontWidgetAllocation* allocation,
                              cairo_t* cr)
{
	BirdFontTool* t = NULL;
	gdouble label_x = 0.0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (allocation != NULL);
	g_return_if_fail (cr != NULL);
	if (self->headline) {
		BirdFontText* _tmp0_;
		BirdFontText* _tmp1_;
		BirdFontText* _tmp2_;
		cairo_save (cr);
		bird_font_theme_color (cr, "Headline Background");
		cairo_rectangle (cr, (gdouble) 0, self->y, (gdouble) allocation->width, (gdouble) 40);
		cairo_fill (cr);
		cairo_restore (cr);
		cairo_save (cr);
		_tmp0_ = self->priv->label;
		bird_font_theme_text_color (_tmp0_, "Foreground Inverted");
		_tmp1_ = self->priv->label;
		bird_font_text_set_font_size (_tmp1_, (gdouble) 20);
		_tmp2_ = self->priv->label;
		bird_font_text_draw_at_baseline (_tmp2_, cr, (gdouble) 21, self->y + 25, "");
		cairo_restore (cr);
	} else {
		gint _tmp3_ = 0;
		BirdFontTool* _tmp4_;
		BirdFontTool* _tmp5_;
		BirdFontText* _tmp9_;
		BirdFontText* _tmp10_;
		BirdFontText* _tmp11_;
		if (self->active) {
			cairo_save (cr);
			bird_font_theme_color (cr, "Menu Background");
			cairo_rectangle (cr, (gdouble) 0, self->y - 5, (gdouble) allocation->width, (gdouble) 40);
			cairo_fill (cr);
			cairo_restore (cr);
		}
		_tmp4_ = self->button;
		if (_tmp4_ != NULL) {
			_tmp3_ = 70;
		} else {
			_tmp3_ = 20;
		}
		label_x = (gdouble) _tmp3_;
		label_x *= bird_font_main_window_units;
		_tmp5_ = self->button;
		if (_tmp5_ != NULL) {
			BirdFontTool* _tmp6_;
			BirdFontTool* _tmp7_;
			BirdFontTool* _tmp8_;
			_tmp6_ = self->button;
			_tmp7_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, BIRD_FONT_TYPE_TOOL, BirdFontTool));
			_g_object_unref0 (t);
			t = _tmp7_;
			_tmp8_ = t;
			bird_font_widget_draw ((BirdFontWidget*) _tmp8_, cr);
		}
		cairo_save (cr);
		_tmp9_ = self->priv->label;
		bird_font_theme_text_color (_tmp9_, "Text Tool Box");
		_tmp10_ = self->priv->label;
		bird_font_text_set_font_size (_tmp10_, (gdouble) 17);
		_tmp11_ = self->priv->label;
		bird_font_text_draw_at_baseline (_tmp11_, cr, label_x, self->y + 20, "");
		cairo_restore (cr);
		if (self->key_bindings) {
			BirdFontText* key_binding_text = NULL;
			BirdFontText* _tmp12_;
			BirdFontText* _tmp13_;
			BirdFontMenuItem* _tmp14_;
			gchar* _tmp15_;
			gchar* _tmp16_;
			BirdFontText* _tmp19_;
			BirdFontText* _tmp20_;
			BirdFontText* _tmp21_;
			_tmp12_ = bird_font_text_new ("", (gdouble) 17, (gdouble) 0);
			key_binding_text = _tmp12_;
			_tmp13_ = key_binding_text;
			_tmp14_ = self->menu_item;
			_tmp15_ = bird_font_menu_item_get_key_bindings (_tmp14_);
			_tmp16_ = _tmp15_;
			bird_font_text_set_text (_tmp13_, _tmp16_);
			_g_free0 (_tmp16_);
			cairo_save (cr);
			if (self->active) {
				BirdFontText* _tmp17_;
				_tmp17_ = key_binding_text;
				bird_font_theme_text_color (_tmp17_, "Foreground Inverted");
			} else {
				BirdFontText* _tmp18_;
				_tmp18_ = key_binding_text;
				bird_font_theme_text_color (_tmp18_, "Text Tool Box");
			}
			_tmp19_ = key_binding_text;
			bird_font_text_set_font_size (_tmp19_, (gdouble) 17);
			_tmp20_ = self->priv->label;
			label_x += bird_font_text_get_extent (_tmp20_) + 20;
			_tmp21_ = key_binding_text;
			bird_font_text_draw_at_baseline (_tmp21_, cr, label_x, self->y + 20, "");
			cairo_restore (cr);
			_g_object_unref0 (key_binding_text);
		}
	}
	_g_object_unref0 (t);
}

static void
bird_font_settings_item_class_init (BirdFontSettingsItemClass * klass,
                                    gpointer klass_data)
{
	bird_font_settings_item_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BirdFontSettingsItem_private_offset);
	G_OBJECT_CLASS (klass)->finalize = bird_font_settings_item_finalize;
}

static void
bird_font_settings_item_instance_init (BirdFontSettingsItem * self,
                                       gpointer klass)
{
	BirdFontMenuItem* _tmp0_;
	self->priv = bird_font_settings_item_get_instance_private (self);
	self->key_bindings = FALSE;
	self->y = (gdouble) 0;
	self->button = NULL;
	self->headline = FALSE;
	_tmp0_ = bird_font_menu_item_new ("", "");
	self->menu_item = _tmp0_;
	self->active = FALSE;
}

static void
bird_font_settings_item_finalize (GObject * obj)
{
	BirdFontSettingsItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_SETTINGS_ITEM, BirdFontSettingsItem);
	_g_object_unref0 (self->button);
	_g_object_unref0 (self->menu_item);
	_g_object_unref0 (self->priv->label);
	G_OBJECT_CLASS (bird_font_settings_item_parent_class)->finalize (obj);
}

static GType
bird_font_settings_item_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontSettingsItemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_settings_item_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontSettingsItem), 0, (GInstanceInitFunc) bird_font_settings_item_instance_init, NULL };
	GType bird_font_settings_item_type_id;
	bird_font_settings_item_type_id = g_type_register_static (G_TYPE_OBJECT, "BirdFontSettingsItem", &g_define_type_info, 0);
	BirdFontSettingsItem_private_offset = g_type_add_instance_private (bird_font_settings_item_type_id, sizeof (BirdFontSettingsItemPrivate));
	return bird_font_settings_item_type_id;
}

GType
bird_font_settings_item_get_type (void)
{
	static volatile gsize bird_font_settings_item_type_id__once = 0;
	if (g_once_init_enter (&bird_font_settings_item_type_id__once)) {
		GType bird_font_settings_item_type_id;
		bird_font_settings_item_type_id = bird_font_settings_item_get_type_once ();
		g_once_init_leave (&bird_font_settings_item_type_id__once, bird_font_settings_item_type_id);
	}
	return bird_font_settings_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;
}

