/* OverwriteDialog.c generated by valac 0.56.17, the Vala compiler
 * generated from OverwriteDialog.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 <glib.h>
#include <float.h>
#include <math.h>
#include <cairo-gobject.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>

#define BIRD_FONT_OVERWRITE_DIALOG_question_font_size ((gdouble) 23)
#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_OVERWRITE_DIALOG_0_PROPERTY,
	BIRD_FONT_OVERWRITE_DIALOG_NUM_PROPERTIES
};
static GParamSpec* bird_font_overwrite_dialog_properties[BIRD_FONT_OVERWRITE_DIALOG_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block42Data Block42Data;

struct _BirdFontOverwriteDialogPrivate {
	BirdFontOverWriteDialogListener* listener;
	BirdFontText* question;
	BirdFontButton* overwrite_button;
	BirdFontButton* cancel_button;
	BirdFontButton* dont_ask_again_button;
	gdouble width;
	gdouble height;
};

struct _Block42Data {
	int _ref_count_;
	BirdFontOverwriteDialog* self;
	BirdFontOverWriteDialogListener* callbacks;
};

static gint BirdFontOverwriteDialog_private_offset;
static gpointer bird_font_overwrite_dialog_parent_class = NULL;

static Block42Data* block42_data_ref (Block42Data* _data42_);
static void block42_data_unref (void * _userdata_);
static void __lambda216_ (Block42Data* _data42_);
static void ___lambda216__bird_font_button_action (BirdFontButton* _sender,
                                            gpointer self);
static void __lambda217_ (Block42Data* _data42_);
static void ___lambda217__bird_font_button_action (BirdFontButton* _sender,
                                            gpointer self);
static void __lambda218_ (Block42Data* _data42_);
static void ___lambda218__bird_font_button_action (BirdFontButton* _sender,
                                            gpointer self);
static void bird_font_overwrite_dialog_real_layout (BirdFontWidget* base);
static void bird_font_overwrite_dialog_real_draw (BirdFontWidget* base,
                                           cairo_t* cr);
static void bird_font_overwrite_dialog_real_button_press (BirdFontWidget* base,
                                                   guint button,
                                                   gdouble x,
                                                   gdouble y);
static void bird_font_overwrite_dialog_real_button_release (BirdFontWidget* base,
                                                     guint button,
                                                     gdouble x,
                                                     gdouble y);
static void bird_font_overwrite_dialog_finalize (GObject * obj);
static GType bird_font_overwrite_dialog_get_type_once (void);

static inline gpointer
bird_font_overwrite_dialog_get_instance_private (BirdFontOverwriteDialog* self)
{
	return G_STRUCT_MEMBER_P (self, BirdFontOverwriteDialog_private_offset);
}

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

static Block42Data*
block42_data_ref (Block42Data* _data42_)
{
	g_atomic_int_inc (&_data42_->_ref_count_);
	return _data42_;
}

static void
block42_data_unref (void * _userdata_)
{
	Block42Data* _data42_;
	_data42_ = (Block42Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data42_->_ref_count_)) {
		BirdFontOverwriteDialog* self;
		self = _data42_->self;
		_g_object_unref0 (_data42_->callbacks);
		_g_object_unref0 (self);
		g_slice_free (Block42Data, _data42_);
	}
}

static void
__lambda216_ (Block42Data* _data42_)
{
	BirdFontOverwriteDialog* self;
	self = _data42_->self;
	bird_font_main_window_hide_dialog ();
	bird_font_over_write_dialog_listener_overwrite (_data42_->callbacks);
}

static void
___lambda216__bird_font_button_action (BirdFontButton* _sender,
                                       gpointer self)
{
	__lambda216_ (self);
}

static void
__lambda217_ (Block42Data* _data42_)
{
	BirdFontOverwriteDialog* self;
	self = _data42_->self;
	bird_font_main_window_hide_dialog ();
	bird_font_over_write_dialog_listener_cancel (_data42_->callbacks);
}

static void
___lambda217__bird_font_button_action (BirdFontButton* _sender,
                                       gpointer self)
{
	__lambda217_ (self);
}

static void
__lambda218_ (Block42Data* _data42_)
{
	BirdFontOverwriteDialog* self;
	self = _data42_->self;
	bird_font_main_window_hide_dialog ();
	bird_font_over_write_dialog_listener_overwrite_dont_ask_again (_data42_->callbacks);
}

static void
___lambda218__bird_font_button_action (BirdFontButton* _sender,
                                       gpointer self)
{
	__lambda218_ (self);
}

BirdFontOverwriteDialog*
bird_font_overwrite_dialog_construct (GType object_type,
                                      BirdFontOverWriteDialogListener* callbacks)
{
	BirdFontOverwriteDialog * self = NULL;
	Block42Data* _data42_;
	BirdFontOverWriteDialogListener* _tmp0_;
	gdouble font_size = 0.0;
	BirdFontOverWriteDialogListener* _tmp1_;
	const gchar* _tmp2_;
	BirdFontText* _tmp3_;
	const gchar* _tmp4_;
	BirdFontButton* _tmp5_;
	BirdFontButton* _tmp6_;
	const gchar* _tmp7_;
	BirdFontButton* _tmp8_;
	BirdFontButton* _tmp9_;
	const gchar* _tmp10_;
	BirdFontButton* _tmp11_;
	BirdFontButton* _tmp12_;
	g_return_val_if_fail (callbacks != NULL, NULL);
	_data42_ = g_slice_new0 (Block42Data);
	_data42_->_ref_count_ = 1;
	_tmp0_ = _g_object_ref0 (callbacks);
	_g_object_unref0 (_data42_->callbacks);
	_data42_->callbacks = _tmp0_;
	self = (BirdFontOverwriteDialog*) bird_font_dialog_construct (object_type);
	_data42_->self = g_object_ref (self);
	font_size = BIRD_FONT_OVERWRITE_DIALOG_question_font_size;
	_tmp1_ = _g_object_ref0 (_data42_->callbacks);
	_g_object_unref0 (self->priv->listener);
	self->priv->listener = _tmp1_;
	_tmp2_ = _data42_->callbacks->message;
	_tmp3_ = bird_font_text_new (_tmp2_, font_size, (gdouble) 0);
	_g_object_unref0 (self->priv->question);
	self->priv->question = _tmp3_;
	_tmp4_ = _data42_->callbacks->message;
	_tmp5_ = bird_font_button_new (_tmp4_, (gdouble) 0);
	_g_object_unref0 (self->priv->overwrite_button);
	self->priv->overwrite_button = _tmp5_;
	_tmp6_ = self->priv->overwrite_button;
	g_signal_connect_data (_tmp6_, "action", (GCallback) ___lambda216__bird_font_button_action, block42_data_ref (_data42_), (GClosureNotify) block42_data_unref, 0);
	_tmp7_ = _data42_->callbacks->cancel_message;
	_tmp8_ = bird_font_button_new (_tmp7_, (gdouble) 0);
	_g_object_unref0 (self->priv->cancel_button);
	self->priv->cancel_button = _tmp8_;
	_tmp9_ = self->priv->cancel_button;
	g_signal_connect_data (_tmp9_, "action", (GCallback) ___lambda217__bird_font_button_action, block42_data_ref (_data42_), (GClosureNotify) block42_data_unref, 0);
	_tmp10_ = _data42_->callbacks->dont_ask_again_message;
	_tmp11_ = bird_font_button_new (_tmp10_, (gdouble) 0);
	_g_object_unref0 (self->priv->dont_ask_again_button);
	self->priv->dont_ask_again_button = _tmp11_;
	_tmp12_ = self->priv->dont_ask_again_button;
	g_signal_connect_data (_tmp12_, "action", (GCallback) ___lambda218__bird_font_button_action, block42_data_ref (_data42_), (GClosureNotify) block42_data_unref, 0);
	self->priv->height = (gdouble) 90;
	block42_data_unref (_data42_);
	_data42_ = NULL;
	return self;
}

BirdFontOverwriteDialog*
bird_font_overwrite_dialog_new (BirdFontOverWriteDialogListener* callbacks)
{
	return bird_font_overwrite_dialog_construct (BIRD_FONT_TYPE_OVERWRITE_DIALOG, callbacks);
}

static void
bird_font_overwrite_dialog_real_layout (BirdFontWidget* base)
{
	BirdFontOverwriteDialog * self;
	gdouble cx = 0.0;
	gdouble cy = 0.0;
	BirdFontWidgetAllocation* _tmp0_;
	gdouble center = 0.0;
	gdouble qh = 0.0;
	BirdFontButton* _tmp1_;
	BirdFontButton* _tmp2_;
	BirdFontButton* _tmp3_;
	BirdFontButton* _tmp4_;
	BirdFontButton* _tmp5_;
	BirdFontButton* _tmp6_;
	BirdFontWidgetAllocation* _tmp7_;
	BirdFontText* _tmp8_;
	BirdFontButton* _tmp9_;
	BirdFontText* _tmp10_;
	BirdFontText* _tmp11_;
	BirdFontButton* _tmp12_;
	BirdFontButton* _tmp13_;
	BirdFontButton* _tmp14_;
	BirdFontButton* _tmp15_;
	BirdFontButton* _tmp16_;
	BirdFontButton* _tmp17_;
	BirdFontButton* _tmp18_;
	BirdFontButton* _tmp19_;
	BirdFontButton* _tmp20_;
	self = (BirdFontOverwriteDialog*) base;
	cx = (gdouble) 0;
	_tmp0_ = ((BirdFontWidget*) self)->allocation;
	cy = (_tmp0_->height - self->priv->height) / 2.0;
	cx = (gdouble) 20;
	_tmp1_ = self->priv->overwrite_button;
	((BirdFontWidget*) _tmp1_)->widget_x = cx;
	_tmp2_ = self->priv->overwrite_button;
	cx += 10 + bird_font_widget_get_width ((BirdFontWidget*) _tmp2_);
	_tmp3_ = self->priv->cancel_button;
	((BirdFontWidget*) _tmp3_)->widget_x = cx;
	_tmp4_ = self->priv->cancel_button;
	cx += 10 + bird_font_widget_get_width ((BirdFontWidget*) _tmp4_);
	_tmp5_ = self->priv->dont_ask_again_button;
	((BirdFontWidget*) _tmp5_)->widget_x = cx;
	_tmp6_ = self->priv->dont_ask_again_button;
	self->priv->width = (cx + 20) + bird_font_widget_get_width ((BirdFontWidget*) _tmp6_);
	_tmp7_ = ((BirdFontWidget*) self)->allocation;
	center = (_tmp7_->width - self->priv->width) / 2.0;
	_tmp8_ = self->priv->question;
	_tmp9_ = self->priv->overwrite_button;
	((BirdFontWidget*) _tmp8_)->widget_x = ((BirdFontWidget*) _tmp9_)->widget_x + center;
	_tmp10_ = self->priv->question;
	((BirdFontWidget*) _tmp10_)->widget_y = cy + 15;
	_tmp11_ = self->priv->question;
	bird_font_theme_text_color (_tmp11_, "Text Tool Box");
	qh = BIRD_FONT_OVERWRITE_DIALOG_question_font_size + 1;
	_tmp12_ = self->priv->overwrite_button;
	_tmp13_ = self->priv->overwrite_button;
	((BirdFontWidget*) _tmp13_)->widget_x = ((BirdFontWidget*) _tmp13_)->widget_x + center;
	_tmp14_ = self->priv->overwrite_button;
	((BirdFontWidget*) _tmp14_)->widget_y = (cy + qh) + 25;
	_tmp15_ = self->priv->cancel_button;
	_tmp16_ = self->priv->cancel_button;
	((BirdFontWidget*) _tmp16_)->widget_x = ((BirdFontWidget*) _tmp16_)->widget_x + center;
	_tmp17_ = self->priv->cancel_button;
	((BirdFontWidget*) _tmp17_)->widget_y = (cy + qh) + 25;
	_tmp18_ = self->priv->dont_ask_again_button;
	_tmp19_ = self->priv->dont_ask_again_button;
	((BirdFontWidget*) _tmp19_)->widget_x = ((BirdFontWidget*) _tmp19_)->widget_x + center;
	_tmp20_ = self->priv->dont_ask_again_button;
	((BirdFontWidget*) _tmp20_)->widget_y = (cy + qh) + 25;
}

static void
bird_font_overwrite_dialog_real_draw (BirdFontWidget* base,
                                      cairo_t* cr)
{
	BirdFontOverwriteDialog * self;
	gdouble cx = 0.0;
	gdouble cy = 0.0;
	BirdFontWidgetAllocation* _tmp0_;
	BirdFontWidgetAllocation* _tmp1_;
	BirdFontWidgetAllocation* _tmp2_;
	BirdFontWidgetAllocation* _tmp3_;
	BirdFontText* _tmp4_;
	BirdFontButton* _tmp5_;
	BirdFontButton* _tmp6_;
	BirdFontButton* _tmp7_;
	self = (BirdFontOverwriteDialog*) base;
	g_return_if_fail (cr != NULL);
	bird_font_widget_layout ((BirdFontWidget*) self);
	_tmp0_ = ((BirdFontWidget*) self)->allocation;
	cx = (_tmp0_->width - self->priv->width) / 2.0;
	_tmp1_ = ((BirdFontWidget*) self)->allocation;
	cy = (_tmp1_->height - self->priv->height) / 2.0;
	cairo_save (cr);
	bird_font_theme_color (cr, "Dialog Shadow");
	_tmp2_ = ((BirdFontWidget*) self)->allocation;
	_tmp3_ = ((BirdFontWidget*) self)->allocation;
	cairo_rectangle (cr, (gdouble) 0, (gdouble) 0, (gdouble) _tmp2_->width, (gdouble) _tmp3_->height);
	cairo_fill (cr);
	cairo_restore (cr);
	cairo_save (cr);
	bird_font_theme_color (cr, "Dialog Background");
	bird_font_widget_draw_rounded_rectangle (cr, cx, cy, self->priv->width, self->priv->height, (gdouble) 10);
	cairo_fill (cr);
	cairo_restore (cr);
	cairo_save (cr);
	bird_font_theme_color (cr, "Button Border 4");
	cairo_set_line_width (cr, (gdouble) 1);
	bird_font_widget_draw_rounded_rectangle (cr, cx, cy, self->priv->width, self->priv->height, (gdouble) 10);
	cairo_stroke (cr);
	cairo_restore (cr);
	_tmp4_ = self->priv->question;
	bird_font_widget_draw ((BirdFontWidget*) _tmp4_, cr);
	_tmp5_ = self->priv->overwrite_button;
	bird_font_widget_draw ((BirdFontWidget*) _tmp5_, cr);
	_tmp6_ = self->priv->cancel_button;
	bird_font_widget_draw ((BirdFontWidget*) _tmp6_, cr);
	_tmp7_ = self->priv->dont_ask_again_button;
	bird_font_widget_draw ((BirdFontWidget*) _tmp7_, cr);
}

static void
bird_font_overwrite_dialog_real_button_press (BirdFontWidget* base,
                                              guint button,
                                              gdouble x,
                                              gdouble y)
{
	BirdFontOverwriteDialog * self;
	BirdFontButton* _tmp0_;
	BirdFontButton* _tmp1_;
	BirdFontButton* _tmp2_;
	self = (BirdFontOverwriteDialog*) base;
	_tmp0_ = self->priv->overwrite_button;
	bird_font_widget_button_press ((BirdFontWidget*) _tmp0_, button, x, y);
	_tmp1_ = self->priv->cancel_button;
	bird_font_widget_button_press ((BirdFontWidget*) _tmp1_, button, x, y);
	_tmp2_ = self->priv->dont_ask_again_button;
	bird_font_widget_button_press ((BirdFontWidget*) _tmp2_, button, x, y);
}

static void
bird_font_overwrite_dialog_real_button_release (BirdFontWidget* base,
                                                guint button,
                                                gdouble x,
                                                gdouble y)
{
	BirdFontOverwriteDialog * self;
	BirdFontButton* _tmp0_;
	BirdFontButton* _tmp1_;
	BirdFontButton* _tmp2_;
	self = (BirdFontOverwriteDialog*) base;
	_tmp0_ = self->priv->overwrite_button;
	bird_font_widget_button_release ((BirdFontWidget*) _tmp0_, button, x, y);
	_tmp1_ = self->priv->cancel_button;
	bird_font_widget_button_release ((BirdFontWidget*) _tmp1_, button, x, y);
	_tmp2_ = self->priv->dont_ask_again_button;
	bird_font_widget_button_release ((BirdFontWidget*) _tmp2_, button, x, y);
}

static void
bird_font_overwrite_dialog_class_init (BirdFontOverwriteDialogClass * klass,
                                       gpointer klass_data)
{
	bird_font_overwrite_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BirdFontOverwriteDialog_private_offset);
	((BirdFontWidgetClass *) klass)->layout = (void (*) (BirdFontWidget*)) bird_font_overwrite_dialog_real_layout;
	((BirdFontWidgetClass *) klass)->draw = (void (*) (BirdFontWidget*, cairo_t*)) bird_font_overwrite_dialog_real_draw;
	((BirdFontWidgetClass *) klass)->button_press = (void (*) (BirdFontWidget*, guint, gdouble, gdouble)) bird_font_overwrite_dialog_real_button_press;
	((BirdFontWidgetClass *) klass)->button_release = (void (*) (BirdFontWidget*, guint, gdouble, gdouble)) bird_font_overwrite_dialog_real_button_release;
	G_OBJECT_CLASS (klass)->finalize = bird_font_overwrite_dialog_finalize;
}

static void
bird_font_overwrite_dialog_instance_init (BirdFontOverwriteDialog * self,
                                          gpointer klass)
{
	self->priv = bird_font_overwrite_dialog_get_instance_private (self);
	self->priv->width = (gdouble) 0;
}

static void
bird_font_overwrite_dialog_finalize (GObject * obj)
{
	BirdFontOverwriteDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_OVERWRITE_DIALOG, BirdFontOverwriteDialog);
	_g_object_unref0 (self->priv->listener);
	_g_object_unref0 (self->priv->question);
	_g_object_unref0 (self->priv->overwrite_button);
	_g_object_unref0 (self->priv->cancel_button);
	_g_object_unref0 (self->priv->dont_ask_again_button);
	G_OBJECT_CLASS (bird_font_overwrite_dialog_parent_class)->finalize (obj);
}

static GType
bird_font_overwrite_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontOverwriteDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_overwrite_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontOverwriteDialog), 0, (GInstanceInitFunc) bird_font_overwrite_dialog_instance_init, NULL };
	GType bird_font_overwrite_dialog_type_id;
	bird_font_overwrite_dialog_type_id = g_type_register_static (BIRD_FONT_TYPE_DIALOG, "BirdFontOverwriteDialog", &g_define_type_info, 0);
	BirdFontOverwriteDialog_private_offset = g_type_add_instance_private (bird_font_overwrite_dialog_type_id, sizeof (BirdFontOverwriteDialogPrivate));
	return bird_font_overwrite_dialog_type_id;
}

GType
bird_font_overwrite_dialog_get_type (void)
{
	static volatile gsize bird_font_overwrite_dialog_type_id__once = 0;
	if (g_once_init_enter (&bird_font_overwrite_dialog_type_id__once)) {
		GType bird_font_overwrite_dialog_type_id;
		bird_font_overwrite_dialog_type_id = bird_font_overwrite_dialog_get_type_once ();
		g_once_init_leave (&bird_font_overwrite_dialog_type_id__once, bird_font_overwrite_dialog_type_id);
	}
	return bird_font_overwrite_dialog_type_id__once;
}

