/* ViewContainer.c generated by valac 0.56.19, the Vala compiler
 * generated from ViewContainer.vala, do not modify */

/*
 * Copyright 2026 elementary, Inc. (https://elementary.io)
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Authored by: Leonhard Kargl <leo.kargl@proton.me>
 */

#include <granite-7.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <gio/gio.h>
#include <float.h>
#include <math.h>

#define GALA_DAEMON_VIEW_CONTAINER_KEY_SIZE 2
#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 GALA_DAEMON_TYPE_VIEW_CONTAINER (gala_daemon_view_container_get_type ())
#define GALA_DAEMON_VIEW_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_DAEMON_TYPE_VIEW_CONTAINER, GalaDaemonViewContainer))
#define GALA_DAEMON_VIEW_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_DAEMON_TYPE_VIEW_CONTAINER, GalaDaemonViewContainerClass))
#define GALA_DAEMON_IS_VIEW_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_DAEMON_TYPE_VIEW_CONTAINER))
#define GALA_DAEMON_IS_VIEW_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_DAEMON_TYPE_VIEW_CONTAINER))
#define GALA_DAEMON_VIEW_CONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_DAEMON_TYPE_VIEW_CONTAINER, GalaDaemonViewContainerClass))

typedef struct _GalaDaemonViewContainer GalaDaemonViewContainer;
typedef struct _GalaDaemonViewContainerClass GalaDaemonViewContainerClass;
typedef struct _GalaDaemonViewContainerPrivate GalaDaemonViewContainerPrivate;
enum  {
	GALA_DAEMON_VIEW_CONTAINER_0_PROPERTY,
	GALA_DAEMON_VIEW_CONTAINER_VIEW_PROPERTY,
	GALA_DAEMON_VIEW_CONTAINER_NUM_PROPERTIES
};
static GParamSpec* gala_daemon_view_container_properties[GALA_DAEMON_VIEW_CONTAINER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define GALA_DAEMON_TYPE_KEY (gala_daemon_key_get_type ())
#define GALA_DAEMON_KEY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_DAEMON_TYPE_KEY, GalaDaemonKey))
#define GALA_DAEMON_KEY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_DAEMON_TYPE_KEY, GalaDaemonKeyClass))
#define GALA_DAEMON_IS_KEY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_DAEMON_TYPE_KEY))
#define GALA_DAEMON_IS_KEY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_DAEMON_TYPE_KEY))
#define GALA_DAEMON_KEY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_DAEMON_TYPE_KEY, GalaDaemonKeyClass))

typedef struct _GalaDaemonKey GalaDaemonKey;
typedef struct _GalaDaemonKeyClass GalaDaemonKeyClass;

#define GALA_DAEMON_TYPE_KEY_BUTTON (gala_daemon_key_button_get_type ())
#define GALA_DAEMON_KEY_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_DAEMON_TYPE_KEY_BUTTON, GalaDaemonKeyButton))
#define GALA_DAEMON_KEY_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_DAEMON_TYPE_KEY_BUTTON, GalaDaemonKeyButtonClass))
#define GALA_DAEMON_IS_KEY_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_DAEMON_TYPE_KEY_BUTTON))
#define GALA_DAEMON_IS_KEY_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_DAEMON_TYPE_KEY_BUTTON))
#define GALA_DAEMON_KEY_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_DAEMON_TYPE_KEY_BUTTON, GalaDaemonKeyButtonClass))

typedef struct _GalaDaemonKeyButton GalaDaemonKeyButton;
typedef struct _GalaDaemonKeyButtonClass GalaDaemonKeyButtonClass;

struct _GalaDaemonViewContainer {
	GraniteBin parent_instance;
	GalaDaemonViewContainerPrivate * priv;
};

struct _GalaDaemonViewContainerClass {
	GraniteBinClass parent_class;
};

struct _GalaDaemonViewContainerPrivate {
	GtkGrid* grid;
	GtkAspectFrame* aspect_frame;
};

static gint GalaDaemonViewContainer_private_offset;
static gpointer gala_daemon_view_container_parent_class = NULL;

VALA_EXTERN GType gala_daemon_view_container_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaDaemonViewContainer, g_object_unref)
static void gala_daemon_view_container_update_keys (GalaDaemonViewContainer* self,
                                             GListModel* rows);
static void gala_daemon_view_container_attach_row (GalaDaemonViewContainer* self,
                                            gint index,
                                            GListModel* row,
                                            gint* row_width,
                                            gint* row_height);
