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

/* stack-list.vala
 *
 * Copyright (C) 2023 Markus Göllnitz
 *
 * This program 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 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors: Markus Göllnitz <camelcasenick@bewares.it>
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <gio/gio.h>
#include <string.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
#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 USAGE_TYPE_STACK_LIST (usage_stack_list_get_type ())
#define USAGE_STACK_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), USAGE_TYPE_STACK_LIST, UsageStackList))
#define USAGE_STACK_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), USAGE_TYPE_STACK_LIST, UsageStackListClass))
#define USAGE_IS_STACK_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), USAGE_TYPE_STACK_LIST))
#define USAGE_IS_STACK_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), USAGE_TYPE_STACK_LIST))
#define USAGE_STACK_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), USAGE_TYPE_STACK_LIST, UsageStackListClass))

typedef struct _UsageStackList UsageStackList;
typedef struct _UsageStackListClass UsageStackListClass;
typedef struct _UsageStackListPrivate UsageStackListPrivate;
enum  {
	USAGE_STACK_LIST_0_PROPERTY,
	USAGE_STACK_LIST_SELECTION_MODE_PROPERTY,
	USAGE_STACK_LIST_NUM_PROPERTIES
};
static GParamSpec* usage_stack_list_properties[USAGE_STACK_LIST_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block7Data Block7Data;
enum  {
	USAGE_STACK_LIST_MODEL_CHANGED_SIGNAL,
	USAGE_STACK_LIST_ROW_ACTIVATED_SIGNAL,
	USAGE_STACK_LIST_NUM_SIGNALS
};
static guint usage_stack_list_signals[USAGE_STACK_LIST_NUM_SIGNALS] = {0};

struct _UsageStackList {
	GtkBox parent_instance;
	UsageStackListPrivate * priv;
};

struct _UsageStackListClass {
	GtkBoxClass parent_class;
};

struct _UsageStackListPrivate {
	GtkListBox* list_box;
	GQueue* models;
	gint depth;
};

struct _Block7Data {
	int _ref_count_;
	UsageStackList* self;
	GtkListBoxCreateWidgetFunc row_function;
	gpointer row_function_target;
};

static gint UsageStackList_private_offset;
static gpointer usage_stack_list_parent_class = NULL;

VALA_EXTERN GType usage_stack_list_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UsageStackList, g_object_unref)
static void _g_object_unref0_ (gpointer var);
static inline void _g_queue_free__g_object_unref0_ (GQueue* self);
VALA_EXTERN void usage_stack_list_init (UsageStackList* self,
                            GtkListBoxCreateWidgetFunc row_function,
                            gpointer row_function_target);
static Block7Data* block7_data_ref (Block7Data* _data7_);
static void block7_data_unref (void * _userdata_);
static void __lambda34_ (UsageStackList* self,
                  GtkListBox* box,
                  GtkListBoxRow* row);
static void ___lambda34__gtk_list_box_row_activated (GtkListBox* _sender,
                                              GtkListBoxRow* row,
                                              gpointer self);
static void __lambda35_ (Block7Data* _data7_,
                  GListStore* model);
static GtkWidget* __lambda36_ (Block7Data* _data7_,
                        GObject* item);
static GtkWidget* ___lambda36__gtk_list_box_create_widget_func (GObject* item,
                                                         gpointer self);
static void ___lambda35__usage_stack_list_model_changed (UsageStackList* _sender,
                                                  GListStore* model,
                                                  gpointer self);
VALA_EXTERN GListStore* usage_stack_list_get_model (UsageStackList* self);
VALA_EXTERN gint usage_stack_list_get_depth (UsageStackList* self);
VALA_EXTERN void usage_stack_list_push_layer (UsageStackList* self,
                                  GListStore* model);
VALA_EXTERN gboolean usage_stack_list_layer_up (UsageStackList* self);
VALA_EXTERN UsageStackList* usage_stack_list_new (void);
VALA_EXTERN UsageStackList* usage_stack_list_construct (GType object_type);
VALA_EXTERN GtkSelectionMode usage_stack_list_get_selection_mode (UsageStackList* self);
VALA_EXTERN void usage_stack_list_set_selection_mode (UsageStackList* self,
                                          GtkSelectionMode value);
static void usage_stack_list_finalize (GObject * obj);
static GType usage_stack_list_get_type_once (void);
static void _vala_usage_stack_list_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec);
static void _vala_usage_stack_list_set_property (GObject * object,
                                          guint property_id,
                                          const GValue * value,
                                          GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
usage_stack_list_get_instance_private (UsageStackList* self)
{
	return G_STRUCT_MEMBER_P (self, UsageStackList_private_offset);
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

static inline void
_g_queue_free__g_object_unref0_ (GQueue* self)
{
	g_queue_free_full (self, (GDestroyNotify) _g_object_unref0_);
}

static Block7Data*
block7_data_ref (Block7Data* _data7_)
{
	g_atomic_int_inc (&_data7_->_ref_count_);
	return _data7_;
}

static void
block7_data_unref (void * _userdata_)
{
	Block7Data* _data7_;
	_data7_ = (Block7Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data7_->_ref_count_)) {
		UsageStackList* self;
		self = _data7_->self;
		_g_object_unref0 (self);
		g_slice_free (Block7Data, _data7_);
	}
}

static void
__lambda34_ (UsageStackList* self,
             GtkListBox* box,
             GtkListBoxRow* row)
{
	g_return_if_fail (box != NULL);
	g_return_if_fail (row != NULL);
	g_signal_emit (self, usage_stack_list_signals[USAGE_STACK_LIST_ROW_ACTIVATED_SIGNAL], 0, row);
}

static void
___lambda34__gtk_list_box_row_activated (GtkListBox* _sender,
                                         GtkListBoxRow* row,
                                         gpointer self)
{
	__lambda34_ ((UsageStackList*) self, _sender, row);
}

static GtkWidget*
__lambda36_ (Block7Data* _data7_,
             GObject* item)
{
	UsageStackList* self;
	GtkWidget* _tmp0_;
	GtkWidget* result;
	self = _data7_->self;
	g_return_val_if_fail (item != NULL, NULL);
	_tmp0_ = _data7_->row_function (item, _data7_->row_function_target);
	result = _tmp0_;
	return result;
}

static GtkWidget*
___lambda36__gtk_list_box_create_widget_func (GObject* item,
                                              gpointer self)
{
	GtkWidget* result;
	result = __lambda36_ (self, item);
	return result;
}

static void
__lambda35_ (Block7Data* _data7_,
             GListStore* model)
{
	UsageStackList* self;
	GtkListBox* _tmp0_;
	self = _data7_->self;
	g_return_if_fail (model != NULL);
	_tmp0_ = self->priv->list_box;
	gtk_list_box_bind_model (_tmp0_, (GListModel*) model, ___lambda36__gtk_list_box_create_widget_func, block7_data_ref (_data7_), block7_data_unref);
}

static void
___lambda35__usage_stack_list_model_changed (UsageStackList* _sender,
                                             GListStore* model,
                                             gpointer self)
{
	__lambda35_ (self, model);
}

void
usage_stack_list_init (UsageStackList* self,
                       GtkListBoxCreateWidgetFunc row_function,
                       gpointer row_function_target)
{
	Block7Data* _data7_;
	GtkScrolledWindow* scrolled_window = NULL;
	GtkScrolledWindow* _tmp0_;
	GtkListBox* _tmp1_;
	GtkListBox* _tmp2_;
	GtkListBox* _tmp3_;
	GtkListBox* _tmp4_;
	GtkListBox* _tmp5_;
	GtkListBox* _tmp6_;
	GtkListBox* _tmp7_;
	GtkListBox* _tmp8_;
	g_return_if_fail (self != NULL);
	_data7_ = g_slice_new0 (Block7Data);
	_data7_->_ref_count_ = 1;
	_data7_->self = g_object_ref (self);
	_data7_->row_function = row_function;
	_data7_->row_function_target = row_function_target;
	_tmp0_ = (GtkScrolledWindow*) gtk_scrolled_window_new ();
	g_object_ref_sink (_tmp0_);
	scrolled_window = _tmp0_;
	gtk_widget_set_vexpand ((GtkWidget*) scrolled_window, TRUE);
	gtk_widget_set_hexpand ((GtkWidget*) scrolled_window, TRUE);
	_tmp1_ = self->priv->list_box;
	gtk_scrolled_window_set_child (scrolled_window, (GtkWidget*) _tmp1_);
	_tmp2_ = self->priv->list_box;
	gtk_widget_set_margin_top ((GtkWidget*) _tmp2_, 12);
	_tmp3_ = self->priv->list_box;
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp3_, 12);
	_tmp4_ = self->priv->list_box;
	gtk_widget_set_margin_start ((GtkWidget*) _tmp4_, 12);
	_tmp5_ = self->priv->list_box;
	gtk_widget_set_margin_end ((GtkWidget*) _tmp5_, 12);
	_tmp6_ = self->priv->list_box;
	gtk_widget_set_valign ((GtkWidget*) _tmp6_, GTK_ALIGN_START);
	_tmp7_ = self->priv->list_box;
	gtk_widget_add_css_class ((GtkWidget*) _tmp7_, "boxed-list");
	gtk_box_append ((GtkBox*) self, (GtkWidget*) scrolled_window);
	_tmp8_ = self->priv->list_box;
	g_signal_connect_object (_tmp8_, "row-activated", (GCallback) ___lambda34__gtk_list_box_row_activated, self, 0);
	g_signal_connect_data (self, "model-changed", (GCallback) ___lambda35__usage_stack_list_model_changed, block7_data_ref (_data7_), (GClosureNotify) block7_data_unref, 0);
	_g_object_unref0 (scrolled_window);
	block7_data_unref (_data7_);
	_data7_ = NULL;
}

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

GListStore*
usage_stack_list_get_model (UsageStackList* self)
{
	GQueue* _tmp0_;
	gconstpointer _tmp1_;
	GListStore* _tmp2_;
	GListStore* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->models;
	_tmp1_ = g_queue_peek_head (_tmp0_);
	_tmp2_ = _g_object_ref0 ((GListStore*) _tmp1_);
	result = _tmp2_;
	return result;
}

gint
usage_stack_list_get_depth (UsageStackList* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->depth;
	return result;
}

void
usage_stack_list_push_layer (UsageStackList* self,
                             GListStore* model)
{
	GQueue* _tmp0_;
	GListStore* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (model != NULL);
	_tmp0_ = self->priv->models;
	_tmp1_ = _g_object_ref0 (model);
	g_queue_push_head (_tmp0_, _tmp1_);
	g_signal_emit (self, usage_stack_list_signals[USAGE_STACK_LIST_MODEL_CHANGED_SIGNAL], 0, model);
	self->priv->depth = self->priv->depth + 1;
}

gboolean
usage_stack_list_layer_up (UsageStackList* self)
{
	GListStore* previous_head = NULL;
	GQueue* _tmp0_;
	gpointer _tmp1_;
	GQueue* _tmp2_;
	gconstpointer _tmp3_;
	GListStore* _tmp6_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->models;
	_tmp1_ = g_queue_pop_head (_tmp0_);
	previous_head = (GListStore*) _tmp1_;
	_tmp2_ = self->priv->models;
	_tmp3_ = g_queue_peek_head (_tmp2_);
	if (((GListStore*) _tmp3_) != NULL) {
		GQueue* _tmp4_;
		gconstpointer _tmp5_;
		_tmp4_ = self->priv->models;
		_tmp5_ = g_queue_peek_head (_tmp4_);
		g_signal_emit (self, usage_stack_list_signals[USAGE_STACK_LIST_MODEL_CHANGED_SIGNAL], 0, (GListStore*) _tmp5_);
	}
	self->priv->depth = self->priv->depth - 1;
	_tmp6_ = previous_head;
	result = _tmp6_ != NULL;
	_g_object_unref0 (previous_head);
	return result;
}

UsageStackList*
usage_stack_list_construct (GType object_type)
{
	UsageStackList * self = NULL;
	self = (UsageStackList*) g_object_new (object_type, NULL);
	return self;
}

UsageStackList*
usage_stack_list_new (void)
{
	return usage_stack_list_construct (USAGE_TYPE_STACK_LIST);
}

GtkSelectionMode
usage_stack_list_get_selection_mode (UsageStackList* self)
{
	GtkSelectionMode result;
	GtkListBox* _tmp0_;
	GtkSelectionMode _tmp1_;
	GtkSelectionMode _tmp2_;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->list_box;
	_tmp1_ = gtk_list_box_get_selection_mode (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

void
usage_stack_list_set_selection_mode (UsageStackList* self,
                                     GtkSelectionMode value)
{
	GtkListBox* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->list_box;
	gtk_list_box_set_selection_mode (_tmp0_, value);
	g_object_notify_by_pspec ((GObject *) self, usage_stack_list_properties[USAGE_STACK_LIST_SELECTION_MODE_PROPERTY]);
}

static void
usage_stack_list_class_init (UsageStackListClass * klass,
                             gpointer klass_data)
{
	usage_stack_list_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &UsageStackList_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_usage_stack_list_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_usage_stack_list_set_property;
	G_OBJECT_CLASS (klass)->finalize = usage_stack_list_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), USAGE_STACK_LIST_SELECTION_MODE_PROPERTY, usage_stack_list_properties[USAGE_STACK_LIST_SELECTION_MODE_PROPERTY] = g_param_spec_enum ("selection-mode", "selection-mode", "selection-mode", gtk_selection_mode_get_type (), 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	usage_stack_list_signals[USAGE_STACK_LIST_MODEL_CHANGED_SIGNAL] = g_signal_new ("model-changed", USAGE_TYPE_STACK_LIST, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, g_list_store_get_type ());
	usage_stack_list_signals[USAGE_STACK_LIST_ROW_ACTIVATED_SIGNAL] = g_signal_new ("row-activated", USAGE_TYPE_STACK_LIST, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, gtk_list_box_row_get_type ());
}

static void
usage_stack_list_instance_init (UsageStackList * self,
                                gpointer klass)
{
	GtkListBox* _tmp0_;
	GQueue* _tmp1_;
	self->priv = usage_stack_list_get_instance_private (self);
	_tmp0_ = (GtkListBox*) gtk_list_box_new ();
	g_object_ref_sink (_tmp0_);
	self->priv->list_box = _tmp0_;
	_tmp1_ = g_queue_new ();
	self->priv->models = _tmp1_;
	self->priv->depth = 0;
}

static void
usage_stack_list_finalize (GObject * obj)
{
	UsageStackList * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, USAGE_TYPE_STACK_LIST, UsageStackList);
	_g_object_unref0 (self->priv->list_box);
	(self->priv->models == NULL) ? NULL : (self->priv->models = (_g_queue_free__g_object_unref0_ (self->priv->models), NULL));
	G_OBJECT_CLASS (usage_stack_list_parent_class)->finalize (obj);
}

static GType
usage_stack_list_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (UsageStackListClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) usage_stack_list_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UsageStackList), 0, (GInstanceInitFunc) usage_stack_list_instance_init, NULL };
	GType usage_stack_list_type_id;
	usage_stack_list_type_id = g_type_register_static (gtk_box_get_type (), "UsageStackList", &g_define_type_info, 0);
	UsageStackList_private_offset = g_type_add_instance_private (usage_stack_list_type_id, sizeof (UsageStackListPrivate));
	return usage_stack_list_type_id;
}

GType
usage_stack_list_get_type (void)
{
	static volatile gsize usage_stack_list_type_id__once = 0;
	if (g_once_init_enter (&usage_stack_list_type_id__once)) {
		GType usage_stack_list_type_id;
		usage_stack_list_type_id = usage_stack_list_get_type_once ();
		g_once_init_leave (&usage_stack_list_type_id__once, usage_stack_list_type_id);
	}
	return usage_stack_list_type_id__once;
}

static void
_vala_usage_stack_list_get_property (GObject * object,
                                     guint property_id,
                                     GValue * value,
                                     GParamSpec * pspec)
{
	UsageStackList * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, USAGE_TYPE_STACK_LIST, UsageStackList);
	switch (property_id) {
		case USAGE_STACK_LIST_SELECTION_MODE_PROPERTY:
		g_value_set_enum (value, usage_stack_list_get_selection_mode (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_usage_stack_list_set_property (GObject * object,
                                     guint property_id,
                                     const GValue * value,
                                     GParamSpec * pspec)
{
	UsageStackList * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, USAGE_TYPE_STACK_LIST, UsageStackList);
	switch (property_id) {
		case USAGE_STACK_LIST_SELECTION_MODE_PROPERTY:
		usage_stack_list_set_selection_mode (self, g_value_get_enum (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

