/* inline-stack-switcher.c generated by valac 0.56.19, the Vala compiler
 * generated from inline-stack-switcher.vala, do not modify */

/* SPDX-License-Identifier: GPL-3.0-or-later*/

#include "graphs.h"
#include <gtk/gtk.h>
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

#define GRAPHS_INLINE_STACK_SWITCHER_TIMEOUT_EXPAND 500
#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  {
	GRAPHS_INLINE_STACK_SWITCHER_0_PROPERTY,
	GRAPHS_INLINE_STACK_SWITCHER_STACK_PROPERTY,
	GRAPHS_INLINE_STACK_SWITCHER_NUM_PROPERTIES
};
static GParamSpec* graphs_inline_stack_switcher_properties[GRAPHS_INLINE_STACK_SWITCHER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
typedef struct _Block11Data Block11Data;

struct _GraphsInlineStackSwitcherPrivate {
	GtkStack* _stack;
	GtkSelectionModel* pages;
	GHashTable* buttons;
};

struct _Block11Data {
	int _ref_count_;
	GraphsInlineStackSwitcher* self;
	GtkToggleButton* button;
	gint index;
};

static gint GraphsInlineStackSwitcher_private_offset;
static gpointer graphs_inline_stack_switcher_parent_class = NULL;

static void graphs_inline_stack_switcher_real_dispose (GObject* base);
static void graphs_inline_stack_switcher_disconnect_stack (GraphsInlineStackSwitcher* self);
static void graphs_inline_stack_switcher_connect_stack (GraphsInlineStackSwitcher* self);
static void graphs_inline_stack_switcher_items_changed_cb (GraphsInlineStackSwitcher* self);
static void _graphs_inline_stack_switcher_items_changed_cb_g_list_model_items_changed (GListModel* _sender,
                                                                                guint position,
                                                                                guint removed,
                                                                                guint added,
                                                                                gpointer self);
static void graphs_inline_stack_switcher_selection_changed_cb (GraphsInlineStackSwitcher* self,
                                                        guint position,
                                                        guint n_items);
static void _graphs_inline_stack_switcher_selection_changed_cb_gtk_selection_model_selection_changed (GtkSelectionModel* _sender,
                                                                                               guint position,
                                                                                               guint n_items,
                                                                                               gpointer self);
static void graphs_inline_stack_switcher_populate_switcher (GraphsInlineStackSwitcher* self);
static void graphs_inline_stack_switcher_clear_switcher (GraphsInlineStackSwitcher* self);
static void graphs_inline_stack_switcher_add_child (GraphsInlineStackSwitcher* self,
                                             gint index);
static void __lambda4_ (GraphsInlineStackSwitcher* self,
                 GtkStackPage* page,
                 GtkToggleButton* button);
static void graphs_inline_stack_switcher_page_updated_cb (GraphsInlineStackSwitcher* self,
                                                   GObject* object,
                                                   GParamSpec* pspec);
static void _graphs_inline_stack_switcher_page_updated_cb_g_object_notify (GObject* _sender,
                                                                    GParamSpec* pspec,
                                                                    gpointer self);
static void ___lambda4__gh_func (gconstpointer key,
                          gconstpointer value,
                          gpointer self);
static Block11Data* block11_data_ref (Block11Data* _data11_);
static void block11_data_unref (void * _userdata_);
static void __lambda5_ (Block11Data* _data11_);
static gboolean __lambda6_ (Block11Data* _data11_);
static gboolean ___lambda6__gsource_func (gpointer self);
static void __lambda7_ (void* data);
static void ___lambda7__gdestroy_notify (void* data);
static void ___lambda5__gtk_drop_controller_motion_enter (GtkDropControllerMotion* _sender,
                                                   gdouble x,
                                                   gdouble y,
                                                   gpointer self);
static void __lambda8_ (Block11Data* _data11_);
static void ___lambda8__gtk_drop_controller_motion_leave (GtkDropControllerMotion* _sender,
                                                   gpointer self);
static void graphs_inline_stack_switcher_update_button (GraphsInlineStackSwitcher* self,
                                                 GtkStackPage* page,
                                                 GtkButton* button);
static void __lambda9_ (Block11Data* _data11_);
static void ___lambda9__g_object_notify (GObject* _sender,
                                  GParamSpec* pspec,
                                  gpointer self);
static void __lambda10_ (Block11Data* _data11_);
static void graphs_inline_stack_switcher_update_separator (GraphsInlineStackSwitcher* self,
                                                    GtkWidget* separator);
static void ___lambda10__gtk_widget_state_flags_changed (GtkWidget* _sender,
                                                  GtkStateFlags previous_state_flags,
                                                  gpointer self);
static gboolean graphs_inline_stack_switcher_should_hide_separators (GraphsInlineStackSwitcher* self,
                                                              GtkWidget* widget);
static GObject * graphs_inline_stack_switcher_constructor (GType type,
                                                    guint n_construct_properties,
                                                    GObjectConstructParam * construct_properties);
static void _g_object_unref0_ (gpointer var);
static void graphs_inline_stack_switcher_finalize (GObject * obj);
static GType graphs_inline_stack_switcher_get_type_once (void);
static void _vala_graphs_inline_stack_switcher_get_property (GObject * object,
                                                      guint property_id,
                                                      GValue * value,
                                                      GParamSpec * pspec);
static void _vala_graphs_inline_stack_switcher_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
graphs_inline_stack_switcher_get_instance_private (GraphsInlineStackSwitcher* self)
{
	return G_STRUCT_MEMBER_P (self, GraphsInlineStackSwitcher_private_offset);
}

static void
graphs_inline_stack_switcher_real_dispose (GObject* base)
{
	GraphsInlineStackSwitcher * self;
	GtkStack* _tmp0_;
	GtkStack* _tmp1_;
	self = (GraphsInlineStackSwitcher*) base;
	_tmp0_ = graphs_inline_stack_switcher_get_stack (self);
	_tmp1_ = _tmp0_;
	if (_tmp1_ != NULL) {
		graphs_inline_stack_switcher_disconnect_stack (self);
	}
	G_OBJECT_CLASS (graphs_inline_stack_switcher_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
}

static void
_graphs_inline_stack_switcher_items_changed_cb_g_list_model_items_changed (GListModel* _sender,
                                                                           guint position,
                                                                           guint removed,
                                                                           guint added,
                                                                           gpointer self)
{
	graphs_inline_stack_switcher_items_changed_cb ((GraphsInlineStackSwitcher*) self);
}

static void
_graphs_inline_stack_switcher_selection_changed_cb_gtk_selection_model_selection_changed (GtkSelectionModel* _sender,
                                                                                          guint position,
                                                                                          guint n_items,
                                                                                          gpointer self)
{
	graphs_inline_stack_switcher_selection_changed_cb ((GraphsInlineStackSwitcher*) self, position, n_items);
}

static void
graphs_inline_stack_switcher_connect_stack (GraphsInlineStackSwitcher* self)
{
	GtkStack* _tmp0_;
	GtkStack* _tmp1_;
	GtkSelectionModel* _tmp2_;
	GtkSelectionModel* _tmp3_;
	GtkSelectionModel* _tmp4_;
	GtkSelectionModel* _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = graphs_inline_stack_switcher_get_stack (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = gtk_stack_get_pages (_tmp1_);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (self->priv->pages);
	self->priv->pages = _tmp3_;
	_tmp4_ = self->priv->pages;
	g_signal_connect_object ((GListModel*) _tmp4_, "items-changed", (GCallback) _graphs_inline_stack_switcher_items_changed_cb_g_list_model_items_changed, self, 0);
	_tmp5_ = self->priv->pages;
	g_signal_connect_object (_tmp5_, "selection-changed", (GCallback) _graphs_inline_stack_switcher_selection_changed_cb_gtk_selection_model_selection_changed, self, 0);
	graphs_inline_stack_switcher_populate_switcher (self);
}

static void
graphs_inline_stack_switcher_disconnect_stack (GraphsInlineStackSwitcher* self)
{
	GtkSelectionModel* _tmp0_;
	guint _tmp1_;
	GtkSelectionModel* _tmp2_;
	guint _tmp3_;
	g_return_if_fail (self != NULL);
	graphs_inline_stack_switcher_clear_switcher (self);
	_tmp0_ = self->priv->pages;
	g_signal_parse_name ("items-changed", g_list_model_get_type (), &_tmp1_, NULL, FALSE);
	g_signal_handlers_disconnect_matched ((GListModel*) _tmp0_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp1_, 0, NULL, (GCallback) _graphs_inline_stack_switcher_items_changed_cb_g_list_model_items_changed, self);
	_tmp2_ = self->priv->pages;
	g_signal_parse_name ("selection-changed", gtk_selection_model_get_type (), &_tmp3_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (_tmp2_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp3_, 0, NULL, (GCallback) _graphs_inline_stack_switcher_selection_changed_cb_gtk_selection_model_selection_changed, self);
	_g_object_unref0 (self->priv->pages);
	self->priv->pages = NULL;
}

static void
graphs_inline_stack_switcher_populate_switcher (GraphsInlineStackSwitcher* self)
{
	g_return_if_fail (self != NULL);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				GtkSelectionModel* _tmp2_;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				_tmp2_ = self->priv->pages;
				if (!(((guint) i) < g_list_model_get_n_items ((GListModel*) _tmp2_))) {
					break;
				}
				graphs_inline_stack_switcher_add_child (self, i);
			}
		}
	}
}

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

static void
_graphs_inline_stack_switcher_page_updated_cb_g_object_notify (GObject* _sender,
                                                               GParamSpec* pspec,
                                                               gpointer self)
{
	graphs_inline_stack_switcher_page_updated_cb ((GraphsInlineStackSwitcher*) self, _sender, pspec);
}

static void
__lambda4_ (GraphsInlineStackSwitcher* self,
            GtkStackPage* page,
            GtkToggleButton* button)
{
	GtkWidget* separator = NULL;
	gconstpointer _tmp0_;
	GtkWidget* _tmp1_;
	guint _tmp2_;
	g_return_if_fail (page != NULL);
	g_return_if_fail (button != NULL);
	_tmp0_ = g_object_get_data ((GObject*) button, "next-separator");
	_tmp1_ = _g_object_ref0 ((GtkWidget*) _tmp0_);
	separator = _tmp1_;
	gtk_widget_unparent ((GtkWidget*) button);
	gtk_widget_unparent (separator);
	g_signal_parse_name ("notify", G_TYPE_OBJECT, &_tmp2_, NULL, FALSE);
	g_signal_handlers_disconnect_matched ((GObject*) page, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp2_, 0, NULL, (GCallback) _graphs_inline_stack_switcher_page_updated_cb_g_object_notify, self);
	_g_object_unref0 (separator);
}

static void
___lambda4__gh_func (gconstpointer key,
                     gconstpointer value,
                     gpointer self)
{
	__lambda4_ ((GraphsInlineStackSwitcher*) self, (GtkStackPage*) key, (GtkToggleButton*) value);
}

static void
graphs_inline_stack_switcher_clear_switcher (GraphsInlineStackSwitcher* self)
{
	GHashTable* _tmp0_;
	GHashTable* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->buttons;
	g_hash_table_foreach (_tmp0_, ___lambda4__gh_func, self);
	_tmp1_ = self->priv->buttons;
	g_hash_table_remove_all (_tmp1_);
}

static void
graphs_inline_stack_switcher_items_changed_cb (GraphsInlineStackSwitcher* self)
{
	g_return_if_fail (self != NULL);
	graphs_inline_stack_switcher_clear_switcher (self);
	graphs_inline_stack_switcher_populate_switcher (self);
}

static void
graphs_inline_stack_switcher_selection_changed_cb (GraphsInlineStackSwitcher* self,
                                                   guint position,
                                                   guint n_items)
{
	g_return_if_fail (self != NULL);
	{
		guint i = 0U;
		i = position;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				GtkStackPage* page = NULL;
				GtkSelectionModel* _tmp2_;
				GObject* _tmp3_;
				GtkStackPage* _tmp4_;
				GtkToggleButton* button = NULL;
				GHashTable* _tmp5_;
				GtkStackPage* _tmp6_;
				gconstpointer _tmp7_;
				GtkToggleButton* _tmp8_;
				GtkToggleButton* _tmp9_;
				if (!_tmp0_) {
					guint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				if (!(i < (position + n_items))) {
					break;
				}
				_tmp2_ = self->priv->pages;
				_tmp3_ = g_list_model_get_item ((GListModel*) _tmp2_, i);
				_tmp4_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp3_, gtk_stack_page_get_type ()) ? ((GtkStackPage*) _tmp3_) : NULL;
				if (_tmp4_ == NULL) {
					_g_object_unref0 (_tmp3_);
				}
				page = _tmp4_;
				_tmp5_ = self->priv->buttons;
				_tmp6_ = page;
				_tmp7_ = g_hash_table_lookup (_tmp5_, _tmp6_);
				_tmp8_ = _g_object_ref0 ((GtkToggleButton*) _tmp7_);
				button = _tmp8_;
				_tmp9_ = button;
				if (_tmp9_ != NULL) {
					gboolean selected = FALSE;
					GtkSelectionModel* _tmp10_;
					GtkToggleButton* _tmp11_;
					GtkToggleButton* _tmp12_;
					_tmp10_ = self->priv->pages;
					selected = gtk_selection_model_is_selected (_tmp10_, i);
					_tmp11_ = button;
					gtk_toggle_button_set_active (_tmp11_, selected);
					_tmp12_ = button;
					gtk_accessible_update_state ((GtkAccessible*) _tmp12_, GTK_ACCESSIBLE_STATE_SELECTED, selected, -1, -1);
				}
				_g_object_unref0 (button);
				_g_object_unref0 (page);
			}
		}
	}
}