VALA_EXTERN GType gala_daemon_key_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaDaemonKey, g_object_unref)
VALA_EXTERN GType gala_daemon_key_button_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaDaemonKeyButton, g_object_unref)
VALA_EXTERN GalaDaemonKeyButton* gala_daemon_key_button_new (void);
VALA_EXTERN GalaDaemonKeyButton* gala_daemon_key_button_construct (GType object_type);
VALA_EXTERN void gala_daemon_key_button_set_key (GalaDaemonKeyButton* self,
                                     GalaDaemonKey* value);
VALA_EXTERN gdouble gala_daemon_key_get_left_offset (GalaDaemonKey* self);
VALA_EXTERN gdouble gala_daemon_key_get_width (GalaDaemonKey* self);
VALA_EXTERN gdouble gala_daemon_key_get_height (GalaDaemonKey* self);
VALA_EXTERN GalaDaemonViewContainer* gala_daemon_view_container_new (void);
VALA_EXTERN GalaDaemonViewContainer* gala_daemon_view_container_construct (GType object_type);
VALA_EXTERN void gala_daemon_view_container_set_view (GalaDaemonViewContainer* self,
                                          GListModel* value);
static GObject * gala_daemon_view_container_constructor (GType type,
                                                  guint n_construct_properties,
                                                  GObjectConstructParam * construct_properties);
static void gala_daemon_view_container_finalize (GObject * obj);
static GType gala_daemon_view_container_get_type_once (void);
static void _vala_gala_daemon_view_container_set_property (GObject * object,
                                                    guint property_id,
                                                    const GValue * value,
                                                    GParamSpec * pspec);

static inline gpointer
gala_daemon_view_container_get_instance_private (GalaDaemonViewContainer* self)
{
	return G_STRUCT_MEMBER_P (self, GalaDaemonViewContainer_private_offset);
}

static void
gala_daemon_view_container_update_keys (GalaDaemonViewContainer* self,
                                        GListModel* rows)
{
	gint max_row_width = 0;
	gint current_row = 0;
	GtkAspectFrame* _tmp11_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (rows != NULL);
	while (TRUE) {
		GtkGrid* _tmp0_;
		GtkWidget* _tmp1_;
		GtkGrid* _tmp2_;
		GtkGrid* _tmp3_;
		GtkWidget* _tmp4_;
		_tmp0_ = self->priv->grid;
		_tmp1_ = gtk_widget_get_first_child ((GtkWidget*) _tmp0_);
		if (!(_tmp1_ != NULL)) {
			break;
		}
		_tmp2_ = self->priv->grid;
		_tmp3_ = self->priv->grid;
		_tmp4_ = gtk_widget_get_first_child ((GtkWidget*) _tmp3_);
		gtk_grid_remove (_tmp2_, _tmp4_);
	}
	max_row_width = 0;
	current_row = 0;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp5_ = FALSE;
			_tmp5_ = TRUE;
			while (TRUE) {
				GListModel* row = NULL;
				GObject* _tmp7_;
				gint row_width = 0;
				gint row_height = 0;
				GListModel* _tmp8_;
				gint _tmp9_ = 0;
				gint _tmp10_ = 0;
				if (!_tmp5_) {
					gint _tmp6_;
					_tmp6_ = i;
					i = _tmp6_ + 1;
				}
				_tmp5_ = FALSE;
				if (!(((guint) i) < g_list_model_get_n_items (rows))) {
					break;
				}
				_tmp7_ = g_list_model_get_item (rows, (guint) i);
				row = G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, g_list_model_get_type (), GListModel);
				_tmp8_ = row;
				gala_daemon_view_container_attach_row (self, current_row, _tmp8_, &_tmp9_, &_tmp10_);
				row_width = _tmp9_;
				row_height = _tmp10_;
				max_row_width = MAX (max_row_width, row_width);
				current_row += row_height;
				_g_object_unref0 (row);
			}
		}
	}
	_tmp11_ = self->priv->aspect_frame;
	gtk_aspect_frame_set_ratio (_tmp11_, ((gfloat) max_row_width) / ((gfloat) current_row));
}

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

