/* LicenseDialog.c generated by valac 0.56.17, the Vala compiler
 * generated from LicenseDialog.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>

#define BIRD_FONT_LICENSE_DIALOG_font_size ((gdouble) 20)
#define BIRD_FONT_LICENSE_DIALOG_margin ((gdouble) 20)
#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_LICENSE_DIALOG_0_PROPERTY,
	BIRD_FONT_LICENSE_DIALOG_NUM_PROPERTIES
};
static GParamSpec* bird_font_license_dialog_properties[BIRD_FONT_LICENSE_DIALOG_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _bird_font_color_unref0(var) ((var == NULL) ? NULL : (var = (bird_font_color_unref (var), NULL)))

struct _BirdFontLicenseDialogPrivate {
	BirdFontTextArea* agreement;
	BirdFontButton* accept;
	BirdFontButton* decline;
	gdouble width;
	gdouble height;
};

static gint BirdFontLicenseDialog_private_offset;
static gpointer bird_font_license_dialog_parent_class = NULL;

static void __lambda586_ (BirdFontLicenseDialog* self);
static void bird_font_license_dialog_commercial (BirdFontLicenseDialog* self);
static void ___lambda586__bird_font_button_action (BirdFontButton* _sender,
                                            gpointer self);
static void __lambda587_ (BirdFontLicenseDialog* self);
static void ___lambda587__bird_font_button_action (BirdFontButton* _sender,
                                            gpointer self);
static void bird_font_license_dialog_real_layout (BirdFontWidget* base);
static void bird_font_license_dialog_real_draw (BirdFontWidget* base,
                                         cairo_t* cr);
static void bird_font_license_dialog_real_button_press (BirdFontWidget* base,
                                                 guint button,
                                                 gdouble x,
                                                 gdouble y);
static void bird_font_license_dialog_real_button_release (BirdFontWidget* base,
                                                   guint button,
                                                   gdouble x,
                                                   gdouble y);
static void bird_font_license_dialog_exit (void);
static void _bird_font_license_dialog_exit_bird_font_message_dialog_close (BirdFontMessageDialog* _sender,
                                                                    gpointer self);
static void bird_font_license_dialog_finalize (GObject * obj);
static GType bird_font_license_dialog_get_type_once (void);

static inline gpointer
bird_font_license_dialog_get_instance_private (BirdFontLicenseDialog* self)
{
	return G_STRUCT_MEMBER_P (self, BirdFontLicenseDialog_private_offset);
}

static void
__lambda586_ (BirdFontLicenseDialog* self)
{
	bird_font_license_dialog_commercial (self);
}

static void
___lambda586__bird_font_button_action (BirdFontButton* _sender,
                                       gpointer self)
{
	__lambda586_ ((BirdFontLicenseDialog*) self);
}

static void
__lambda587_ (BirdFontLicenseDialog* self)
{
	BirdFontToolbox* _tmp0_;
	BirdFontToolbox* _tmp1_;
	bird_font_main_window_hide_dialog ();
	_tmp0_ = bird_font_main_window_get_toolbox ();
	_tmp1_ = _tmp0_;
	bird_font_toolbox_set_suppress_event (_tmp1_, FALSE);
	_g_object_unref0 (_tmp1_);
}

static void
___lambda587__bird_font_button_action (BirdFontButton* _sender,
                                       gpointer self)
{
	__lambda587_ ((BirdFontLicenseDialog*) self);
}

BirdFontLicenseDialog*
bird_font_license_dialog_construct (GType object_type)
{
	BirdFontLicenseDialog * self = NULL;
	BirdFontTextArea* _tmp0_;
	BirdFontTextArea* _tmp1_;
	BirdFontTextArea* _tmp2_;
	BirdFontTextArea* _tmp3_;
	BirdFontTextArea* _tmp4_;
	BirdFontColor* _tmp5_;
	BirdFontTextArea* _tmp6_;
	BirdFontButton* _tmp7_;
	BirdFontButton* _tmp8_;
	BirdFontButton* _tmp9_;
	BirdFontButton* _tmp10_;
	BirdFontToolbox* _tmp11_;
	BirdFontToolbox* _tmp12_;
	self = (BirdFontLicenseDialog*) bird_font_dialog_construct (object_type);
	_tmp0_ = bird_font_text_area_new (BIRD_FONT_LICENSE_DIALOG_font_size, NULL);
	_g_object_unref0 (self->priv->agreement);
	self->priv->agreement = _tmp0_;
	_tmp1_ = self->priv->agreement;
	_tmp1_->min_width = (gdouble) 300;
	_tmp2_ = self->priv->agreement;
	bird_font_text_area_set_editable (_tmp2_, FALSE);
	_tmp3_ = self->priv->agreement;
	_tmp3_->draw_border = FALSE;
	_tmp4_ = self->priv->agreement;
	_tmp5_ = bird_font_theme_get_color ("Text Tool Box");
	_bird_font_color_unref0 (_tmp4_->text_color);
	_tmp4_->text_color = _tmp5_;
	_tmp6_ = self->priv->agreement;
	bird_font_text_area_set_text (_tmp6_, "BirdFont is developed with donations, please consider donating to the " \
"project.\n" \
"\n" \
"This is the freeware version of BirdFont. You may use it for creating " \
"fonts under the SIL Open Font License.\n" \
"\n" \
"Which license do you want to use for your font?");
	_tmp7_ = bird_font_button_new ("Commercial License", (gdouble) 0);
	_g_object_unref0 (self->priv->decline);
	self->priv->decline = _tmp7_;
	_tmp8_ = self->priv->decline;
	g_signal_connect_object (_tmp8_, "action", (GCallback) ___lambda586__bird_font_button_action, self, 0);
	_tmp9_ = bird_font_button_new ("SIL Open Font License", (gdouble) 0);
	_g_object_unref0 (self->priv->accept);
	self->priv->accept = _tmp9_;
	_tmp10_ = self->priv->accept;
	g_signal_connect_object (_tmp10_, "action", (GCallback) ___lambda587__bird_font_button_action, self, 0);
	_tmp11_ = bird_font_main_window_get_toolbox ();
	_tmp12_ = _tmp11_;
	bird_font_toolbox_set_suppress_event (_tmp12_, TRUE);
	_g_object_unref0 (_tmp12_);
	self->priv->height = (gdouble) 240;
	return self;
}

BirdFontLicenseDialog*
bird_font_license_dialog_new (void)
{
	return bird_font_license_dialog_construct (BIRD_FONT_TYPE_LICENSE_DIALOG);
}

static void
bird_font_license_dialog_real_layout (BirdFontWidget* base)
{
	BirdFontLicenseDialog * self;
	gdouble cx = 0.0;
	gdouble cy = 0.0;
	BirdFontWidgetAllocation* _tmp0_;
	gdouble center = 0.0;
	gdouble h = 0.0;
	BirdFontButton* _tmp1_;
	BirdFontButton* _tmp2_;
	BirdFontButton* _tmp3_;
	BirdFontTextArea* _tmp4_;
	BirdFontWidgetAllocation* _tmp5_;
	BirdFontTextArea* _tmp6_;
	BirdFontTextArea* _tmp7_;
	BirdFontTextArea* _tmp8_;
	BirdFontWidgetAllocation* _tmp9_;
	BirdFontTextArea* _tmp10_;
	BirdFontTextArea* _tmp11_;
	BirdFontButton* _tmp12_;
	BirdFontButton* _tmp13_;
	BirdFontButton* _tmp14_;
	BirdFontButton* _tmp15_;
	BirdFontButton* _tmp16_;
	BirdFontButton* _tmp17_;
	self = (BirdFontLicenseDialog*) base;
	cx = (gdouble) 0;
	_tmp0_ = ((BirdFontWidget*) self)->allocation;
	cy = (_tmp0_->height - self->priv->height) / 2.0;
	cx = BIRD_FONT_LICENSE_DIALOG_margin;
	_tmp1_ = self->priv->decline;
	((BirdFontWidget*) _tmp1_)->widget_x = cx;
	_tmp2_ = self->priv->decline;
	cx += BIRD_FONT_LICENSE_DIALOG_margin + bird_font_widget_get_width ((BirdFontWidget*) _tmp2_);
	_tmp3_ = self->priv->accept;
	((BirdFontWidget*) _tmp3_)->widget_x = cx;
	_tmp4_ = self->priv->agreement;
	self->priv->width = bird_font_widget_get_width ((BirdFontWidget*) _tmp4_) + BIRD_FONT_LICENSE_DIALOG_margin;
	_tmp5_ = ((BirdFontWidget*) self)->allocation;
	center = (_tmp5_->width - self->priv->width) / 2.0;
	_tmp6_ = self->priv->agreement;
	((BirdFontWidget*) _tmp6_)->widget_x = BIRD_FONT_LICENSE_DIALOG_margin + center;
	_tmp7_ = self->priv->agreement;
	((BirdFontWidget*) _tmp7_)->widget_y = cy + BIRD_FONT_LICENSE_DIALOG_margin;
	_tmp8_ = self->priv->agreement;
	_tmp9_ = bird_font_widget_allocation_new_for_area (0, 0, 300, 450);
	_g_object_unref0 (((BirdFontWidget*) _tmp8_)->allocation);
	((BirdFontWidget*) _tmp8_)->allocation = _tmp9_;
	_tmp10_ = self->priv->agreement;
	bird_font_widget_layout ((BirdFontWidget*) _tmp10_);
	_tmp11_ = self->priv->agreement;
	h = bird_font_widget_get_height ((BirdFontWidget*) _tmp11_) + BIRD_FONT_LICENSE_DIALOG_margin;
	_tmp12_ = self->priv->decline;
	_tmp13_ = self->priv->decline;
	((BirdFontWidget*) _tmp13_)->widget_x = ((BirdFontWidget*) _tmp13_)->widget_x + center;
	_tmp14_ = self->priv->decline;
	((BirdFontWidget*) _tmp14_)->widget_y = (cy + h) + BIRD_FONT_LICENSE_DIALOG_margin;
	_tmp15_ = self->priv->accept;
	_tmp16_ = self->priv->accept;
	((BirdFontWidget*) _tmp16_)->widget_x = ((BirdFontWidget*) _tmp16_)->widget_x + center;
	_tmp17_ = self->priv->accept;
	((BirdFontWidget*) _tmp17_)->widget_y = (cy + h) + BIRD_FONT_LICENSE_DIALOG_margin;
}

static void
bird_font_license_dialog_real_draw (BirdFontWidget* base,
                                    cairo_t* cr)
{
	BirdFontLicenseDialog * self;
	gdouble cx = 0.0;
	gdouble cy = 0.0;
	BirdFontWidgetAllocation* _tmp0_;
	BirdFontWidgetAllocation* _tmp1_;
	BirdFontWidgetAllocation* _tmp2_;
	BirdFontWidgetAllocation* _tmp3_;
	BirdFontButton* _tmp4_;
	BirdFontButton* _tmp5_;
	BirdFontTextArea* _tmp6_;
	self = (BirdFontLicenseDialog*) 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->decline;
	bird_font_widget_draw ((BirdFontWidget*) _tmp4_, cr);
	_tmp5_ = self->priv->accept;
	bird_font_widget_draw ((BirdFontWidget*) _tmp5_, cr);
	_tmp6_ = self->priv->agreement;
	bird_font_widget_draw ((BirdFontWidget*) _tmp6_, cr);
}

static void
bird_font_license_dialog_real_button_press (BirdFontWidget* base,
                                            guint button,
                                            gdouble x,
                                            gdouble y)
{
	BirdFontLicenseDialog * self;
	BirdFontButton* _tmp0_;
	BirdFontButton* _tmp1_;
	self = (BirdFontLicenseDialog*) base;
	_tmp0_ = self->priv->decline;
	bird_font_widget_button_press ((BirdFontWidget*) _tmp0_, button, x, y);
	_tmp1_ = self->priv->accept;
	bird_font_widget_button_press ((BirdFontWidget*) _tmp1_, button, x, y);
}

static void
bird_font_license_dialog_real_button_release (BirdFontWidget* base,
                                              guint button,
                                              gdouble x,
                                              gdouble y)
{
	BirdFontLicenseDialog * self;
	BirdFontButton* _tmp0_;
	BirdFontButton* _tmp1_;
	self = (BirdFontLicenseDialog*) base;
	_tmp0_ = self->priv->decline;
	bird_font_widget_button_release ((BirdFontWidget*) _tmp0_, button, x, y);
	_tmp1_ = self->priv->accept;
	bird_font_widget_button_release ((BirdFontWidget*) _tmp1_, button, x, y);
}

static void
_bird_font_license_dialog_exit_bird_font_message_dialog_close (BirdFontMessageDialog* _sender,
                                                               gpointer self)
{
	bird_font_license_dialog_exit ();
}

static void
bird_font_license_dialog_commercial (BirdFontLicenseDialog* self)
{
	BirdFontMessageDialog* md = NULL;
	BirdFontMessageDialog* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = bird_font_message_dialog_new ("You need to get a commercial copy of BirdFont. Visit to birdfont.org");
	md = _tmp0_;
	g_signal_connect (md, "close", (GCallback) _bird_font_license_dialog_exit_bird_font_message_dialog_close, NULL);
	bird_font_main_window_show_dialog ((BirdFontDialog*) md);
	_g_object_unref0 (md);
}

static void
bird_font_license_dialog_exit (void)
{
	BirdFontNativeWindow* _tmp0_;
	_tmp0_ = bird_font_main_window_native_window;
	bird_font_native_window_quit (_tmp0_);
}

static void
bird_font_license_dialog_class_init (BirdFontLicenseDialogClass * klass,
                                     gpointer klass_data)
{
	bird_font_license_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BirdFontLicenseDialog_private_offset);
	((BirdFontWidgetClass *) klass)->layout = (void (*) (BirdFontWidget*)) bird_font_license_dialog_real_layout;
	((BirdFontWidgetClass *) klass)->draw = (void (*) (BirdFontWidget*, cairo_t*)) bird_font_license_dialog_real_draw;
	((BirdFontWidgetClass *) klass)->button_press = (void (*) (BirdFontWidget*, guint, gdouble, gdouble)) bird_font_license_dialog_real_button_press;
	((BirdFontWidgetClass *) klass)->button_release = (void (*) (BirdFontWidget*, guint, gdouble, gdouble)) bird_font_license_dialog_real_button_release;
	G_OBJECT_CLASS (klass)->finalize = bird_font_license_dialog_finalize;
}

static void
bird_font_license_dialog_instance_init (BirdFontLicenseDialog * self,
                                        gpointer klass)
{
	self->priv = bird_font_license_dialog_get_instance_private (self);
	self->priv->width = (gdouble) 0;
}

static void
bird_font_license_dialog_finalize (GObject * obj)
{
	BirdFontLicenseDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_LICENSE_DIALOG, BirdFontLicenseDialog);
	_g_object_unref0 (self->priv->agreement);
	_g_object_unref0 (self->priv->accept);
	_g_object_unref0 (self->priv->decline);
	G_OBJECT_CLASS (bird_font_license_dialog_parent_class)->finalize (obj);
}

static GType
bird_font_license_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontLicenseDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_license_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontLicenseDialog), 0, (GInstanceInitFunc) bird_font_license_dialog_instance_init, NULL };
	GType bird_font_license_dialog_type_id;
	bird_font_license_dialog_type_id = g_type_register_static (BIRD_FONT_TYPE_DIALOG, "BirdFontLicenseDialog", &g_define_type_info, 0);
	BirdFontLicenseDialog_private_offset = g_type_add_instance_private (bird_font_license_dialog_type_id, sizeof (BirdFontLicenseDialogPrivate));
	return bird_font_license_dialog_type_id;
}

GType
bird_font_license_dialog_get_type (void)
{
	static volatile gsize bird_font_license_dialog_type_id__once = 0;
	if (g_once_init_enter (&bird_font_license_dialog_type_id__once)) {
		GType bird_font_license_dialog_type_id;
		bird_font_license_dialog_type_id = bird_font_license_dialog_get_type_once ();
		g_once_init_leave (&bird_font_license_dialog_type_id__once, bird_font_license_dialog_type_id);
	}
	return bird_font_license_dialog_type_id__once;
}