static Block11Data*
block11_data_ref (Block11Data* _data11_)
{
	g_atomic_int_inc (&_data11_->_ref_count_);
	return _data11_;
}

static void
block11_data_unref (void * _userdata_)
{
	Block11Data* _data11_;
	_data11_ = (Block11Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data11_->_ref_count_)) {
		GraphsInlineStackSwitcher* self;
		self = _data11_->self;
		_g_object_unref0 (_data11_->button);
		_g_object_unref0 (self);
		g_slice_free (Block11Data, _data11_);
	}
}

static gboolean
__lambda6_ (Block11Data* _data11_)
{
	GraphsInlineStackSwitcher* self;
	GtkToggleButton* _tmp0_;
	GtkToggleButton* _tmp1_;
	gboolean result;
	self = _data11_->self;
	_tmp0_ = _data11_->button;
	g_object_steal_data ((GObject*) _tmp0_, "switch-timer");
	_tmp1_ = _data11_->button;
	gtk_toggle_button_set_active (_tmp1_, TRUE);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda6__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda6_ (self);
	return result;
}

static void
__lambda7_ (void* data)
{
	if (data != NULL) {
		g_source_remove ((guint) data);
	}
}

static void
___lambda7__gdestroy_notify (void* data)
{
	__lambda7_ (data);
}

