/* gitg-when-mapped.c generated by valac 0.56.19, the Vala compiler
 * generated from gitg-when-mapped.vala, do not modify */

/*
 * This file is part of gitg
 *
 * Copyright (C) 2012 - Jesse van den Kieboom
 *
 * gitg is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * gitg 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gitg. If not, see <http://www.gnu.org/licenses/>.
 */

#include "libgitg.h"
#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib.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

typedef struct _Block49Data Block49Data;
#define _gitg_when_mapped_unref0(var) ((var == NULL) ? NULL : (var = (gitg_when_mapped_unref (var), NULL)))
typedef struct _GitgParamSpecWhenMapped GitgParamSpecWhenMapped;

struct _GitgWhenMappedPrivate {
	GtkWidget* d_widget;
	GObject* d_lifetime;
	gulong d_sid;
};

struct _Block49Data {
	int _ref_count_;
	GitgWhenMapped* self;
	GitgWhenMappedOnMapped mapped;
	gpointer mapped_target;
	GDestroyNotify mapped_target_destroy_notify;
};

struct _GitgParamSpecWhenMapped {
	GParamSpec parent_instance;
};

static gint GitgWhenMapped_private_offset;
static gpointer gitg_when_mapped_parent_class = NULL;

static void gitg_when_mapped_weak_notify (GitgWhenMapped* self,
                                   GObject* o);
static void _gitg_when_mapped_weak_notify_gweak_notify (gpointer self,
                                                 GObject* object);
static void gitg_when_mapped_lifetime_weak_notify (GitgWhenMapped* self,
                                            GObject* o);
static void _gitg_when_mapped_lifetime_weak_notify_gweak_notify (gpointer self,
                                                          GObject* object);
static Block49Data* block49_data_ref (Block49Data* _data49_);
static void block49_data_unref (void * _userdata_);
static void ___lambda98_ (Block49Data* _data49_);
static void ____lambda98__gtk_widget_map (GtkWidget* _sender,
                                   gpointer self);
static void gitg_when_mapped_finalize (GitgWhenMapped * obj);
static GType gitg_when_mapped_get_type_once (void);

static inline gpointer
gitg_when_mapped_get_instance_private (GitgWhenMapped* self)
{
	return G_STRUCT_MEMBER_P (self, GitgWhenMapped_private_offset);
}

static void
_gitg_when_mapped_weak_notify_gweak_notify (gpointer self,
                                            GObject* object)
{
	gitg_when_mapped_weak_notify ((GitgWhenMapped*) self, object);
}

static void
_gitg_when_mapped_lifetime_weak_notify_gweak_notify (gpointer self,
                                                     GObject* object)
{
	gitg_when_mapped_lifetime_weak_notify ((GitgWhenMapped*) self, object);
}

GitgWhenMapped*
gitg_when_mapped_construct (GType object_type,
                            GtkWidget* widget)
{
	GitgWhenMapped* self = NULL;
	GtkWidget* _tmp0_;
	g_return_val_if_fail (widget != NULL, NULL);
	self = (GitgWhenMapped*) g_type_create_instance (object_type);
	self->priv->d_sid = (gulong) 0;
	self->priv->d_widget = widget;
	_tmp0_ = self->priv->d_widget;
	g_object_weak_ref ((GObject*) _tmp0_, _gitg_when_mapped_weak_notify_gweak_notify, self);
	return self;
}

GitgWhenMapped*
gitg_when_mapped_new (GtkWidget* widget)
{
	return gitg_when_mapped_construct (GITG_TYPE_WHEN_MAPPED, widget);
}

static void
gitg_when_mapped_weak_notify (GitgWhenMapped* self,
                              GObject* o)
{
	GObject* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (o != NULL);
	self->priv->d_widget = NULL;
	self->priv->d_sid = (gulong) 0;
	_tmp0_ = self->priv->d_lifetime;
	if (_tmp0_ != NULL) {
		GObject* _tmp1_;
		_tmp1_ = self->priv->d_lifetime;
		g_object_weak_unref (_tmp1_, _gitg_when_mapped_lifetime_weak_notify_gweak_notify, self);
		self->priv->d_lifetime = NULL;
	}
}

static void
gitg_when_mapped_lifetime_weak_notify (GitgWhenMapped* self,
                                       GObject* o)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (o != NULL);
	if (self->priv->d_sid != ((gulong) 0)) {
		GtkWidget* _tmp1_;
		_tmp1_ = self->priv->d_widget;
		_tmp0_ = _tmp1_ != NULL;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		GtkWidget* _tmp2_;
		_tmp2_ = self->priv->d_widget;
		g_signal_handler_disconnect ((GObject*) _tmp2_, self->priv->d_sid);
		self->priv->d_sid = (gulong) 0;
	}
	self->priv->d_lifetime = NULL;
}

static Block49Data*
block49_data_ref (Block49Data* _data49_)
{
	g_atomic_int_inc (&_data49_->_ref_count_);
	return _data49_;
}