static void
gala_daemon_view_container_attach_row (GalaDaemonViewContainer* self,
                                       gint index,
                                       GListModel* row,
                                       gint* row_width,
                                       gint* row_height)
{
	gint _vala_row_width = 0;
	gint _vala_row_height = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (row != NULL);
	_vala_row_width = 0;
	_vala_row_height = 0;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				GalaDaemonKey* key = NULL;
				GObject* _tmp2_;
				GalaDaemonKeyButton* key_button = NULL;
				GalaDaemonKey* _tmp3_;
				GalaDaemonKey* _tmp4_;
				GalaDaemonKeyButton* _tmp5_ = NULL;
				GalaDaemonKey* _tmp6_;
				gdouble _tmp7_;
				gdouble _tmp8_;
				gint width = 0;
				GalaDaemonKey* _tmp9_;
				gdouble _tmp10_;
				gdouble _tmp11_;
				gint height = 0;
				GalaDaemonKey* _tmp12_;
				gdouble _tmp13_;
				gdouble _tmp14_;
				GtkGrid* _tmp15_;
				GalaDaemonKeyButton* _tmp16_;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				if (!(((guint) i) < g_list_model_get_n_items (row))) {
					break;
				}
				_tmp2_ = g_list_model_get_item (row, (guint) i);
				key = G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, GALA_DAEMON_TYPE_KEY, GalaDaemonKey);
				_tmp3_ = key;
				_tmp4_ = _g_object_ref0 (_tmp3_);
				_tmp5_ = gala_daemon_key_button_new ();
				gala_daemon_key_button_set_key (_tmp5_, _tmp4_);
				_g_object_unref0 (_tmp4_);
				g_object_ref_sink (_tmp5_);
				key_button = _tmp5_;
				_tmp6_ = key;
				_tmp7_ = gala_daemon_key_get_left_offset (_tmp6_);
				_tmp8_ = _tmp7_;
				_vala_row_width = _vala_row_width + ((gint) (_tmp8_ * GALA_DAEMON_VIEW_CONTAINER_KEY_SIZE));
				_tmp9_ = key;
				_tmp10_ = gala_daemon_key_get_width (_tmp9_);
				_tmp11_ = _tmp10_;
				width = (gint) (_tmp11_ * GALA_DAEMON_VIEW_CONTAINER_KEY_SIZE);
				_tmp12_ = key;
				_tmp13_ = gala_daemon_key_get_height (_tmp12_);
				_tmp14_ = _tmp13_;
				height = (gint) (_tmp14_ * GALA_DAEMON_VIEW_CONTAINER_KEY_SIZE);
				_tmp15_ = self->priv->grid;
				_tmp16_ = key_button;
				gtk_grid_attach (_tmp15_, (GtkWidget*) _tmp16_, _vala_row_width, index, width, height);
				_vala_row_width = _vala_row_width + width;
				_vala_row_height = MAX (_vala_row_height, height);
				_g_object_unref0 (key_button);
				_g_object_unref0 (key);
			}
		}
	}
	if (row_width) {
		*row_width = _vala_row_width;
	}
	if (row_height) {
		*row_height = _vala_row_height;
	}
}

GalaDaemonViewContainer*
gala_daemon_view_container_construct (GType object_type)
{
	GalaDaemonViewContainer * self = NULL;
	self = (GalaDaemonViewContainer*) granite_bin_construct (object_type);
	return self;
}

GalaDaemonViewContainer*
gala_daemon_view_container_new (void)
{
	return gala_daemon_view_container_construct (GALA_DAEMON_TYPE_VIEW_CONTAINER);
}

void
gala_daemon_view_container_set_view (GalaDaemonViewContainer* self,
                                     GListModel* value)
{
	g_return_if_fail (self != NULL);
	gala_daemon_view_container_update_keys (self, value);
	g_object_notify_by_pspec ((GObject *) self, gala_daemon_view_container_properties[GALA_DAEMON_VIEW_CONTAINER_VIEW_PROPERTY]);
}