static void
__lambda5_ (Block11Data* _data11_)
{
	GraphsInlineStackSwitcher* self;
	GtkToggleButton* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	guint switch_timer = 0U;
	GtkToggleButton* _tmp3_;
	self = _data11_->self;
	_tmp0_ = _data11_->button;
	_tmp1_ = gtk_toggle_button_get_active (_tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_) {
		return;
	}
	switch_timer = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) GRAPHS_INLINE_STACK_SWITCHER_TIMEOUT_EXPAND, ___lambda6__gsource_func, block11_data_ref (_data11_), block11_data_unref);
	_tmp3_ = _data11_->button;
	g_object_set_data_full ((GObject*) _tmp3_, "switch-timer", (void*) switch_timer, ___lambda7__gdestroy_notify);
}

static void
___lambda5__gtk_drop_controller_motion_enter (GtkDropControllerMotion* _sender,
                                              gdouble x,
                                              gdouble y,
                                              gpointer self)
{
	__lambda5_ (self);
}

static void
__lambda8_ (Block11Data* _data11_)
{
	GraphsInlineStackSwitcher* self;
	guint switch_timer = 0U;
	GtkToggleButton* _tmp0_;
	gpointer _tmp1_;
	self = _data11_->self;
	_tmp0_ = _data11_->button;
	_tmp1_ = g_object_steal_data ((GObject*) _tmp0_, "switch-timer");
	switch_timer = (guint) ((guintptr) _tmp1_);
	if (switch_timer > ((guint) 0)) {
		g_source_remove (switch_timer);
	}
}