static void
block49_data_unref (void * _userdata_)
{
	Block49Data* _data49_;
	_data49_ = (Block49Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data49_->_ref_count_)) {
		GitgWhenMapped* self;
		self = _data49_->self;
		(_data49_->mapped_target_destroy_notify == NULL) ? NULL : (_data49_->mapped_target_destroy_notify (_data49_->mapped_target), NULL);
		_data49_->mapped = NULL;
		_data49_->mapped_target = NULL;
		_data49_->mapped_target_destroy_notify = NULL;
		_gitg_when_mapped_unref0 (self);
		g_slice_free (Block49Data, _data49_);
	}
}

static void
___lambda98_ (Block49Data* _data49_)
{
	GitgWhenMapped* self;
	GtkWidget* _tmp0_;
	GObject* _tmp1_;
	self = _data49_->self;
	_tmp0_ = self->priv->d_widget;
	g_signal_handler_disconnect ((GObject*) _tmp0_, self->priv->d_sid);
	self->priv->d_sid = (gulong) 0;
	_tmp1_ = self->priv->d_lifetime;
	if (_tmp1_ != NULL) {
		GObject* _tmp2_;
		_tmp2_ = self->priv->d_lifetime;
		g_object_weak_unref (_tmp2_, _gitg_when_mapped_lifetime_weak_notify_gweak_notify, self);
		self->priv->d_lifetime = NULL;
	}
	_data49_->mapped (_data49_->mapped_target);
}

static void
____lambda98__gtk_widget_map (GtkWidget* _sender,
                              gpointer self)
{
	___lambda98_ (self);
}

void
gitg_when_mapped_update (GitgWhenMapped* self,
                         GitgWhenMappedOnMapped mapped,
                         gpointer mapped_target,
                         GDestroyNotify mapped_target_destroy_notify,
                         GObject* lifetime)
{
	Block49Data* _data49_;
	GtkWidget* _tmp0_;
	GObject* _tmp2_;
	GtkWidget* _tmp4_;
	g_return_if_fail (self != NULL);
	_data49_ = g_slice_new0 (Block49Data);
	_data49_->_ref_count_ = 1;
	_data49_->self = gitg_when_mapped_ref (self);
	(_data49_->mapped_target_destroy_notify == NULL) ? NULL : (_data49_->mapped_target_destroy_notify (_data49_->mapped_target), NULL);
	_data49_->mapped = NULL;
	_data49_->mapped_target = NULL;
	_data49_->mapped_target_destroy_notify = NULL;
	_data49_->mapped = mapped;
	_data49_->mapped_target = mapped_target;
	_data49_->mapped_target_destroy_notify = mapped_target_destroy_notify;
	_tmp0_ = self->priv->d_widget;
	if (_tmp0_ == NULL) {
		block49_data_unref (_data49_);
		_data49_ = NULL;
		return;
	}
	if (self->priv->d_sid != ((gulong) 0)) {
		GtkWidget* _tmp1_;
		_tmp1_ = self->priv->d_widget;
		g_signal_handler_disconnect ((GObject*) _tmp1_, self->priv->d_sid);
		self->priv->d_sid = (gulong) 0;
	}
	_tmp2_ = self->priv->d_lifetime;
	if (_tmp2_ != NULL) {
		GObject* _tmp3_;
		_tmp3_ = self->priv->d_lifetime;
		g_object_weak_unref (_tmp3_, _gitg_when_mapped_lifetime_weak_notify_gweak_notify, self);
		self->priv->d_lifetime = NULL;
	}
	_tmp4_ = self->priv->d_widget;
	if (gtk_widget_get_mapped (_tmp4_)) {
		_data49_->mapped (_data49_->mapped_target);
	} else {
		GtkWidget* _tmp5_;
		gulong _tmp6_;
		GObject* _tmp7_;
		_tmp5_ = self->priv->d_widget;
		_tmp6_ = g_signal_connect_data (_tmp5_, "map", (GCallback) ____lambda98__gtk_widget_map, block49_data_ref (_data49_), (GClosureNotify) block49_data_unref, 0);
		self->priv->d_sid = _tmp6_;
		self->priv->d_lifetime = lifetime;
		_tmp7_ = self->priv->d_lifetime;
		if (_tmp7_ != NULL) {
			GObject* _tmp8_;
			_tmp8_ = self->priv->d_lifetime;
			g_object_weak_ref (_tmp8_, _gitg_when_mapped_lifetime_weak_notify_gweak_notify, self);
		}
	}
	block49_data_unref (_data49_);
	_data49_ = NULL;
}

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

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

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

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

