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

/*
 * SPDX-License-Identifier: GPL-3.0-or-later
 * SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io)
 *                         2014 Corentin Noël <tintou@mailoo.org>
 *                         2011-2012 Giulio Collura
 */

#include "slingshot.h"
#include <handy.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <glib-object.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  {
	SLINGSHOT_WIDGETS_SWITCHER_0_PROPERTY,
	SLINGSHOT_WIDGETS_SWITCHER_CAROUSEL_PROPERTY,
	SLINGSHOT_WIDGETS_SWITCHER_NUM_PROPERTIES
};
static GParamSpec* slingshot_widgets_switcher_properties[SLINGSHOT_WIDGETS_SWITCHER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block15Data Block15Data;

struct _SlingshotWidgetsSwitcherPrivate {
	HdyCarousel* _carousel;
};

struct _Block15Data {
	int _ref_count_;
	SlingshotWidgetsSwitcher* self;
	GtkWidget* page;
};

static gint SlingshotWidgetsSwitcher_private_offset;
static gpointer slingshot_widgets_switcher_parent_class = NULL;

static void slingshot_widgets_switcher_update_pages (SlingshotWidgetsSwitcher* self);
static void __lambda45_ (SlingshotWidgetsSwitcher* self,
                  GtkWidget* child);
static void ___lambda45__gfunc (gconstpointer data,
                         gpointer self);
static Block15Data* block15_data_ref (Block15Data* _data15_);
static void block15_data_unref (void * _userdata_);
static void _____lambda47_ (Block15Data* _data15_);
static void ______lambda47__gtk_button_clicked (GtkButton* _sender,
                                         gpointer self);
static void _slingshot_widgets_switcher_update_pages_g_object_notify (GObject* _sender,
                                                               GParamSpec* pspec,
                                                               gpointer self);
static GObject * slingshot_widgets_switcher_constructor (GType type,
                                                  guint n_construct_properties,
                                                  GObjectConstructParam * construct_properties);
static void slingshot_widgets_switcher_finalize (GObject * obj);
static GType slingshot_widgets_switcher_get_type_once (void);
static void _vala_slingshot_widgets_switcher_set_property (GObject * object,
                                                    guint property_id,
                                                    const GValue * value,
                                                    GParamSpec * pspec);

static inline gpointer
slingshot_widgets_switcher_get_instance_private (SlingshotWidgetsSwitcher* self)
{
	return G_STRUCT_MEMBER_P (self, SlingshotWidgetsSwitcher_private_offset);
}

static void
__lambda45_ (SlingshotWidgetsSwitcher* self,
             GtkWidget* child)
{
	g_return_if_fail (child != NULL);
	gtk_widget_destroy (child);
}

static void
___lambda45__gfunc (gconstpointer data,
                    gpointer self)
{
	__lambda45_ ((SlingshotWidgetsSwitcher*) self, (GtkWidget*) data);
}

static Block15Data*
block15_data_ref (Block15Data* _data15_)
{
	g_atomic_int_inc (&_data15_->_ref_count_);
	return _data15_;
}

static void
block15_data_unref (void * _userdata_)
{
	Block15Data* _data15_;
	_data15_ = (Block15Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data15_->_ref_count_)) {
		SlingshotWidgetsSwitcher* self;
		self = _data15_->self;
		_g_object_unref0 (self);
		g_slice_free (Block15Data, _data15_);
	}
}

static void
_____lambda47_ (Block15Data* _data15_)
{
	SlingshotWidgetsSwitcher* self;
	HdyCarousel* _tmp0_;
	GtkWidget* _tmp1_;
	self = _data15_->self;
	_tmp0_ = self->priv->_carousel;
	_tmp1_ = _data15_->page;
	hdy_carousel_scroll_to (_tmp0_, _tmp1_);
}

static void
______lambda47__gtk_button_clicked (GtkButton* _sender,
                                    gpointer self)
{
	_____lambda47_ (self);
}

