/* UtilsView.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from UtilsView.vala, do not modify */

/*
 * Copyright 2018 elementary, Inc. (https://elementary.io)
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#include "granite-7.h"
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <gio/gio.h>

#define UTILS_VIEW_CSS "\n" \
"        .contrast-demo {\n" \
"            background: %s;\n" \
"            color: %s;\n" \
"            text-shadow: none;\n" \
"        }\n" \
"    "
#define UTILS_VIEW_DARK_BG "#273445"
#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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define TYPE_DEMO_PAGE (demo_page_get_type ())
#define DEMO_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DEMO_PAGE, DemoPage))
#define DEMO_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DEMO_PAGE, DemoPageClass))
#define IS_DEMO_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DEMO_PAGE))
#define IS_DEMO_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DEMO_PAGE))
#define DEMO_PAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DEMO_PAGE, DemoPageClass))

typedef struct _DemoPage DemoPage;
typedef struct _DemoPageClass DemoPageClass;
typedef struct _DemoPagePrivate DemoPagePrivate;

#define TYPE_UTILS_VIEW (utils_view_get_type ())
#define UTILS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_UTILS_VIEW, UtilsView))
#define UTILS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_UTILS_VIEW, UtilsViewClass))
#define IS_UTILS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_UTILS_VIEW))
#define IS_UTILS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_UTILS_VIEW))
#define UTILS_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_UTILS_VIEW, UtilsViewClass))

typedef struct _UtilsView UtilsView;
typedef struct _UtilsViewClass UtilsViewClass;
typedef struct _UtilsViewPrivate UtilsViewPrivate;
enum  {
	UTILS_VIEW_0_PROPERTY,
	UTILS_VIEW_NUM_PROPERTIES
};
static GParamSpec* utils_view_properties[UTILS_VIEW_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block8Data Block8Data;
typedef struct _Block9Data Block9Data;
#define __vala_GdkRGBA_free0(var) ((var == NULL) ? NULL : (var = (_vala_GdkRGBA_free (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _DemoPage {
	GraniteToolBox parent_instance;
	DemoPagePrivate * priv;
};

struct _DemoPageClass {
	GraniteToolBoxClass parent_class;
};

struct _UtilsView {
	DemoPage parent_instance;
	UtilsViewPrivate * priv;
};

struct _UtilsViewClass {
	DemoPageClass parent_class;
};

struct _Block8Data {
	int _ref_count_;
	UtilsView* self;
	GdkRGBA gdk_demo_bg;
};

struct _Block9Data {
	int _ref_count_;
	Block8Data * _data8_;
	GtkColorDialog* dialog;
};

static gpointer utils_view_parent_class = NULL;

VALA_EXTERN GType demo_page_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DemoPage, g_object_unref)
VALA_EXTERN GType utils_view_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UtilsView, g_object_unref)
static void utils_view_style_contrast_demo (UtilsView* self,
                                     GdkRGBA* bg_color);
VALA_EXTERN UtilsView* utils_view_new (void);
VALA_EXTERN UtilsView* utils_view_construct (GType object_type);
VALA_EXTERN DemoPage* demo_page_new (void);
VALA_EXTERN DemoPage* demo_page_construct (GType object_type);
static GObject * utils_view_constructor (GType type,
                                  guint n_construct_properties,
                                  GObjectConstructParam * construct_properties);
static Block8Data* block8_data_ref (Block8Data* _data8_);
static void block8_data_unref (void * _userdata_);
VALA_EXTERN void demo_page_set_child (DemoPage* self,
                          GtkWidget* value);
static void _utils_view___lambda13_ (Block8Data* _data8_);
static Block9Data* block9_data_ref (Block9Data* _data9_);
static void block9_data_unref (void * _userdata_);
static void __lambda14_ (Block9Data* _data9_,
                  GObject* obj,
                  GAsyncResult* res);
static void _vala_GdkRGBA_free (GdkRGBA* self);
static void ___lambda14__gasync_ready_callback (GObject* source_object,
                                         GAsyncResult* res,
                                         gpointer self);
static void __utils_view___lambda13__gtk_button_clicked (GtkButton* _sender,
                                                  gpointer self);
static GType utils_view_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

static void
utils_view_style_contrast_demo (UtilsView* self,
                                GdkRGBA* bg_color)
{
	GtkCssProvider* provider = NULL;
	GtkCssProvider* _tmp0_;
	gchar* css = NULL;
	gchar* _tmp1_;
	gchar* _tmp2_;
	GdkRGBA _tmp3_;
	GdkRGBA _tmp4_ = {0};
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	GdkDisplay* _tmp9_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (bg_color != NULL);
	_tmp0_ = gtk_css_provider_new ();
	provider = _tmp0_;
	_tmp1_ = gdk_rgba_to_string (bg_color);
	_tmp2_ = _tmp1_;
	_tmp3_ = *bg_color;
	granite_contrasting_foreground_color (&_tmp3_, &_tmp4_);
	_tmp5_ = gdk_rgba_to_string (&_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = g_strdup_printf (UTILS_VIEW_CSS, _tmp2_, _tmp6_);
	_tmp8_ = _tmp7_;
	_g_free0 (_tmp6_);
	_g_free0 (_tmp2_);
	css = _tmp8_;
	gtk_css_provider_load_from_string (provider, css);
	_tmp9_ = gdk_display_get_default ();
	gtk_style_context_add_provider_for_display (_tmp9_, (GtkStyleProvider*) provider, (guint) GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
	_g_free0 (css);
	_g_object_unref0 (provider);
}

UtilsView*
utils_view_construct (GType object_type)
{
	UtilsView * self = NULL;
	self = (UtilsView*) demo_page_construct (object_type);
	return self;
}

UtilsView*
utils_view_new (void)
{
	return utils_view_construct (TYPE_UTILS_VIEW);
}

static Block8Data*
block8_data_ref (Block8Data* _data8_)
{
	g_atomic_int_inc (&_data8_->_ref_count_);
	return _data8_;
}

static void
block8_data_unref (void * _userdata_)
{
	Block8Data* _data8_;
	_data8_ = (Block8Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data8_->_ref_count_)) {
		UtilsView* self;
		self = _data8_->self;
		_g_object_unref0 (self);
		g_slice_free (Block8Data, _data8_);
	}
}

static Block9Data*
block9_data_ref (Block9Data* _data9_)
{
	g_atomic_int_inc (&_data9_->_ref_count_);
	return _data9_;
}

static void
block9_data_unref (void * _userdata_)
{
	Block9Data* _data9_;
	_data9_ = (Block9Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data9_->_ref_count_)) {
		UtilsView* self;
		self = _data9_->_data8_->self;
		_g_object_unref0 (_data9_->dialog);
		block8_data_unref (_data9_->_data8_);
		_data9_->_data8_ = NULL;
		g_slice_free (Block9Data, _data9_);
	}
}

static void
_vala_GdkRGBA_free (GdkRGBA* self)
{
	g_boxed_free (gdk_rgba_get_type (), self);
}

static void
__lambda14_ (Block9Data* _data9_,
             GObject* obj,
             GAsyncResult* res)
{
	Block8Data* _data8_;
	UtilsView* self;
	GError* _inner_error0_ = NULL;
	_data8_ = _data9_->_data8_;
	self = _data8_->self;
	g_return_if_fail (res != NULL);
	{
		GdkRGBA* _tmp0_ = NULL;
		GtkColorDialog* _tmp1_;
		GdkRGBA* _tmp2_;
		GdkRGBA* _tmp3_;
		GdkRGBA* _tmp4_;
		GdkRGBA _tmp5_;
		_tmp1_ = _data9_->dialog;
		_tmp2_ = gtk_color_dialog_choose_rgba_finish (_tmp1_, res, &_inner_error0_);
		_tmp0_ = _tmp2_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp3_ = _tmp0_;
		_tmp0_ = NULL;
		_tmp4_ = _tmp3_;
		_data8_->gdk_demo_bg = *_tmp4_;
		__vala_GdkRGBA_free0 (_tmp4_);
		_tmp5_ = _data8_->gdk_demo_bg;
		utils_view_style_contrast_demo (self, &_tmp5_);
		__vala_GdkRGBA_free0 (_tmp0_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp6_;
		const gchar* _tmp7_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp6_ = e;
		_tmp7_ = _tmp6_->message;
		g_debug ("UtilsView.vala:60: %s", _tmp7_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
}

static void
___lambda14__gasync_ready_callback (GObject* source_object,
                                    GAsyncResult* res,
                                    gpointer self)
{
	__lambda14_ (self, source_object, res);
	block9_data_unref (self);
}

static void
_utils_view___lambda13_ (Block8Data* _data8_)
{
	UtilsView* self;
	Block9Data* _data9_;
	GtkColorDialog* _tmp0_;
	GtkColorDialog* _tmp1_;
	GtkRoot* _tmp2_;
	GdkRGBA _tmp3_;
	self = _data8_->self;
	_data9_ = g_slice_new0 (Block9Data);
	_data9_->_ref_count_ = 1;
	_data9_->_data8_ = block8_data_ref (_data8_);
	_tmp0_ = gtk_color_dialog_new ();
	_data9_->dialog = _tmp0_;
	_tmp1_ = _data9_->dialog;
	_tmp2_ = gtk_widget_get_root ((GtkWidget*) self);
	_tmp3_ = _data8_->gdk_demo_bg;
	gtk_color_dialog_choose_rgba (_tmp1_, G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, gtk_window_get_type (), GtkWindow), &_tmp3_, NULL, ___lambda14__gasync_ready_callback, block9_data_ref (_data9_));
	block9_data_unref (_data9_);
	_data9_ = NULL;
}

static void
__utils_view___lambda13__gtk_button_clicked (GtkButton* _sender,
                                             gpointer self)
{
	_utils_view___lambda13_ (self);
}

static GObject *
utils_view_constructor (GType type,
                        guint n_construct_properties,
                        GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	UtilsView * self;
	Block8Data* _data8_;
	GtkLabel* tooltip_markup_label = NULL;
	GtkLabel* _tmp0_;
	GtkLabel* _tmp1_;
	GtkButton* tooltip_button_one = NULL;
	GtkButton* _tmp2_;
	GtkButton* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar** _tmp6_;
	gchar** _tmp7_;
	gint _tmp7__length1;
	gchar* _tmp8_;
	gchar* _tmp9_;
	GtkButton* tooltip_button_two = NULL;
	GtkButton* _tmp10_;
	GtkButton* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	gchar** _tmp16_;
	gchar** _tmp17_;
	gint _tmp17__length1;
	gchar* _tmp18_;
	gchar* _tmp19_;
	GtkLabel* contrasting_foreground_color_label = NULL;
	GtkLabel* _tmp20_ = NULL;
	GtkButton* contrast_demo_button = NULL;
	GtkButton* _tmp21_;
	GtkButton* _tmp22_;
	GtkAlign _tmp23_ = 0;
	GtkGrid* grid = NULL;
	GtkGrid* _tmp24_ = NULL;
	GtkGrid* _tmp25_;
	GtkLabel* _tmp26_;
	GtkGrid* _tmp27_;
	GtkButton* _tmp28_;
	GtkGrid* _tmp29_;
	GtkButton* _tmp30_;
	GtkGrid* _tmp31_;
	GtkLabel* _tmp32_;
	GtkGrid* _tmp33_;
	GtkButton* _tmp34_;
	GtkGrid* _tmp35_;
	GdkRGBA _tmp36_;
	GtkButton* _tmp37_;
	parent_class = G_OBJECT_CLASS (utils_view_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_UTILS_VIEW, UtilsView);
	_data8_ = g_slice_new0 (Block8Data);
	_data8_->_ref_count_ = 1;
	_data8_->self = g_object_ref (self);
	_tmp0_ = (GtkLabel*) gtk_label_new ("Markup Accel Tooltips:");
	g_object_ref_sink (_tmp0_);
	tooltip_markup_label = _tmp0_;
	_tmp1_ = tooltip_markup_label;
	gtk_widget_set_halign ((GtkWidget*) _tmp1_, GTK_ALIGN_END);
	_tmp2_ = (GtkButton*) gtk_button_new_from_icon_name ("mail-reply-all");
	g_object_ref_sink (_tmp2_);
	tooltip_button_one = _tmp2_;
	_tmp3_ = tooltip_button_one;
	_tmp4_ = g_strdup ("<Ctrl><Shift>R");
	_tmp5_ = g_strdup ("R");
	_tmp6_ = g_new0 (gchar*, 2 + 1);
	_tmp6_[0] = _tmp4_;
	_tmp6_[1] = _tmp5_;
	_tmp7_ = _tmp6_;
	_tmp7__length1 = 2;
	_tmp8_ = granite_markup_accel_tooltip (_tmp7_, (gint) 2, "Reply All");
	_tmp9_ = _tmp8_;
	gtk_widget_set_tooltip_markup ((GtkWidget*) _tmp3_, _tmp9_);
	_g_free0 (_tmp9_);
	_tmp7_ = (_vala_array_free (_tmp7_, _tmp7__length1, (GDestroyNotify) g_free), NULL);
	_tmp10_ = (GtkButton*) gtk_button_new_with_label ("Label Buttons");
	g_object_ref_sink (_tmp10_);
	tooltip_button_two = _tmp10_;
	_tmp11_ = tooltip_button_two;
	_tmp12_ = g_strdup ("<Super>R");
	_tmp13_ = g_strdup ("<Ctrl><Shift>Up");
	_tmp14_ = g_strdup ("<Ctrl>Return");
	_tmp15_ = g_strdup ("<Super>");
	_tmp16_ = g_new0 (gchar*, 4 + 1);
	_tmp16_[0] = _tmp12_;
	_tmp16_[1] = _tmp13_;
	_tmp16_[2] = _tmp14_;
	_tmp16_[3] = _tmp15_;
	_tmp17_ = _tmp16_;
	_tmp17__length1 = 4;
	_tmp18_ = granite_markup_accel_tooltip (_tmp17_, (gint) 4, NULL);
	_tmp19_ = _tmp18_;
	gtk_widget_set_tooltip_markup ((GtkWidget*) _tmp11_, _tmp19_);
	_g_free0 (_tmp19_);
	_tmp17_ = (_vala_array_free (_tmp17_, _tmp17__length1, (GDestroyNotify) g_free), NULL);
	_tmp20_ = (GtkLabel*) gtk_label_new ("Contrasting Foreground Color:");
	gtk_widget_set_halign ((GtkWidget*) _tmp20_, GTK_ALIGN_END);
	g_object_ref_sink (_tmp20_);
	contrasting_foreground_color_label = _tmp20_;
	_tmp21_ = (GtkButton*) gtk_button_new_with_label ("Contrast Demo");
	g_object_ref_sink (_tmp21_);
	contrast_demo_button = _tmp21_;
	_tmp22_ = contrast_demo_button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp22_, "contrast-demo");
	_tmp23_ = GTK_ALIGN_CENTER;
	_tmp24_ = (GtkGrid*) gtk_grid_new ();
	gtk_widget_set_valign ((GtkWidget*) _tmp24_, _tmp23_);
	gtk_widget_set_halign ((GtkWidget*) _tmp24_, _tmp23_);
	gtk_grid_set_column_spacing (_tmp24_, 12);
	gtk_grid_set_row_spacing (_tmp24_, 12);
	g_object_ref_sink (_tmp24_);
	grid = _tmp24_;
	_tmp25_ = grid;
	_tmp26_ = tooltip_markup_label;
	gtk_grid_attach (_tmp25_, (GtkWidget*) _tmp26_, 0, 0, 1, 1);
	_tmp27_ = grid;
	_tmp28_ = tooltip_button_one;
	gtk_grid_attach (_tmp27_, (GtkWidget*) _tmp28_, 1, 0, 1, 1);
	_tmp29_ = grid;
	_tmp30_ = tooltip_button_two;
	gtk_grid_attach (_tmp29_, (GtkWidget*) _tmp30_, 2, 0, 1, 1);
	_tmp31_ = grid;
	_tmp32_ = contrasting_foreground_color_label;
	gtk_grid_attach (_tmp31_, (GtkWidget*) _tmp32_, 0, 1, 1, 1);
	_tmp33_ = grid;
	_tmp34_ = contrast_demo_button;
	gtk_grid_attach (_tmp33_, (GtkWidget*) _tmp34_, 1, 1, 2, 1);
	_tmp35_ = grid;
	demo_page_set_child ((DemoPage*) self, (GtkWidget*) _tmp35_);
	memset (&_data8_->gdk_demo_bg, 0, sizeof (GdkRGBA));
	gdk_rgba_parse (&_data8_->gdk_demo_bg, UTILS_VIEW_DARK_BG);
	_tmp36_ = _data8_->gdk_demo_bg;
	utils_view_style_contrast_demo (self, &_tmp36_);
	_tmp37_ = contrast_demo_button;
	g_signal_connect_data (_tmp37_, "clicked", (GCallback) __utils_view___lambda13__gtk_button_clicked, block8_data_ref (_data8_), (GClosureNotify) block8_data_unref, 0);
	_g_object_unref0 (grid);
	_g_object_unref0 (contrast_demo_button);
	_g_object_unref0 (contrasting_foreground_color_label);
	_g_object_unref0 (tooltip_button_two);
	_g_object_unref0 (tooltip_button_one);
	_g_object_unref0 (tooltip_markup_label);
	block8_data_unref (_data8_);
	_data8_ = NULL;
	return obj;
}

static void
utils_view_class_init (UtilsViewClass * klass,
                       gpointer klass_data)
{
	utils_view_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->constructor = utils_view_constructor;
}

static void
utils_view_instance_init (UtilsView * self,
                          gpointer klass)
{
}

static GType
utils_view_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (UtilsViewClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) utils_view_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UtilsView), 0, (GInstanceInitFunc) utils_view_instance_init, NULL };
	GType utils_view_type_id;
	utils_view_type_id = g_type_register_static (TYPE_DEMO_PAGE, "UtilsView", &g_define_type_info, 0);
	return utils_view_type_id;
}

GType
utils_view_get_type (void)
{
	static volatile gsize utils_view_type_id__once = 0;
	if (g_once_init_enter (&utils_view_type_id__once)) {
		GType utils_view_type_id;
		utils_view_type_id = utils_view_get_type_once ();
		g_once_init_leave (&utils_view_type_id__once, utils_view_type_id);
	}
	return utils_view_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