static void
___lambda8__gtk_drop_controller_motion_leave (GtkDropControllerMotion* _sender,
                                              gpointer self)
{
	__lambda8_ (self);
}

static void
__lambda9_ (Block11Data* _data11_)
{
	GraphsInlineStackSwitcher* self;
	GtkToggleButton* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	self = _data11_->self;
	_tmp0_ = _data11_->button;
	_tmp1_ = gtk_toggle_button_get_active (_tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_) {
		GtkSelectionModel* _tmp3_;
		_tmp3_ = self->priv->pages;
		gtk_selection_model_select_item (_tmp3_, (guint) _data11_->index, TRUE);
	} else {
		GtkToggleButton* _tmp4_;
		GtkSelectionModel* _tmp5_;
		_tmp4_ = _data11_->button;
		_tmp5_ = self->priv->pages;
		gtk_toggle_button_set_active (_tmp4_, gtk_selection_model_is_selected (_tmp5_, (guint) _data11_->index));
	}
}

static void
___lambda9__g_object_notify (GObject* _sender,
                             GParamSpec* pspec,
                             gpointer self)
{
	__lambda9_ (self);
}

static void
__lambda10_ (Block11Data* _data11_)
{
	GraphsInlineStackSwitcher* self;
	GtkWidget* prev_separator = NULL;
	GtkToggleButton* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* _tmp2_;
	GtkWidget* next_separator = NULL;
	GtkToggleButton* _tmp3_;
	GtkWidget* _tmp4_;
	GtkWidget* _tmp5_;
	GtkWidget* _tmp6_;
	GtkWidget* _tmp8_;
	self = _data11_->self;
	_tmp0_ = _data11_->button;
	_tmp1_ = gtk_widget_get_prev_sibling ((GtkWidget*) _tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	prev_separator = _tmp2_;
	_tmp3_ = _data11_->button;
	_tmp4_ = gtk_widget_get_next_sibling ((GtkWidget*) _tmp3_);
	_tmp5_ = _g_object_ref0 (_tmp4_);
	next_separator = _tmp5_;
	_tmp6_ = prev_separator;
	if (_tmp6_ != NULL) {
		GtkWidget* _tmp7_;
		_tmp7_ = prev_separator;
		graphs_inline_stack_switcher_update_separator (self, _tmp7_);
	}
	_tmp8_ = next_separator;
	if (_tmp8_ != NULL) {
		GtkWidget* _tmp9_;
		_tmp9_ = next_separator;
		graphs_inline_stack_switcher_update_separator (self, _tmp9_);
	}
	_g_object_unref0 (next_separator);
	_g_object_unref0 (prev_separator);
}

static void
___lambda10__gtk_widget_state_flags_changed (GtkWidget* _sender,
                                             GtkStateFlags previous_state_flags,
                                             gpointer self)
{
	__lambda10_ (self);
}

static void
graphs_inline_stack_switcher_add_child (GraphsInlineStackSwitcher* self,
                                        gint index)
{
	Block11Data* _data11_;
	GtkToggleButton* _tmp0_ = NULL;
	GtkToggleButton* _tmp1_;
	GtkToggleButton* _tmp2_;
	GtkDropControllerMotion* controller = NULL;
	GtkDropControllerMotion* _tmp3_;
	GtkDropControllerMotion* _tmp4_;
	GtkDropControllerMotion* _tmp5_;
	GtkToggleButton* _tmp6_;
	GtkDropControllerMotion* _tmp7_;
	GtkEventController* _tmp8_;
	GtkStackPage* page = NULL;
	GtkSelectionModel* _tmp9_;
	GObject* _tmp10_;
	GtkStackPage* _tmp11_;
	GtkStackPage* _tmp12_;
	GtkToggleButton* _tmp13_;
	GtkToggleButton* _tmp14_;
	gboolean selected = FALSE;
	GtkSelectionModel* _tmp15_;
	GtkToggleButton* _tmp16_;
	GtkToggleButton* _tmp17_;
	GtkToggleButton* _tmp18_;
	GtkStackPage* _tmp19_;
	GtkToggleButton* _tmp20_;
	GtkStackPage* _tmp21_;
	GHashTable* _tmp22_;
	GtkStackPage* _tmp23_;
	GtkStackPage* _tmp24_;
	GtkToggleButton* _tmp25_;
	GtkToggleButton* _tmp26_;
	GtkSeparator* separator = NULL;
	GtkSeparator* _tmp27_;
	GtkSeparator* _tmp28_;
	GtkToggleButton* _tmp29_;
	GtkSeparator* _tmp30_;
	GtkWidget* _tmp31_;
	GtkToggleButton* _tmp32_;
	GtkWidget* prev_separator = NULL;
	GtkToggleButton* _tmp33_;
	GtkWidget* _tmp34_;
	GtkWidget* _tmp35_;
	GtkWidget* next_separator = NULL;
	GtkToggleButton* _tmp36_;
	GtkWidget* _tmp37_;
	GtkWidget* _tmp38_;
	GtkWidget* _tmp39_;
	GtkWidget* _tmp41_;
	g_return_if_fail (self != NULL);
	_data11_ = g_slice_new0 (Block11Data);
	_data11_->_ref_count_ = 1;
	_data11_->self = g_object_ref (self);
	_data11_->index = index;
	_tmp0_ = (GtkToggleButton*) gtk_toggle_button_new ();
	g_object_set ((GtkAccessible*) _tmp0_, "accessible-role", GTK_ACCESSIBLE_ROLE_TAB, NULL);
	gtk_widget_set_hexpand ((GtkWidget*) _tmp0_, TRUE);
	gtk_widget_set_vexpand ((GtkWidget*) _tmp0_, TRUE);
	gtk_widget_set_focus_on_click ((GtkWidget*) _tmp0_, FALSE);
	g_object_ref_sink (_tmp0_);
	_data11_->button = _tmp0_;
	_tmp1_ = _data11_->button;
	gtk_button_set_can_shrink ((GtkButton*) _tmp1_, TRUE);
	_tmp2_ = _data11_->button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp2_, "flat");
	_tmp3_ = (GtkDropControllerMotion*) gtk_drop_controller_motion_new ();
	controller = _tmp3_;
	_tmp4_ = controller;
	g_signal_connect_data (_tmp4_, "enter", (GCallback) ___lambda5__gtk_drop_controller_motion_enter, block11_data_ref (_data11_), (GClosureNotify) block11_data_unref, 0);
	_tmp5_ = controller;
	g_signal_connect_data (_tmp5_, "leave", (GCallback) ___lambda8__gtk_drop_controller_motion_leave, block11_data_ref (_data11_), (GClosureNotify) block11_data_unref, 0);
	_tmp6_ = _data11_->button;
	_tmp7_ = controller;
	_tmp8_ = _g_object_ref0 ((GtkEventController*) _tmp7_);
	gtk_widget_add_controller ((GtkWidget*) _tmp6_, _tmp8_);
	_tmp9_ = self->priv->pages;
	_tmp10_ = g_list_model_get_item ((GListModel*) _tmp9_, (guint) _data11_->index);
	_tmp11_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp10_, gtk_stack_page_get_type ()) ? ((GtkStackPage*) _tmp10_) : NULL;
	if (_tmp11_ == NULL) {
		_g_object_unref0 (_tmp10_);
	}
	page = _tmp11_;
	_tmp12_ = page;
	_tmp13_ = _data11_->button;
	graphs_inline_stack_switcher_update_button (self, _tmp12_, (GtkButton*) _tmp13_);
	_tmp14_ = _data11_->button;
	gtk_widget_set_parent ((GtkWidget*) _tmp14_, (GtkWidget*) self);
	_tmp15_ = self->priv->pages;
	selected = gtk_selection_model_is_selected (_tmp15_, (guint) _data11_->index);
	_tmp16_ = _data11_->button;
	gtk_toggle_button_set_active (_tmp16_, selected);
	_tmp17_ = _data11_->button;
	gtk_accessible_update_state ((GtkAccessible*) _tmp17_, GTK_ACCESSIBLE_STATE_SELECTED, selected, -1, -1);
	_tmp18_ = _data11_->button;
	_tmp19_ = page;
	gtk_accessible_update_relation ((GtkAccessible*) _tmp18_, GTK_ACCESSIBLE_RELATION_CONTROLS, _tmp19_, NULL, -1, -1);
	_tmp20_ = _data11_->button;
	g_signal_connect_data ((GObject*) _tmp20_, "notify::active", (GCallback) ___lambda9__g_object_notify, block11_data_ref (_data11_), (GClosureNotify) block11_data_unref, 0);
	_tmp21_ = page;
	g_signal_connect_object ((GObject*) _tmp21_, "notify", (GCallback) _graphs_inline_stack_switcher_page_updated_cb_g_object_notify, self, 0);
	_tmp22_ = self->priv->buttons;
	_tmp23_ = page;
	_tmp24_ = _g_object_ref0 (_tmp23_);
	_tmp25_ = _data11_->button;
	_tmp26_ = _g_object_ref0 (_tmp25_);
	g_hash_table_insert (_tmp22_, _tmp24_, _tmp26_);
	_tmp27_ = (GtkSeparator*) gtk_separator_new (GTK_ORIENTATION_VERTICAL);
	g_object_ref_sink (_tmp27_);
	separator = _tmp27_;
	_tmp28_ = separator;
	gtk_widget_set_parent ((GtkWidget*) _tmp28_, (GtkWidget*) self);
	_tmp29_ = _data11_->button;
	_tmp30_ = separator;
	_tmp31_ = _g_object_ref0 ((GtkWidget*) _tmp30_);
	g_object_set_data_full ((GObject*) _tmp29_, "separator", _tmp31_, g_object_unref);
	_tmp32_ = _data11_->button;
	g_signal_connect_data ((GtkWidget*) _tmp32_, "state-flags-changed", (GCallback) ___lambda10__gtk_widget_state_flags_changed, block11_data_ref (_data11_), (GClosureNotify) block11_data_unref, 0);
	_tmp33_ = _data11_->button;
	_tmp34_ = gtk_widget_get_prev_sibling ((GtkWidget*) _tmp33_);
	_tmp35_ = _g_object_ref0 (_tmp34_);
	prev_separator = _tmp35_;
	_tmp36_ = _data11_->button;
	_tmp37_ = gtk_widget_get_next_sibling ((GtkWidget*) _tmp36_);
	_tmp38_ = _g_object_ref0 (_tmp37_);
	next_separator = _tmp38_;
	_tmp39_ = prev_separator;
	if (_tmp39_ != NULL) {
		GtkWidget* _tmp40_;
		_tmp40_ = prev_separator;
		graphs_inline_stack_switcher_update_separator (self, _tmp40_);
	}
	_tmp41_ = next_separator;
	if (_tmp41_ != NULL) {
		GtkWidget* _tmp42_;
		_tmp42_ = next_separator;
		graphs_inline_stack_switcher_update_separator (self, _tmp42_);
	}
	_g_object_unref0 (next_separator);
	_g_object_unref0 (prev_separator);
	_g_object_unref0 (separator);
	_g_object_unref0 (page);
	_g_object_unref0 (controller);
	block11_data_unref (_data11_);
	_data11_ = NULL;
}