static GObject *
gala_daemon_view_container_constructor (GType type,
                                        guint n_construct_properties,
                                        GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GalaDaemonViewContainer * self;
	GtkGrid* _tmp0_ = NULL;
	GtkGrid* _tmp1_;
	GtkWidget* _tmp2_;
	GtkAspectFrame* _tmp3_ = NULL;
	GtkAspectFrame* _tmp4_;
	parent_class = G_OBJECT_CLASS (gala_daemon_view_container_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_DAEMON_TYPE_VIEW_CONTAINER, GalaDaemonViewContainer);
	_tmp0_ = (GtkGrid*) gtk_grid_new ();
	gtk_grid_set_row_homogeneous (_tmp0_, TRUE);
	gtk_grid_set_column_homogeneous (_tmp0_, TRUE);
	gtk_grid_set_row_spacing (_tmp0_, 4);
	gtk_grid_set_column_spacing (_tmp0_, 4);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->grid);
	self->priv->grid = _tmp0_;
	_tmp1_ = self->priv->grid;
	_tmp2_ = _g_object_ref0 ((GtkWidget*) _tmp1_);
	_tmp3_ = (GtkAspectFrame*) gtk_aspect_frame_new (0.5f, 0.5f, 1.0f, FALSE);
	gtk_aspect_frame_set_child (_tmp3_, _tmp2_);
	_g_object_unref0 (_tmp2_);
	gtk_widget_set_margin_top ((GtkWidget*) _tmp3_, 6);
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp3_, 6);
	gtk_widget_set_margin_start ((GtkWidget*) _tmp3_, 6);
	gtk_widget_set_margin_end ((GtkWidget*) _tmp3_, 6);
	g_object_ref_sink (_tmp3_);
	_g_object_unref0 (self->priv->aspect_frame);
	self->priv->aspect_frame = _tmp3_;
	_tmp4_ = self->priv->aspect_frame;
	granite_bin_set_child ((GraniteBin*) self, (GtkWidget*) _tmp4_);
	return obj;
}

static void
gala_daemon_view_container_class_init (GalaDaemonViewContainerClass * klass,
                                       gpointer klass_data)
{
	gala_daemon_view_container_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GalaDaemonViewContainer_private_offset);
	G_OBJECT_CLASS (klass)->set_property = _vala_gala_daemon_view_container_set_property;
	G_OBJECT_CLASS (klass)->constructor = gala_daemon_view_container_constructor;
	G_OBJECT_CLASS (klass)->finalize = gala_daemon_view_container_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_DAEMON_VIEW_CONTAINER_VIEW_PROPERTY, gala_daemon_view_container_properties[GALA_DAEMON_VIEW_CONTAINER_VIEW_PROPERTY] = g_param_spec_object ("view", "view", "view", g_list_model_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE));
}

static void
gala_daemon_view_container_instance_init (GalaDaemonViewContainer * self,
                                          gpointer klass)
{
	self->priv = gala_daemon_view_container_get_instance_private (self);
}

static void
gala_daemon_view_container_finalize (GObject * obj)
{
	GalaDaemonViewContainer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_DAEMON_TYPE_VIEW_CONTAINER, GalaDaemonViewContainer);
	_g_object_unref0 (self->priv->grid);
	_g_object_unref0 (self->priv->aspect_frame);
	G_OBJECT_CLASS (gala_daemon_view_container_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gala_daemon_view_container_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaDaemonViewContainerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_daemon_view_container_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaDaemonViewContainer), 0, (GInstanceInitFunc) gala_daemon_view_container_instance_init, NULL };
	GType gala_daemon_view_container_type_id;
	gala_daemon_view_container_type_id = g_type_register_static (GRANITE_TYPE_BIN, "GalaDaemonViewContainer", &g_define_type_info, G_TYPE_FLAG_NONE);
	GalaDaemonViewContainer_private_offset = g_type_add_instance_private (gala_daemon_view_container_type_id, sizeof (GalaDaemonViewContainerPrivate));
	return gala_daemon_view_container_type_id;
}

GType
gala_daemon_view_container_get_type (void)
{
	static gsize gala_daemon_view_container_type_id__once = 0;
	if (g_once_init_enter (&gala_daemon_view_container_type_id__once)) {
		GType gala_daemon_view_container_type_id;
		gala_daemon_view_container_type_id = gala_daemon_view_container_get_type_once ();
		g_once_init_leave (&gala_daemon_view_container_type_id__once, gala_daemon_view_container_type_id);
	}
	return gala_daemon_view_container_type_id__once;
}

static void
_vala_gala_daemon_view_container_set_property (GObject * object,
                                               guint property_id,
                                               const GValue * value,
                                               GParamSpec * pspec)
{
	GalaDaemonViewContainer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_DAEMON_TYPE_VIEW_CONTAINER, GalaDaemonViewContainer);
	switch (property_id) {
		case GALA_DAEMON_VIEW_CONTAINER_VIEW_PROPERTY:
		gala_daemon_view_container_set_view (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

