/* gtk-helper.c generated by valac 0.56.17, the Vala compiler
 * generated from gtk-helper.vala, do not modify */

/*
Peek Copyright (c) 2017 by Philipp Wolfer <ph.wolfer@gmail.com>

This file is part of Peek.

This software is licensed under the GNU General Public License
(version 3 or later). See the LICENSE file in this distribution.
*/

#include "../../application.h"
#include <gtk/gtk.h>
#include <glib.h>
#include <glib-object.h>
#include <cairo-gobject.h>
#include <string.h>
#include <gobject/gvaluecollector.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

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _PeekParamSpecGtkHelper PeekParamSpecGtkHelper;

struct _PeekParamSpecGtkHelper {
	GParamSpec parent_instance;
};

static gpointer peek_gtk_helper_parent_class = NULL;

static void peek_gtk_helper_finalize (PeekGtkHelper * obj);
static GType peek_gtk_helper_get_type_once (void);

void
peek_gtk_helper_hide_button_label (GtkButton* button)
{
	GtkWidget* label = NULL;
	GtkWidget* _tmp0_;
	g_return_if_fail (button != NULL);
	_tmp0_ = peek_gtk_helper_find_first_child_of_type ((GtkContainer*) button, gtk_label_get_type ());
	label = _tmp0_;
	gtk_widget_hide (label);
	_g_object_unref0 (label);
}

void
peek_gtk_helper_show_button_label (GtkButton* button)
{
	GtkWidget* label = NULL;
	GtkWidget* _tmp0_;
	g_return_if_fail (button != NULL);
	_tmp0_ = peek_gtk_helper_find_first_child_of_type ((GtkContainer*) button, gtk_label_get_type ());
	label = _tmp0_;
	gtk_widget_show (label);
	_g_object_unref0 (label);
}

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

GtkWidget*
peek_gtk_helper_find_first_child_of_type (GtkContainer* container,
                                          GType type)
{
	GList* children = NULL;
	GList* _tmp0_;
	GList* _tmp1_;
	GtkWidget* result;
	g_return_val_if_fail (container != NULL, NULL);
	_tmp0_ = gtk_container_get_children (container);
	children = _tmp0_;
	_tmp1_ = children;
	{
		GList* child_collection = NULL;
		GList* child_it = NULL;
		child_collection = _tmp1_;
		for (child_it = child_collection; child_it != NULL; child_it = child_it->next) {
			GtkWidget* child = NULL;
			child = (GtkWidget*) child_it->data;
			{
				GType child_type = 0UL;
				GtkWidget* _tmp2_;
				_tmp2_ = child;
				child_type = G_TYPE_FROM_INSTANCE ((GObject*) _tmp2_);
				if (g_type_is_a (child_type, type)) {
					GtkWidget* _tmp3_;
					GtkWidget* _tmp4_;
					_tmp3_ = child;
					_tmp4_ = _g_object_ref0 (_tmp3_);
					result = _tmp4_;
					(children == NULL) ? NULL : (children = (g_list_free (children), NULL));
					return result;
				} else {
					if (g_type_is_a (child_type, gtk_container_get_type ())) {
						GtkWidget* _tmp5_;
						GtkWidget* _tmp6_;
						_tmp5_ = child;
						_tmp6_ = peek_gtk_helper_find_first_child_of_type (G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, gtk_container_get_type (), GtkContainer), type);
						result = _tmp6_;
						(children == NULL) ? NULL : (children = (g_list_free (children), NULL));
						return result;
					}
				}
			}
		}
	}
	result = NULL;
	(children == NULL) ? NULL : (children = (g_list_free (children), NULL));
	return result;
}

cairo_region_t*
peek_gtk_helper_create_region_from_widget (GtkWidget* widget)
{
	cairo_rectangle_int_t rectangle = {0};
	cairo_rectangle_int_t _tmp0_ = {0};
	GtkWidget* _tmp1_;
	gint _tmp2_ = 0;
	gint _tmp3_ = 0;
	cairo_region_t* region = NULL;
	cairo_rectangle_int_t _tmp4_;
	cairo_region_t* _tmp5_;
	cairo_region_t* result;
	g_return_val_if_fail (widget != NULL, NULL);
	memset (&_tmp0_, 0, sizeof (cairo_rectangle_int_t));
	_tmp0_.width = gtk_widget_get_allocated_width (widget);
	_tmp0_.height = gtk_widget_get_allocated_height (widget);
	rectangle = _tmp0_;
	_tmp1_ = gtk_widget_get_toplevel (widget);
	gtk_widget_translate_coordinates (widget, _tmp1_, 0, 0, &_tmp2_, &_tmp3_);
	rectangle.x = _tmp2_;
	rectangle.y = _tmp3_;
	_tmp4_ = rectangle;
	_tmp5_ = cairo_region_create_rectangle (&_tmp4_);
	region = _tmp5_;
	result = region;
	return result;
}