static void
graphs_inline_stack_switcher_page_updated_cb (GraphsInlineStackSwitcher* self,
                                              GObject* object,
                                              GParamSpec* pspec)
{
	GtkStackPage* page = NULL;
	GtkStackPage* _tmp0_;
	GtkToggleButton* button = NULL;
	GHashTable* _tmp1_;
	gconstpointer _tmp2_;
	GtkToggleButton* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (object != NULL);
	g_return_if_fail (pspec != NULL);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (object, gtk_stack_page_get_type ()) ? ((GtkStackPage*) object) : NULL);
	page = _tmp0_;
	_tmp1_ = self->priv->buttons;
	_tmp2_ = g_hash_table_lookup (_tmp1_, page);
	_tmp3_ = _g_object_ref0 ((GtkToggleButton*) _tmp2_);
	button = _tmp3_;
	graphs_inline_stack_switcher_update_button (self, page, (GtkButton*) button);
	_g_object_unref0 (button);
	_g_object_unref0 (page);
}

static void
graphs_inline_stack_switcher_update_button (GraphsInlineStackSwitcher* self,
                                            GtkStackPage* page,
                                            GtkButton* button)
{
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp12_;
	const gchar* _tmp13_;
	gboolean _tmp14_ = FALSE;
	gboolean _tmp15_;
	gboolean _tmp16_;
	gboolean _tmp22_;
	gboolean _tmp23_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (page != NULL);
	g_return_if_fail (button != NULL);
	_tmp0_ = gtk_stack_page_get_icon_name (page);
	_tmp1_ = _tmp0_;
	if (_tmp1_ != NULL) {
		const gchar* _tmp2_;
		const gchar* _tmp3_;
		const gchar* _tmp4_;
		const gchar* _tmp5_;
		_tmp2_ = gtk_stack_page_get_icon_name (page);
		_tmp3_ = _tmp2_;
		gtk_button_set_icon_name (button, _tmp3_);
		_tmp4_ = gtk_stack_page_get_title (page);
		_tmp5_ = _tmp4_;
		gtk_widget_set_tooltip_text ((GtkWidget*) button, _tmp5_);
	} else {
		const gchar* _tmp6_;
		const gchar* _tmp7_;
		_tmp6_ = gtk_stack_page_get_title (page);
		_tmp7_ = _tmp6_;
		if (_tmp7_ != NULL) {
			const gchar* _tmp8_;
			const gchar* _tmp9_;
			gboolean _tmp10_;
			gboolean _tmp11_;
			_tmp8_ = gtk_stack_page_get_title (page);
			_tmp9_ = _tmp8_;
			gtk_button_set_label (button, _tmp9_);
			_tmp10_ = gtk_stack_page_get_use_underline (page);
			_tmp11_ = _tmp10_;
			gtk_button_set_use_underline (button, _tmp11_);
			gtk_widget_set_tooltip_text ((GtkWidget*) button, NULL);
		}
	}
	_tmp12_ = gtk_stack_page_get_title (page);
	_tmp13_ = _tmp12_;
	gtk_accessible_update_property ((GtkAccessible*) button, GTK_ACCESSIBLE_PROPERTY_LABEL, _tmp13_, -1, -1);
	_tmp15_ = gtk_stack_page_get_visible (page);
	_tmp16_ = _tmp15_;
	if (_tmp16_) {
		gboolean _tmp17_ = FALSE;
		const gchar* _tmp18_;
		const gchar* _tmp19_;
		_tmp18_ = gtk_stack_page_get_title (page);
		_tmp19_ = _tmp18_;
		if (_tmp19_ != NULL) {
			_tmp17_ = TRUE;
		} else {
			const gchar* _tmp20_;
			const gchar* _tmp21_;
			_tmp20_ = gtk_stack_page_get_icon_name (page);
			_tmp21_ = _tmp20_;
			_tmp17_ = _tmp21_ != NULL;
		}
		_tmp14_ = _tmp17_;
	} else {
		_tmp14_ = FALSE;
	}
	gtk_widget_set_visible ((GtkWidget*) button, _tmp14_);
	_tmp22_ = gtk_stack_page_get_needs_attention (page);
	_tmp23_ = _tmp22_;
	if (_tmp23_) {
		gtk_widget_add_css_class ((GtkWidget*) button, "needs-attention");
	} else {
		gtk_widget_remove_css_class ((GtkWidget*) button, "needs-attention");
	}
}

