/* QuestionDialog.c generated by valac 0.56.17, the Vala compiler
 * generated from QuestionDialog.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>
#include <gee.h>

#define BIRD_FONT_QUESTION_DIALOG_font_size ((gdouble) 20)
#define BIRD_FONT_QUESTION_DIALOG_margin ((gdouble) 20)
#define BIRD_FONT_QUESTION_DIALOG_margin_small ((gdouble) 5)
#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_QUESTION_DIALOG_0_PROPERTY,
	BIRD_FONT_QUESTION_DIALOG_NUM_PROPERTIES
};
static GParamSpec* bird_font_question_dialog_properties[BIRD_FONT_QUESTION_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 _BirdFontQuestionDialogPrivate {
	BirdFontTextArea* question;
	gdouble width;
	gdouble height;
};

static gint BirdFontQuestionDialog_private_offset;
static gpointer bird_font_question_dialog_parent_class = NULL;

static void bird_font_question_dialog_real_layout (BirdFontWidget* base);
static void bird_font_question_dialog_real_draw (BirdFontWidget* base,
                                          cairo_t* cr);
static void bird_font_question_dialog_real_button_press (BirdFontWidget* base,
                                                  guint button,
                                                  gdouble x,
                                                  gdouble y);
static void bird_font_question_dialog_real_button_release (BirdFontWidget* base,
                                                    guint button,
                                                    gdouble x,
                                                    gdouble y);
static void bird_font_question_dialog_finalize (GObject * obj);
static GType bird_font_question_dialog_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
bird_font_question_dialog_get_instance_private (BirdFontQuestionDialog* self)
{
	return G_STRUCT_MEMBER_P (self, BirdFontQuestionDialog_private_offset);
}

BirdFontQuestionDialog*
bird_font_question_dialog_construct (GType object_type,
                                     const gchar* message)
{
	BirdFontQuestionDialog * self = NULL;
	BirdFontTextArea* _tmp0_;
	BirdFontTextArea* _tmp1_;
	BirdFontTextArea* _tmp2_;
	BirdFontTextArea* _tmp3_;
	BirdFontTextArea* _tmp4_;
	BirdFontTextArea* _tmp5_;
	BirdFontColor* _tmp6_;
	BirdFontTextArea* _tmp7_;
	GeeArrayList* _tmp8_;
	g_return_val_if_fail (message != NULL, NULL);
	self = (BirdFontQuestionDialog*) bird_font_dialog_construct (object_type);
	_tmp0_ = bird_font_text_area_new (BIRD_FONT_QUESTION_DIALOG_font_size, NULL);
	_g_object_unref0 (self->priv->question);
	self->priv->question = _tmp0_;
	_tmp1_ = self->priv->question;
	_tmp1_->min_width = (gdouble) 300;
	_tmp2_ = self->priv->question;
	_tmp2_->min_height = BIRD_FONT_QUESTION_DIALOG_font_size;
	_tmp3_ = self->priv->question;
	bird_font_text_area_set_editable (_tmp3_, FALSE);
	_tmp4_ = self->priv->question;
	_tmp4_->draw_border = FALSE;
	_tmp5_ = self->priv->question;
	_tmp6_ = bird_font_theme_get_color ("Text Tool Box");
	_bird_font_color_unref0 (_tmp5_->text_color);
	_tmp5_->text_color = _tmp6_;
	_tmp7_ = self->priv->question;
	bird_font_text_area_set_text (_tmp7_, message);
	_tmp8_ = gee_array_list_new (BIRD_FONT_TYPE_BUTTON, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (self->buttons);
	self->buttons = _tmp8_;
	return self;
}

BirdFontQuestionDialog*
bird_font_question_dialog_new (const gchar* message)
{
	return bird_font_question_dialog_construct (BIRD_FONT_TYPE_QUESTION_DIALOG, message);
}

void
bird_font_question_dialog_add_button (BirdFontQuestionDialog* self,
                                      BirdFontButton* button)
{
	GeeArrayList* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (button != NULL);
	_tmp0_ = self->buttons;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp0_, button);
}

static void
bird_font_question_dialog_real_layout (BirdFontWidget* base)
{
	BirdFontQuestionDialog * self;
	gdouble cx = 0.0;
	gdouble cy = 0.0;
	gdouble center = 0.0;
	gdouble h = 0.0;
	BirdFontTextArea* _tmp10_;
	BirdFontWidgetAllocation* _tmp11_;
	BirdFontTextArea* _tmp12_;
	BirdFontTextArea* _tmp13_;
	BirdFontWidgetAllocation* _tmp14_;
	BirdFontTextArea* _tmp15_;
	BirdFontTextArea* _tmp16_;
	GeeArrayList* _tmp27_;
	gint _tmp28_;
	gint _tmp29_;
	BirdFontWidgetAllocation* _tmp33_;
	BirdFontTextArea* _tmp43_;
	self = (BirdFontQuestionDialog*) base;
	cx = (gdouble) 0;
	cx = BIRD_FONT_QUESTION_DIALOG_margin;
	{
		GeeArrayList* _button_list = NULL;
		GeeArrayList* _tmp0_;
		gint _button_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _button_index = 0;
		_tmp0_ = self->buttons;
		_button_list = _tmp0_;
		_tmp1_ = _button_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_button_size = _tmp3_;
		_button_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			BirdFontButton* button = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			BirdFontButton* _tmp8_;
			BirdFontButton* _tmp9_;
			_button_index = _button_index + 1;
			_tmp4_ = _button_index;
			_tmp5_ = _button_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _button_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _button_index);
			button = (BirdFontButton*) _tmp7_;
			_tmp8_ = button;
			((BirdFontWidget*) _tmp8_)->widget_x = cx;
			_tmp9_ = button;
			cx += BIRD_FONT_QUESTION_DIALOG_margin + bird_font_widget_get_width ((BirdFontWidget*) _tmp9_);
			_g_object_unref0 (button);
		}
	}
	_tmp10_ = self->priv->question;
	self->priv->width = bird_font_widget_get_width ((BirdFontWidget*) _tmp10_) + BIRD_FONT_QUESTION_DIALOG_margin;
	_tmp11_ = ((BirdFontWidget*) self)->allocation;
	center = (_tmp11_->width - self->priv->width) / 2.0;
	_tmp12_ = self->priv->question;
	((BirdFontWidget*) _tmp12_)->widget_x = BIRD_FONT_QUESTION_DIALOG_margin + center;
	_tmp13_ = self->priv->question;
	_tmp14_ = bird_font_widget_allocation_new_for_area (0, 0, 3000, 3000);
	_g_object_unref0 (((BirdFontWidget*) _tmp13_)->allocation);
	((BirdFontWidget*) _tmp13_)->allocation = _tmp14_;
	_tmp15_ = self->priv->question;
	bird_font_widget_layout ((BirdFontWidget*) _tmp15_);
	_tmp16_ = self->priv->question;
	h = bird_font_widget_get_height ((BirdFontWidget*) _tmp16_) + BIRD_FONT_QUESTION_DIALOG_margin;
	{
		GeeArrayList* _button_list = NULL;
		GeeArrayList* _tmp17_;
		gint _button_size = 0;
		GeeArrayList* _tmp18_;
		gint _tmp19_;
		gint _tmp20_;
		gint _button_index = 0;
		_tmp17_ = self->buttons;
		_button_list = _tmp17_;
		_tmp18_ = _button_list;
		_tmp19_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp18_);
		_tmp20_ = _tmp19_;
		_button_size = _tmp20_;
		_button_index = -1;
		while (TRUE) {
			gint _tmp21_;
			gint _tmp22_;
			BirdFontButton* button = NULL;
			GeeArrayList* _tmp23_;
			gpointer _tmp24_;
			BirdFontButton* _tmp25_;
			BirdFontButton* _tmp26_;
			_button_index = _button_index + 1;
			_tmp21_ = _button_index;
			_tmp22_ = _button_size;
			if (!(_tmp21_ < _tmp22_)) {
				break;
			}
			_tmp23_ = _button_list;
			_tmp24_ = gee_abstract_list_get ((GeeAbstractList*) _tmp23_, _button_index);
			button = (BirdFontButton*) _tmp24_;
			_tmp25_ = button;
			_tmp26_ = button;
			((BirdFontWidget*) _tmp26_)->widget_x = ((BirdFontWidget*) _tmp26_)->widget_x + center;
			_g_object_unref0 (button);
		}
	}
	self->priv->height = (h + BIRD_FONT_QUESTION_DIALOG_margin) + BIRD_FONT_QUESTION_DIALOG_margin_small;
	_tmp27_ = self->buttons;
	_tmp28_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp27_);
	_tmp29_ = _tmp28_;
	if (_tmp29_ > 0) {
		GeeArrayList* _tmp30_;
		gpointer _tmp31_;
		BirdFontButton* _tmp32_;
		_tmp30_ = self->buttons;
		_tmp31_ = gee_abstract_list_get ((GeeAbstractList*) _tmp30_, 0);
		_tmp32_ = (BirdFontButton*) _tmp31_;
		self->priv->height = self->priv->height + bird_font_widget_get_height ((BirdFontWidget*) _tmp32_);
		_g_object_unref0 (_tmp32_);
	}
	_tmp33_ = ((BirdFontWidget*) self)->allocation;
	cy = (_tmp33_->height - self->priv->height) / 2.0;
	{
		GeeArrayList* _button_list = NULL;
		GeeArrayList* _tmp34_;
		gint _button_size = 0;
		GeeArrayList* _tmp35_;
		gint _tmp36_;
		gint _tmp37_;
		gint _button_index = 0;
		_tmp34_ = self->buttons;
		_button_list = _tmp34_;
		_tmp35_ = _button_list;
		_tmp36_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp35_);
		_tmp37_ = _tmp36_;
		_button_size = _tmp37_;
		_button_index = -1;
		while (TRUE) {
			gint _tmp38_;
			gint _tmp39_;
			BirdFontButton* button = NULL;
			GeeArrayList* _tmp40_;
			gpointer _tmp41_;
			BirdFontButton* _tmp42_;
			_button_index = _button_index + 1;
			_tmp38_ = _button_index;
			_tmp39_ = _button_size;
			if (!(_tmp38_ < _tmp39_)) {
				break;
			}
			_tmp40_ = _button_list;
			_tmp41_ = gee_abstract_list_get ((GeeAbstractList*) _tmp40_, _button_index);
			button = (BirdFontButton*) _tmp41_;
			_tmp42_ = button;
			((BirdFontWidget*) _tmp42_)->widget_y = (cy + h) + BIRD_FONT_QUESTION_DIALOG_margin_small;
			_g_object_unref0 (button);
		}
	}
	_tmp43_ = self->priv->question;
	((BirdFontWidget*) _tmp43_)->widget_y = cy + BIRD_FONT_QUESTION_DIALOG_margin;
}

static void
bird_font_question_dialog_real_draw (BirdFontWidget* base,
                                     cairo_t* cr)
{
	BirdFontQuestionDialog * self;
	gdouble cx = 0.0;
	gdouble cy = 0.0;
	BirdFontWidgetAllocation* _tmp0_;
	BirdFontWidgetAllocation* _tmp1_;
	BirdFontWidgetAllocation* _tmp2_;
	BirdFontWidgetAllocation* _tmp3_;
	BirdFontTextArea* _tmp13_;
	self = (BirdFontQuestionDialog*) base;
	g_return_if_fail (cr != NULL);
	_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);
	{
		GeeArrayList* _button_list = NULL;
		GeeArrayList* _tmp4_;
		gint _button_size = 0;
		GeeArrayList* _tmp5_;
		gint _tmp6_;
		gint _tmp7_;
		gint _button_index = 0;
		_tmp4_ = self->buttons;
		_button_list = _tmp4_;
		_tmp5_ = _button_list;
		_tmp6_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp5_);
		_tmp7_ = _tmp6_;
		_button_size = _tmp7_;
		_button_index = -1;
		while (TRUE) {
			gint _tmp8_;
			gint _tmp9_;
			BirdFontButton* button = NULL;
			GeeArrayList* _tmp10_;
			gpointer _tmp11_;
			BirdFontButton* _tmp12_;
			_button_index = _button_index + 1;
			_tmp8_ = _button_index;
			_tmp9_ = _button_size;
			if (!(_tmp8_ < _tmp9_)) {
				break;
			}
			_tmp10_ = _button_list;
			_tmp11_ = gee_abstract_list_get ((GeeAbstractList*) _tmp10_, _button_index);
			button = (BirdFontButton*) _tmp11_;
			_tmp12_ = button;
			bird_font_widget_draw ((BirdFontWidget*) _tmp12_, cr);
			_g_object_unref0 (button);
		}
	}
	_tmp13_ = self->priv->question;
	bird_font_widget_draw ((BirdFontWidget*) _tmp13_, cr);
}

static void
bird_font_question_dialog_real_button_press (BirdFontWidget* base,
                                             guint button,
                                             gdouble x,
                                             gdouble y)
{
	BirdFontQuestionDialog * self;
	self = (BirdFontQuestionDialog*) base;
	{
		GeeArrayList* _b_list = NULL;
		GeeArrayList* _tmp0_;
		gint _b_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _b_index = 0;
		_tmp0_ = self->buttons;
		_b_list = _tmp0_;
		_tmp1_ = _b_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_b_size = _tmp3_;
		_b_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			BirdFontButton* b = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			BirdFontButton* _tmp8_;
			_b_index = _b_index + 1;
			_tmp4_ = _b_index;
			_tmp5_ = _b_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _b_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _b_index);
			b = (BirdFontButton*) _tmp7_;
			_tmp8_ = b;
			bird_font_widget_button_press ((BirdFontWidget*) _tmp8_, button, x, y);
			_g_object_unref0 (b);
		}
	}
}

static void
bird_font_question_dialog_real_button_release (BirdFontWidget* base,
                                               guint button,
                                               gdouble x,
                                               gdouble y)
{
	BirdFontQuestionDialog * self;
	self = (BirdFontQuestionDialog*) base;
	{
		GeeArrayList* _b_list = NULL;
		GeeArrayList* _tmp0_;
		gint _b_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _b_index = 0;
		_tmp0_ = self->buttons;
		_b_list = _tmp0_;
		_tmp1_ = _b_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_b_size = _tmp3_;
		_b_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			BirdFontButton* b = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			BirdFontButton* _tmp8_;
			_b_index = _b_index + 1;
			_tmp4_ = _b_index;
			_tmp5_ = _b_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _b_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _b_index);
			b = (BirdFontButton*) _tmp7_;
			_tmp8_ = b;
			bird_font_widget_button_release ((BirdFontWidget*) _tmp8_, button, x, y);
			_g_object_unref0 (b);
		}
	}
}

static void
bird_font_question_dialog_class_init (BirdFontQuestionDialogClass * klass,
                                      gpointer klass_data)
{
	bird_font_question_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BirdFontQuestionDialog_private_offset);
	((BirdFontWidgetClass *) klass)->layout = (void (*) (BirdFontWidget*)) bird_font_question_dialog_real_layout;
	((BirdFontWidgetClass *) klass)->draw = (void (*) (BirdFontWidget*, cairo_t*)) bird_font_question_dialog_real_draw;
	((BirdFontWidgetClass *) klass)->button_press = (void (*) (BirdFontWidget*, guint, gdouble, gdouble)) bird_font_question_dialog_real_button_press;
	((BirdFontWidgetClass *) klass)->button_release = (void (*) (BirdFontWidget*, guint, gdouble, gdouble)) bird_font_question_dialog_real_button_release;
	G_OBJECT_CLASS (klass)->finalize = bird_font_question_dialog_finalize;
}

static void
bird_font_question_dialog_instance_init (BirdFontQuestionDialog * self,
                                         gpointer klass)
{
	self->priv = bird_font_question_dialog_get_instance_private (self);
	self->priv->width = (gdouble) 300;
	self->priv->height = (gdouble) 0;
}

static void
bird_font_question_dialog_finalize (GObject * obj)
{
	BirdFontQuestionDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_QUESTION_DIALOG, BirdFontQuestionDialog);
	_g_object_unref0 (self->priv->question);
	_g_object_unref0 (self->buttons);
	G_OBJECT_CLASS (bird_font_question_dialog_parent_class)->finalize (obj);
}

static GType
bird_font_question_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontQuestionDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_question_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontQuestionDialog), 0, (GInstanceInitFunc) bird_font_question_dialog_instance_init, NULL };
	GType bird_font_question_dialog_type_id;
	bird_font_question_dialog_type_id = g_type_register_static (BIRD_FONT_TYPE_DIALOG, "BirdFontQuestionDialog", &g_define_type_info, 0);
	BirdFontQuestionDialog_private_offset = g_type_add_instance_private (bird_font_question_dialog_type_id, sizeof (BirdFontQuestionDialogPrivate));
	return bird_font_question_dialog_type_id;
}

GType
bird_font_question_dialog_get_type (void)
{
	static volatile gsize bird_font_question_dialog_type_id__once = 0;
	if (g_once_init_enter (&bird_font_question_dialog_type_id__once)) {
		GType bird_font_question_dialog_type_id;
		bird_font_question_dialog_type_id = bird_font_question_dialog_get_type_once ();
		g_once_init_leave (&bird_font_question_dialog_type_id__once, bird_font_question_dialog_type_id);
	}
	return bird_font_question_dialog_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;
}