static gchar*
gitg_value_when_mapped_collect_value (GValue* value,
                                      guint n_collect_values,
                                      GTypeCValue* collect_values,
                                      guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		GitgWhenMapped * 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 = gitg_when_mapped_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
gitg_value_when_mapped_lcopy_value (const GValue* value,
                                    guint n_collect_values,
                                    GTypeCValue* collect_values,
                                    guint collect_flags)
{
	GitgWhenMapped ** 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 = gitg_when_mapped_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
gitg_param_spec_when_mapped (const gchar* name,
                             const gchar* nick,
                             const gchar* blurb,
                             GType object_type,
                             GParamFlags flags)
{
	GitgParamSpecWhenMapped* spec;
	g_return_val_if_fail (g_type_is_a (object_type, GITG_TYPE_WHEN_MAPPED), 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
gitg_value_get_when_mapped (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GITG_TYPE_WHEN_MAPPED), NULL);
	return value->data[0].v_pointer;
}

void
gitg_value_set_when_mapped (GValue* value,
                            gpointer v_object)
{
	GitgWhenMapped * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GITG_TYPE_WHEN_MAPPED));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GITG_TYPE_WHEN_MAPPED));
		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;
		gitg_when_mapped_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		gitg_when_mapped_unref (old);
	}
}

void
gitg_value_take_when_mapped (GValue* value,
                             gpointer v_object)
{
	GitgWhenMapped * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GITG_TYPE_WHEN_MAPPED));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GITG_TYPE_WHEN_MAPPED));
		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) {
		gitg_when_mapped_unref (old);
	}
}

static void
gitg_when_mapped_class_init (GitgWhenMappedClass * klass,
                             gpointer klass_data)
{
	gitg_when_mapped_parent_class = g_type_class_peek_parent (klass);
	((GitgWhenMappedClass *) klass)->finalize = gitg_when_mapped_finalize;
	g_type_class_adjust_private_offset (klass, &GitgWhenMapped_private_offset);
}

static void
gitg_when_mapped_instance_init (GitgWhenMapped * self,
                                gpointer klass)
{
	self->priv = gitg_when_mapped_get_instance_private (self);
	self->ref_count = 1;
}

static void
gitg_when_mapped_finalize (GitgWhenMapped * obj)
{
	GitgWhenMapped * self;
	GtkWidget* _tmp0_;
	GObject* _tmp5_;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GITG_TYPE_WHEN_MAPPED, GitgWhenMapped);
	g_signal_handlers_destroy (self);
	_tmp0_ = self->priv->d_widget;
	if (_tmp0_ != NULL) {
		gboolean _tmp1_ = FALSE;
		GtkWidget* _tmp4_;
		if (self->priv->d_sid != ((gulong) 0)) {
			GtkWidget* _tmp2_;
			_tmp2_ = self->priv->d_widget;
			_tmp1_ = g_signal_handler_is_connected (_tmp2_, self->priv->d_sid);
		} else {
			_tmp1_ = FALSE;
		}
		if (_tmp1_) {
			GtkWidget* _tmp3_;
			_tmp3_ = self->priv->d_widget;
			g_signal_handler_disconnect ((GObject*) _tmp3_, self->priv->d_sid);
		}
		_tmp4_ = self->priv->d_widget;
		g_object_weak_unref ((GObject*) _tmp4_, _gitg_when_mapped_weak_notify_gweak_notify, self);
		self->priv->d_widget = NULL;
	}
	_tmp5_ = self->priv->d_lifetime;
	if (_tmp5_ != NULL) {
		GObject* _tmp6_;
		_tmp6_ = self->priv->d_lifetime;
		g_object_weak_unref (_tmp6_, _gitg_when_mapped_lifetime_weak_notify_gweak_notify, self);
		self->priv->d_lifetime = NULL;
	}
}

 G_GNUC_NO_INLINE static GType
gitg_when_mapped_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { gitg_value_when_mapped_init, gitg_value_when_mapped_free_value, gitg_value_when_mapped_copy_value, gitg_value_when_mapped_peek_pointer, "p", gitg_value_when_mapped_collect_value, "p", gitg_value_when_mapped_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (GitgWhenMappedClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gitg_when_mapped_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GitgWhenMapped), 0, (GInstanceInitFunc) gitg_when_mapped_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 gitg_when_mapped_type_id;
	gitg_when_mapped_type_id = g_type_register_fundamental (g_type_fundamental_next (), "GitgWhenMapped", &g_define_type_info, &g_define_type_fundamental_info, 0);
	GitgWhenMapped_private_offset = g_type_add_instance_private (gitg_when_mapped_type_id, sizeof (GitgWhenMappedPrivate));
	return gitg_when_mapped_type_id;
}

GType
gitg_when_mapped_get_type (void)
{
	static gsize gitg_when_mapped_type_id__once = 0;
	if (g_once_init_enter (&gitg_when_mapped_type_id__once)) {
		GType gitg_when_mapped_type_id;
		gitg_when_mapped_type_id = gitg_when_mapped_get_type_once ();
		g_once_init_leave (&gitg_when_mapped_type_id__once, gitg_when_mapped_type_id);
	}
	return gitg_when_mapped_type_id__once;
}

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

void
gitg_when_mapped_unref (gpointer instance)
{
	GitgWhenMapped * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		GITG_WHEN_MAPPED_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