static gboolean
graphs_inline_stack_switcher_should_hide_separators (GraphsInlineStackSwitcher* self,
                                                     GtkWidget* widget)
{
	GtkStateFlags flags = 0U;
	gboolean _tmp0_ = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	if (widget == NULL) {
		result = TRUE;
		return result;
	}
	flags = gtk_widget_get_state_flags (widget);
	if ((flags & ((GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_ACTIVE) | GTK_STATE_FLAG_CHECKED)) != 0) {
		result = TRUE;
		return result;
	}
	if ((flags & GTK_STATE_FLAG_FOCUSED) != 0) {
		_tmp0_ = (flags & GTK_STATE_FLAG_FOCUS_VISIBLE) != 0;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		result = TRUE;
		return result;
	}
	result = FALSE;
	return result;
}

static void
graphs_inline_stack_switcher_update_separator (GraphsInlineStackSwitcher* self,
                                               GtkWidget* separator)
{
	GtkWidget* prev_button = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* next_button = NULL;
	GtkWidget* _tmp2_;
	GtkWidget* _tmp3_;
	gboolean _tmp4_ = FALSE;
	GtkWidget* _tmp5_;
	gboolean _tmp7_ = FALSE;
	GtkWidget* _tmp8_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (separator != NULL);
	_tmp0_ = gtk_widget_get_prev_sibling (separator);
	_tmp1_ = _g_object_ref0 (_tmp0_);
	prev_button = _tmp1_;
	_tmp2_ = gtk_widget_get_next_sibling (separator);
	_tmp3_ = _g_object_ref0 (_tmp2_);
	next_button = _tmp3_;
	_tmp5_ = prev_button;
	if (_tmp5_ != NULL) {
		GtkWidget* _tmp6_;
		_tmp6_ = next_button;
		_tmp4_ = _tmp6_ != NULL;
	} else {
		_tmp4_ = FALSE;
	}
	gtk_widget_set_visible (separator, _tmp4_);
	_tmp8_ = prev_button;
	if (graphs_inline_stack_switcher_should_hide_separators (self, _tmp8_)) {
		_tmp7_ = TRUE;
	} else {
		GtkWidget* _tmp9_;
		_tmp9_ = next_button;
		_tmp7_ = graphs_inline_stack_switcher_should_hide_separators (self, _tmp9_);
	}
	if (_tmp7_) {
		gtk_widget_add_css_class (separator, "hidden");
	} else {
		gtk_widget_remove_css_class (separator, "hidden");
	}
	_g_object_unref0 (next_button);
	_g_object_unref0 (prev_button);
}