PeekGtkHelper*
peek_gtk_helper_construct (GType object_type)
{
	PeekGtkHelper* self = NULL;
	self = (PeekGtkHelper*) g_type_create_instance (object_type);
	return self;
}

PeekGtkHelper*
peek_gtk_helper_new (void)
{
	return peek_gtk_helper_construct (PEEK_TYPE_GTK_HELPER);
}

static void
peek_value_gtk_helper_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
peek_value_gtk_helper_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		peek_gtk_helper_unref (value->data[0].v_pointer);
	}
}

static void
peek_value_gtk_helper_copy_value (const GValue* src_value,
                                  GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = peek_gtk_helper_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
peek_value_gtk_helper_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
peek_value_gtk_helper_collect_value (GValue* value,
                                     guint n_collect_values,
                                     GTypeCValue* collect_values,
                                     guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		PeekGtkHelper * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = peek_gtk_helper_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
peek_value_gtk_helper_lcopy_value (const GValue* value,
                                   guint n_collect_values,
                                   GTypeCValue* collect_values,
                                   guint collect_flags)
{
	PeekGtkHelper ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = peek_gtk_helper_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
peek_param_spec_gtk_helper (const gchar* name,
                            const gchar* nick,
                            const gchar* blurb,
                            GType object_type,
                            GParamFlags flags)
{
	PeekParamSpecGtkHelper* spec;
	g_return_val_if_fail (g_type_is_a (object_type, PEEK_TYPE_GTK_HELPER), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
peek_value_get_gtk_helper (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, PEEK_TYPE_GTK_HELPER), NULL);
	return value->data[0].v_pointer;
}

void
peek_value_set_gtk_helper (GValue* value,
                           gpointer v_object)
{
	PeekGtkHelper * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, PEEK_TYPE_GTK_HELPER));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, PEEK_TYPE_GTK_HELPER));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		peek_gtk_helper_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		peek_gtk_helper_unref (old);
	}
}

void
peek_value_take_gtk_helper (GValue* value,
                            gpointer v_object)
{
	PeekGtkHelper * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, PEEK_TYPE_GTK_HELPER));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, PEEK_TYPE_GTK_HELPER));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		peek_gtk_helper_unref (old);
	}
}

static void
peek_gtk_helper_class_init (PeekGtkHelperClass * klass,
                            gpointer klass_data)
{
	peek_gtk_helper_parent_class = g_type_class_peek_parent (klass);
	((PeekGtkHelperClass *) klass)->finalize = peek_gtk_helper_finalize;
}

static void
peek_gtk_helper_instance_init (PeekGtkHelper * self,
                               gpointer klass)
{
	self->ref_count = 1;
}

static void
peek_gtk_helper_finalize (PeekGtkHelper * obj)
{
	PeekGtkHelper * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PEEK_TYPE_GTK_HELPER, PeekGtkHelper);
	g_signal_handlers_destroy (self);
}

static GType
peek_gtk_helper_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { peek_value_gtk_helper_init, peek_value_gtk_helper_free_value, peek_value_gtk_helper_copy_value, peek_value_gtk_helper_peek_pointer, "p", peek_value_gtk_helper_collect_value, "p", peek_value_gtk_helper_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (PeekGtkHelperClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) peek_gtk_helper_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PeekGtkHelper), 0, (GInstanceInitFunc) peek_gtk_helper_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType peek_gtk_helper_type_id;
	peek_gtk_helper_type_id = g_type_register_fundamental (g_type_fundamental_next (), "PeekGtkHelper", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return peek_gtk_helper_type_id;
}

GType
peek_gtk_helper_get_type (void)
{
	static volatile gsize peek_gtk_helper_type_id__once = 0;
	if (g_once_init_enter (&peek_gtk_helper_type_id__once)) {
		GType peek_gtk_helper_type_id;
		peek_gtk_helper_type_id = peek_gtk_helper_get_type_once ();
		g_once_init_leave (&peek_gtk_helper_type_id__once, peek_gtk_helper_type_id);
	}
	return peek_gtk_helper_type_id__once;
}

gpointer
peek_gtk_helper_ref (gpointer instance)
{
	PeekGtkHelper * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
peek_gtk_helper_unref (gpointer instance)
{
	PeekGtkHelper * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		PEEK_GTK_HELPER_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

