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

/*
 * Copyright 2025 elementary, Inc. (https://elementary.io)
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

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

enum  {
	GRANITE_BACK_BUTTON_0_PROPERTY,
	GRANITE_BACK_BUTTON_LABEL_PROPERTY,
	GRANITE_BACK_BUTTON_NUM_PROPERTIES
};
static GParamSpec* granite_back_button_properties[GRANITE_BACK_BUTTON_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)))

struct _GraniteBackButtonPrivate {
	gchar* _label;
};

static gint GraniteBackButton_private_offset;
static gpointer granite_back_button_parent_class = NULL;

static GObject * granite_back_button_constructor (GType type,
                                           guint n_construct_properties,
                                           GObjectConstructParam * construct_properties);
static void granite_back_button_finalize (GObject * obj);
static GType granite_back_button_get_type_once (void);
static void _vala_granite_back_button_get_property (GObject * object,
                                             guint property_id,
                                             GValue * value,
                                             GParamSpec * pspec);
static void _vala_granite_back_button_set_property (GObject * object,
                                             guint property_id,
                                             const GValue * value,
                                             GParamSpec * pspec);
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 inline gpointer
granite_back_button_get_instance_private (GraniteBackButton* self)
{
	return G_STRUCT_MEMBER_P (self, GraniteBackButton_private_offset);
}

const gchar*
granite_back_button_get_label (GraniteBackButton* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_label;
	result = _tmp0_;
	return result;
}

void
granite_back_button_set_label (GraniteBackButton* self,
                               const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = granite_back_button_get_label (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_label);
		self->priv->_label = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, granite_back_button_properties[GRANITE_BACK_BUTTON_LABEL_PROPERTY]);
	}
}

GraniteBackButton*
granite_back_button_construct (GType object_type,
                               const gchar* label)
{
	GraniteBackButton * self = NULL;
	g_return_val_if_fail (label != NULL, NULL);
	self = (GraniteBackButton*) g_object_new (object_type, "label", label, NULL);
	return self;
}

GraniteBackButton*
granite_back_button_new (const gchar* label)
{
	return granite_back_button_construct (GRANITE_TYPE_BACK_BUTTON, label);
}

static GObject *
granite_back_button_constructor (GType type,
                                 guint n_construct_properties,
                                 GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GraniteBackButton * self;
	GtkImage* image = NULL;
	GtkImage* _tmp0_;
	GtkLabel* label_widget = NULL;
	GtkLabel* _tmp1_;
	GtkBox* box = NULL;
	GtkBox* _tmp2_;
	GtkBox* _tmp3_;
	GtkImage* _tmp4_;
	GtkBox* _tmp5_;
	GtkLabel* _tmp6_;
	GtkBox* _tmp7_;
	gchar* _tmp8_;
	gchar** _tmp9_;
	gchar** _tmp10_;
	gint _tmp10__length1;
	gchar* _tmp11_;
	gchar* _tmp12_;
	GtkLabel* _tmp13_;
	parent_class = G_OBJECT_CLASS (granite_back_button_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GRANITE_TYPE_BACK_BUTTON, GraniteBackButton);
	_tmp0_ = (GtkImage*) gtk_image_new_from_icon_name ("go-previous-symbolic");
	g_object_ref_sink (_tmp0_);
	image = _tmp0_;
	_tmp1_ = (GtkLabel*) gtk_label_new ("");
	g_object_ref_sink (_tmp1_);
	label_widget = _tmp1_;
	_tmp2_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
	g_object_ref_sink (_tmp2_);
	box = _tmp2_;
	_tmp3_ = box;
	_tmp4_ = image;
	gtk_box_append (_tmp3_, (GtkWidget*) _tmp4_);
	_tmp5_ = box;
	_tmp6_ = label_widget;
	gtk_box_append (_tmp5_, (GtkWidget*) _tmp6_);
	gtk_actionable_set_action_name ((GtkActionable*) self, "navigation.pop");
	_tmp7_ = box;
	gtk_button_set_child ((GtkButton*) self, (GtkWidget*) _tmp7_);
	_tmp8_ = g_strdup ("<alt>Left");
	_tmp9_ = g_new0 (gchar*, 1 + 1);
	_tmp9_[0] = _tmp8_;
	_tmp10_ = _tmp9_;
	_tmp10__length1 = 1;
	_tmp11_ = granite_markup_accel_tooltip (_tmp10_, (gint) 1, NULL);
	_tmp12_ = _tmp11_;
	gtk_widget_set_tooltip_markup ((GtkWidget*) self, _tmp12_);
	_g_free0 (_tmp12_);
	_tmp10_ = (_vala_array_free (_tmp10_, _tmp10__length1, (GDestroyNotify) g_free), NULL);
	gtk_widget_add_css_class ((GtkWidget*) self, "text-button");
	_tmp13_ = label_widget;
	g_object_bind_property_with_closures ((GObject*) self, "label", (GObject*) _tmp13_, "label", G_BINDING_DEFAULT, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_g_object_unref0 (box);
	_g_object_unref0 (label_widget);
	_g_object_unref0 (image);
	return obj;
}

static void
granite_back_button_class_init (GraniteBackButtonClass * klass,
                                gpointer klass_data)
{
	granite_back_button_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GraniteBackButton_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_granite_back_button_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_granite_back_button_set_property;
	G_OBJECT_CLASS (klass)->constructor = granite_back_button_constructor;
	G_OBJECT_CLASS (klass)->finalize = granite_back_button_finalize;
	/**
	     * Text of the label inside of #this
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRANITE_BACK_BUTTON_LABEL_PROPERTY, granite_back_button_properties[GRANITE_BACK_BUTTON_LABEL_PROPERTY] = g_param_spec_string ("label", "label", "label", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
granite_back_button_instance_init (GraniteBackButton * self,
                                   gpointer klass)
{
	self->priv = granite_back_button_get_instance_private (self);
}

static void
granite_back_button_finalize (GObject * obj)
{
	GraniteBackButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GRANITE_TYPE_BACK_BUTTON, GraniteBackButton);
	_g_free0 (self->priv->_label);
	G_OBJECT_CLASS (granite_back_button_parent_class)->finalize (obj);
}

/**
 * BackButton is meant to be used in headers to navigate in
 * {@link Adw.NavigationView}.
 *
 * By default `action_name` is set to `navigation.pop`
 */