static void
slingshot_widgets_switcher_update_pages (SlingshotWidgetsSwitcher* self)
{
	GList* _tmp0_;
	GList* _tmp1_;
	HdyCarousel* _tmp2_;
	guint _tmp3_;
	guint _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gtk_container_get_children ((GtkContainer*) self);
	_tmp1_ = _tmp0_;
	g_list_foreach (_tmp1_, ___lambda45__gfunc, self);
	(_tmp1_ == NULL) ? NULL : (_tmp1_ = (g_list_free (_tmp1_), NULL));
	_tmp2_ = self->priv->_carousel;
	_tmp3_ = hdy_carousel_get_n_pages (_tmp2_);
	_tmp4_ = _tmp3_;
	if (_tmp4_ == ((guint) 1)) {
		gtk_widget_hide ((GtkWidget*) self);
		return;
	}
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp5_ = FALSE;
			_tmp5_ = TRUE;
			while (TRUE) {
				Block15Data* _data15_;
				HdyCarousel* _tmp7_;
				HdyCarousel* _tmp8_;
				GList* _tmp9_;
				GList* _tmp10_;
				gconstpointer _tmp11_;
				GtkWidget* _tmp12_;
				SlingshotWidgetsPageChecker* button = NULL;
				HdyCarousel* _tmp13_;
				SlingshotWidgetsPageChecker* _tmp14_;
				SlingshotWidgetsPageChecker* _tmp15_;
				SlingshotWidgetsPageChecker* _tmp16_;
				SlingshotWidgetsPageChecker* _tmp17_;
				_data15_ = g_slice_new0 (Block15Data);
				_data15_->_ref_count_ = 1;
				_data15_->self = g_object_ref (self);
				if (!_tmp5_) {
					gint _tmp6_;
					_tmp6_ = i;
					i = _tmp6_ + 1;
				}
				_tmp5_ = FALSE;
				_tmp7_ = self->priv->_carousel;
				if (!(((guint) i) < hdy_carousel_get_n_pages (_tmp7_))) {
					block15_data_unref (_data15_);
					_data15_ = NULL;
					break;
				}
				_tmp8_ = self->priv->_carousel;
				_tmp9_ = gtk_container_get_children ((GtkContainer*) _tmp8_);
				_tmp10_ = _tmp9_;
				_tmp11_ = g_list_nth_data (_tmp10_, (guint) i);
				_tmp12_ = (GtkWidget*) _tmp11_;
				(_tmp10_ == NULL) ? NULL : (_tmp10_ = (g_list_free (_tmp10_), NULL));
				_data15_->page = _tmp12_;
				_tmp13_ = self->priv->_carousel;
				_tmp14_ = slingshot_widgets_page_checker_new (_tmp13_, i);
				g_object_ref_sink (_tmp14_);
				button = _tmp14_;
				_tmp15_ = button;
				gtk_widget_show ((GtkWidget*) _tmp15_);
				_tmp16_ = button;
				gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp16_);
				_tmp17_ = button;
				g_signal_connect_data ((GtkButton*) _tmp17_, "clicked", (GCallback) ______lambda47__gtk_button_clicked, block15_data_ref (_data15_), (GClosureNotify) block15_data_unref, 0);
				_g_object_unref0 (button);
				block15_data_unref (_data15_);
				_data15_ = NULL;
			}
		}
	}
}

SlingshotWidgetsSwitcher*
slingshot_widgets_switcher_construct (GType object_type)
{
	SlingshotWidgetsSwitcher * self = NULL;
	self = (SlingshotWidgetsSwitcher*) g_object_new (object_type, NULL);
	return self;
}

SlingshotWidgetsSwitcher*
slingshot_widgets_switcher_new (void)
{
	return slingshot_widgets_switcher_construct (SLINGSHOT_WIDGETS_TYPE_SWITCHER);
}

static void
_slingshot_widgets_switcher_update_pages_g_object_notify (GObject* _sender,
                                                          GParamSpec* pspec,
                                                          gpointer self)
{
	slingshot_widgets_switcher_update_pages ((SlingshotWidgetsSwitcher*) self);
}

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

void
slingshot_widgets_switcher_set_carousel (SlingshotWidgetsSwitcher* self,
                                         HdyCarousel* value)
{
	HdyCarousel* _tmp0_;
	HdyCarousel* _tmp4_;
	HdyCarousel* _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_carousel;
	if (_tmp0_ != NULL) {
		HdyCarousel* _tmp1_;
		guint _tmp2_;
		GQuark _tmp3_;
		_tmp1_ = self->priv->_carousel;
		g_signal_parse_name ("notify::n-pages", G_TYPE_OBJECT, &_tmp2_, &_tmp3_, TRUE);
		g_signal_handlers_disconnect_matched ((GObject*) _tmp1_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp2_, _tmp3_, NULL, (GCallback) _slingshot_widgets_switcher_update_pages_g_object_notify, self);
	}
	_tmp4_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_carousel);
	self->priv->_carousel = _tmp4_;
	slingshot_widgets_switcher_update_pages (self);
	_tmp5_ = self->priv->_carousel;
	g_signal_connect_object ((GObject*) _tmp5_, "notify::n-pages", (GCallback) _slingshot_widgets_switcher_update_pages_g_object_notify, self, 0);
	g_object_notify_by_pspec ((GObject *) self, slingshot_widgets_switcher_properties[SLINGSHOT_WIDGETS_SWITCHER_CAROUSEL_PROPERTY]);
}