GraphsInlineStackSwitcher*
graphs_inline_stack_switcher_construct (GType object_type)
{
	GraphsInlineStackSwitcher * self = NULL;
	self = (GraphsInlineStackSwitcher*) g_object_new (object_type, NULL);
	return self;
}

GraphsInlineStackSwitcher*
graphs_inline_stack_switcher_new (void)
{
	return graphs_inline_stack_switcher_construct (GRAPHS_TYPE_INLINE_STACK_SWITCHER);
}

GtkStack*
graphs_inline_stack_switcher_get_stack (GraphsInlineStackSwitcher* self)
{
	GtkStack* result;
	GtkStack* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_stack;
	result = _tmp0_;
	return result;
}

void
graphs_inline_stack_switcher_set_stack (GraphsInlineStackSwitcher* self,
                                        GtkStack* value)
{
	GtkStack* _tmp0_;
	GtkStack* _tmp1_;
	GtkStack* _tmp2_;
	GtkStack* _tmp3_;
	GtkStack* _tmp4_;
	GtkStack* _tmp5_;
	GtkStack* _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp0_ = graphs_inline_stack_switcher_get_stack (self);
	_tmp1_ = _tmp0_;
	if (_tmp1_ == value) {
		return;
	}
	_tmp2_ = graphs_inline_stack_switcher_get_stack (self);
	_tmp3_ = _tmp2_;
	if (_tmp3_ != NULL) {
		graphs_inline_stack_switcher_disconnect_stack (self);
	}
	_tmp4_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_stack);
	self->priv->_stack = _tmp4_;
	_tmp5_ = graphs_inline_stack_switcher_get_stack (self);
	_tmp6_ = _tmp5_;
	if (_tmp6_ != NULL) {
		graphs_inline_stack_switcher_connect_stack (self);
	}
	g_object_notify_by_pspec ((GObject *) self, graphs_inline_stack_switcher_properties[GRAPHS_INLINE_STACK_SWITCHER_STACK_PROPERTY]);
}

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