static GType
granite_back_button_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GraniteBackButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) granite_back_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GraniteBackButton), 0, (GInstanceInitFunc) granite_back_button_instance_init, NULL };
	GType granite_back_button_type_id;
	granite_back_button_type_id = g_type_register_static (gtk_button_get_type (), "GraniteBackButton", &g_define_type_info, 0);
	GraniteBackButton_private_offset = g_type_add_instance_private (granite_back_button_type_id, sizeof (GraniteBackButtonPrivate));
	return granite_back_button_type_id;
}

GType
granite_back_button_get_type (void)
{
	static volatile gsize granite_back_button_type_id__once = 0;
	if (g_once_init_enter (&granite_back_button_type_id__once)) {
		GType granite_back_button_type_id;
		granite_back_button_type_id = granite_back_button_get_type_once ();
		g_once_init_leave (&granite_back_button_type_id__once, granite_back_button_type_id);
	}
	return granite_back_button_type_id__once;
}

static void
_vala_granite_back_button_get_property (GObject * object,
                                        guint property_id,
                                        GValue * value,
                                        GParamSpec * pspec)
{
	GraniteBackButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GRANITE_TYPE_BACK_BUTTON, GraniteBackButton);
	switch (property_id) {
		case GRANITE_BACK_BUTTON_LABEL_PROPERTY:
		g_value_set_string (value, granite_back_button_get_label (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_granite_back_button_set_property (GObject * object,
                                        guint property_id,
                                        const GValue * value,
                                        GParamSpec * pspec)
{
	GraniteBackButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GRANITE_TYPE_BACK_BUTTON, GraniteBackButton);
	switch (property_id) {
		case GRANITE_BACK_BUTTON_LABEL_PROPERTY:
		granite_back_button_set_label (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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);
}