static GObject *
slingshot_widgets_switcher_constructor (GType type,
                                        guint n_construct_properties,
                                        GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	SlingshotWidgetsSwitcher * self;
	parent_class = G_OBJECT_CLASS (slingshot_widgets_switcher_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SLINGSHOT_WIDGETS_TYPE_SWITCHER, SlingshotWidgetsSwitcher);
	gtk_box_set_spacing ((GtkBox*) self, 3);
	gtk_widget_set_can_focus ((GtkWidget*) self, FALSE);
	return obj;
}

static void
slingshot_widgets_switcher_class_init (SlingshotWidgetsSwitcherClass * klass,
                                       gpointer klass_data)
{
	slingshot_widgets_switcher_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SlingshotWidgetsSwitcher_private_offset);
	G_OBJECT_CLASS (klass)->set_property = _vala_slingshot_widgets_switcher_set_property;
	G_OBJECT_CLASS (klass)->constructor = slingshot_widgets_switcher_constructor;
	G_OBJECT_CLASS (klass)->finalize = slingshot_widgets_switcher_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SLINGSHOT_WIDGETS_SWITCHER_CAROUSEL_PROPERTY, slingshot_widgets_switcher_properties[SLINGSHOT_WIDGETS_SWITCHER_CAROUSEL_PROPERTY] = g_param_spec_object ("carousel", "carousel", "carousel", hdy_carousel_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE));
}

static void
slingshot_widgets_switcher_instance_init (SlingshotWidgetsSwitcher * self,
                                          gpointer klass)
{
	self->priv = slingshot_widgets_switcher_get_instance_private (self);
}

static void
slingshot_widgets_switcher_finalize (GObject * obj)
{
	SlingshotWidgetsSwitcher * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SLINGSHOT_WIDGETS_TYPE_SWITCHER, SlingshotWidgetsSwitcher);
	_g_object_unref0 (self->priv->_carousel);
	G_OBJECT_CLASS (slingshot_widgets_switcher_parent_class)->finalize (obj);
}

static GType
slingshot_widgets_switcher_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SlingshotWidgetsSwitcherClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) slingshot_widgets_switcher_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SlingshotWidgetsSwitcher), 0, (GInstanceInitFunc) slingshot_widgets_switcher_instance_init, NULL };
	GType slingshot_widgets_switcher_type_id;
	slingshot_widgets_switcher_type_id = g_type_register_static (gtk_box_get_type (), "SlingshotWidgetsSwitcher", &g_define_type_info, 0);
	SlingshotWidgetsSwitcher_private_offset = g_type_add_instance_private (slingshot_widgets_switcher_type_id, sizeof (SlingshotWidgetsSwitcherPrivate));
	return slingshot_widgets_switcher_type_id;
}

GType
slingshot_widgets_switcher_get_type (void)
{
	static volatile gsize slingshot_widgets_switcher_type_id__once = 0;
	if (g_once_init_enter (&slingshot_widgets_switcher_type_id__once)) {
		GType slingshot_widgets_switcher_type_id;
		slingshot_widgets_switcher_type_id = slingshot_widgets_switcher_get_type_once ();
		g_once_init_leave (&slingshot_widgets_switcher_type_id__once, slingshot_widgets_switcher_type_id);
	}
	return slingshot_widgets_switcher_type_id__once;
}

static void
_vala_slingshot_widgets_switcher_set_property (GObject * object,
                                               guint property_id,
                                               const GValue * value,
                                               GParamSpec * pspec)
{
	SlingshotWidgetsSwitcher * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SLINGSHOT_WIDGETS_TYPE_SWITCHER, SlingshotWidgetsSwitcher);
	switch (property_id) {
		case SLINGSHOT_WIDGETS_SWITCHER_CAROUSEL_PROPERTY:
		slingshot_widgets_switcher_set_carousel (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