static GObject *
graphs_inline_stack_switcher_constructor (GType type,
                                          guint n_construct_properties,
                                          GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GraphsInlineStackSwitcher * self;
	GHashFunc _tmp0_;
	GEqualFunc _tmp1_;
	GHashTable* _tmp2_;
	parent_class = G_OBJECT_CLASS (graphs_inline_stack_switcher_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GRAPHS_TYPE_INLINE_STACK_SWITCHER, GraphsInlineStackSwitcher);
	_tmp0_ = g_direct_hash;
	_tmp1_ = g_direct_equal;
	_tmp2_ = g_hash_table_new_full (_tmp0_, _tmp1_, _g_object_unref0_, _g_object_unref0_);
	_g_hash_table_unref0 (self->priv->buttons);
	self->priv->buttons = _tmp2_;
	return obj;
}

static void
graphs_inline_stack_switcher_class_init (GraphsInlineStackSwitcherClass * klass,
                                         gpointer klass_data)
{
	graphs_inline_stack_switcher_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GraphsInlineStackSwitcher_private_offset);
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) graphs_inline_stack_switcher_real_dispose;
	G_OBJECT_CLASS (klass)->get_property = _vala_graphs_inline_stack_switcher_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_graphs_inline_stack_switcher_set_property;
	G_OBJECT_CLASS (klass)->constructor = graphs_inline_stack_switcher_constructor;
	G_OBJECT_CLASS (klass)->finalize = graphs_inline_stack_switcher_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRAPHS_INLINE_STACK_SWITCHER_STACK_PROPERTY, graphs_inline_stack_switcher_properties[GRAPHS_INLINE_STACK_SWITCHER_STACK_PROPERTY] = g_param_spec_object ("stack", "stack", "stack", gtk_stack_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (klass), "inline-stack-switcher");
	gtk_widget_class_set_accessible_role (GTK_WIDGET_CLASS (klass), GTK_ACCESSIBLE_ROLE_TAB_LIST);
	gtk_widget_class_set_layout_manager_type (GTK_WIDGET_CLASS (klass), gtk_box_layout_get_type ());
}

static void
graphs_inline_stack_switcher_instance_init (GraphsInlineStackSwitcher * self,
                                            gpointer klass)
{
	self->priv = graphs_inline_stack_switcher_get_instance_private (self);
}

static void
graphs_inline_stack_switcher_finalize (GObject * obj)
{
	GraphsInlineStackSwitcher * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GRAPHS_TYPE_INLINE_STACK_SWITCHER, GraphsInlineStackSwitcher);
	_g_object_unref0 (self->priv->_stack);
	_g_object_unref0 (self->priv->pages);
	_g_hash_table_unref0 (self->priv->buttons);
	G_OBJECT_CLASS (graphs_inline_stack_switcher_parent_class)->finalize (obj);
}

static GType
graphs_inline_stack_switcher_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GraphsInlineStackSwitcherClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) graphs_inline_stack_switcher_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GraphsInlineStackSwitcher), 0, (GInstanceInitFunc) graphs_inline_stack_switcher_instance_init, NULL };
	GType graphs_inline_stack_switcher_type_id;
	graphs_inline_stack_switcher_type_id = g_type_register_static (gtk_widget_get_type (), "GraphsInlineStackSwitcher", &g_define_type_info, 0);
	GraphsInlineStackSwitcher_private_offset = g_type_add_instance_private (graphs_inline_stack_switcher_type_id, sizeof (GraphsInlineStackSwitcherPrivate));
	return graphs_inline_stack_switcher_type_id;
}

GType
graphs_inline_stack_switcher_get_type (void)
{
	static volatile gsize graphs_inline_stack_switcher_type_id__once = 0;
	if (g_once_init_enter (&graphs_inline_stack_switcher_type_id__once)) {
		GType graphs_inline_stack_switcher_type_id;
		graphs_inline_stack_switcher_type_id = graphs_inline_stack_switcher_get_type_once ();
		g_once_init_leave (&graphs_inline_stack_switcher_type_id__once, graphs_inline_stack_switcher_type_id);
	}
	return graphs_inline_stack_switcher_type_id__once;
}

static void
_vala_graphs_inline_stack_switcher_get_property (GObject * object,
                                                 guint property_id,
                                                 GValue * value,
                                                 GParamSpec * pspec)
{
	GraphsInlineStackSwitcher * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GRAPHS_TYPE_INLINE_STACK_SWITCHER, GraphsInlineStackSwitcher);
	switch (property_id) {
		case GRAPHS_INLINE_STACK_SWITCHER_STACK_PROPERTY:
		g_value_set_object (value, graphs_inline_stack_switcher_get_stack (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_graphs_inline_stack_switcher_set_property (GObject * object,
                                                 guint property_id,
                                                 const GValue * value,
                                                 GParamSpec * pspec)
{
	GraphsInlineStackSwitcher * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GRAPHS_TYPE_INLINE_STACK_SWITCHER, GraphsInlineStackSwitcher);
	switch (property_id) {
		case GRAPHS_INLINE_STACK_SWITCHER_STACK_PROPERTY:
		graphs_inline_stack_switcher_set_stack (self, g_value_get_object (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;
}

