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

/*
* Copyright (c) 2024-2026 (https://github.com/phase1geo/Minder)
*
* 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 2 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, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* Authored by: Trevor Williams <phase1geo@gmail.com>
*/

#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <granite-7.h>
#include <stdlib.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 TYPE_MODE_BUTTONS (mode_buttons_get_type ())
#define MODE_BUTTONS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MODE_BUTTONS, ModeButtons))
#define MODE_BUTTONS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MODE_BUTTONS, ModeButtonsClass))
#define IS_MODE_BUTTONS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MODE_BUTTONS))
#define IS_MODE_BUTTONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MODE_BUTTONS))
#define MODE_BUTTONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MODE_BUTTONS, ModeButtonsClass))

typedef struct _ModeButtons ModeButtons;
typedef struct _ModeButtonsClass ModeButtonsClass;
typedef struct _ModeButtonsPrivate ModeButtonsPrivate;
enum  {
	MODE_BUTTONS_0_PROPERTY,
	MODE_BUTTONS_SELECTED_PROPERTY,
	MODE_BUTTONS_NUM_PROPERTIES
};
static GParamSpec* mode_buttons_properties[MODE_BUTTONS_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block43Data Block43Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block44Data Block44Data;
enum  {
	MODE_BUTTONS_CHANGED_SIGNAL,
	MODE_BUTTONS_UPDATE_ICONS_SIGNAL,
	MODE_BUTTONS_EDITABLE_CHANGED_SIGNAL,
	MODE_BUTTONS_NUM_SIGNALS
};
static guint mode_buttons_signals[MODE_BUTTONS_NUM_SIGNALS] = {0};

struct _ModeButtons {
	GtkBox parent_instance;
	ModeButtonsPrivate * priv;
};

struct _ModeButtonsClass {
	GtkBoxClass parent_class;
};

struct _ModeButtonsPrivate {
	gint _selected;
};

struct _Block43Data {
	int _ref_count_;
	ModeButtons* self;
	GtkImage* image;
	GtkToggleButton* button;
	gchar* light_icon_name;
	gchar* dark_icon_name;
};

struct _Block44Data {
	int _ref_count_;
	ModeButtons* self;
	GtkToggleButton* button;
};

static gint ModeButtons_private_offset;
static gpointer mode_buttons_parent_class = NULL;

VALA_EXTERN GType mode_buttons_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ModeButtons, g_object_unref)
VALA_EXTERN ModeButtons* mode_buttons_new (void);
VALA_EXTERN ModeButtons* mode_buttons_construct (GType object_type);
VALA_EXTERN void mode_buttons_add_button (ModeButtons* self,
                              const gchar* light_icon_name,
                              const gchar* dark_icon_name,
                              const gchar* tooltip);
static Block43Data* block43_data_ref (Block43Data* _data43_);
static void block43_data_unref (void * _userdata_);
static void ___lambda4_ (Block43Data* _data43_);
VALA_EXTERN gboolean utils_use_dark_mode (GtkWidget* w);
static void ____lambda4__mode_buttons_update_icons (ModeButtons* _sender,
                                             gpointer self);
static void __lambda194_ (Block43Data* _data43_);
VALA_EXTERN gint utils_get_child_index (GtkWidget* parent,
                            GtkWidget* child);
static void ___lambda194__gtk_button_clicked (GtkButton* _sender,
                                       gpointer self);
static void __lambda195_ (Block43Data* _data43_,
                   gboolean editable);
static void ___lambda195__mode_buttons_editable_changed (ModeButtons* _sender,
                                                  gboolean editable,
                                                  gpointer self);
VALA_EXTERN void mode_buttons_add_stack_tab (ModeButtons* self,
                                 const gchar* label);
static Block44Data* block44_data_ref (Block44Data* _data44_);
static void block44_data_unref (void * _userdata_);
static void __lambda196_ (Block44Data* _data44_);
static void ___lambda196__gtk_button_clicked (GtkButton* _sender,
                                       gpointer self);
VALA_EXTERN gint mode_buttons_get_selected (ModeButtons* self);
VALA_EXTERN void mode_buttons_set_selected (ModeButtons* self,
                                gint value);
VALA_EXTERN GtkWidget* utils_get_child_at_index (GtkWidget* parent,
                                     gint index);
static void mode_buttons_finalize (GObject * obj);
static GType mode_buttons_get_type_once (void);
static void _vala_mode_buttons_get_property (GObject * object,
                                      guint property_id,
                                      GValue * value,
                                      GParamSpec * pspec);
static void _vala_mode_buttons_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
mode_buttons_get_instance_private (ModeButtons* self)
{
	return G_STRUCT_MEMBER_P (self, ModeButtons_private_offset);
}

ModeButtons*
mode_buttons_construct (GType object_type)
{
	ModeButtons * self = NULL;
	self = (ModeButtons*) g_object_new (object_type, NULL);
	gtk_widget_add_css_class ((GtkWidget*) self, GRANITE_STYLE_CLASS_LINKED);
	return self;
}

ModeButtons*
mode_buttons_new (void)
{
	return mode_buttons_construct (TYPE_MODE_BUTTONS);
}

static Block43Data*
block43_data_ref (Block43Data* _data43_)
{
	g_atomic_int_inc (&_data43_->_ref_count_);
	return _data43_;
}

static void
block43_data_unref (void * _userdata_)
{
	Block43Data* _data43_;
	_data43_ = (Block43Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data43_->_ref_count_)) {
		ModeButtons* self;
		self = _data43_->self;
		_g_object_unref0 (_data43_->button);
		_g_object_unref0 (_data43_->image);
		_g_free0 (_data43_->light_icon_name);
		_g_free0 (_data43_->dark_icon_name);
		_g_object_unref0 (self);
		g_slice_free (Block43Data, _data43_);
	}
}

static void
___lambda4_ (Block43Data* _data43_)
{
	ModeButtons* self;
	const gchar* _tmp0_ = NULL;
	GtkImage* _tmp1_;
	self = _data43_->self;
	if (utils_use_dark_mode ((GtkWidget*) self)) {
		_tmp0_ = _data43_->dark_icon_name;
	} else {
		_tmp0_ = _data43_->light_icon_name;
	}
	_tmp1_ = _data43_->image;
	g_object_set (_tmp1_, "icon-name", _tmp0_, NULL);
}

static void
____lambda4__mode_buttons_update_icons (ModeButtons* _sender,
                                        gpointer self)
{
	___lambda4_ (self);
}

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

static void
__lambda194_ (Block43Data* _data43_)
{
	ModeButtons* self;
	GtkToggleButton* _tmp0_;
	self = _data43_->self;
	_tmp0_ = _data43_->button;
	self->priv->_selected = utils_get_child_index ((GtkWidget*) self, (GtkWidget*) _tmp0_);
	g_signal_emit (self, mode_buttons_signals[MODE_BUTTONS_CHANGED_SIGNAL], 0, self->priv->_selected);
}

static void
___lambda194__gtk_button_clicked (GtkButton* _sender,
                                  gpointer self)
{
	__lambda194_ (self);
}

static void
__lambda195_ (Block43Data* _data43_,
              gboolean editable)
{
	ModeButtons* self;
	GtkToggleButton* _tmp0_;
	self = _data43_->self;
	_tmp0_ = _data43_->button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp0_, editable);
}

static void
___lambda195__mode_buttons_editable_changed (ModeButtons* _sender,
                                             gboolean editable,
                                             gpointer self)
{
	__lambda195_ (self, editable);
}

void
mode_buttons_add_button (ModeButtons* self,
                         const gchar* light_icon_name,
                         const gchar* dark_icon_name,
                         const gchar* tooltip)
{
	Block43Data* _data43_;
	gchar* _tmp0_;
	gchar* _tmp1_;
	GtkImage* _tmp2_;
	GtkImage* _tmp3_;
	GtkWidget* _tmp4_;
	gchar* _tmp5_;
	GtkToggleButton* _tmp6_ = NULL;
	GtkToggleButton* _tmp7_;
	GtkWidget* first = NULL;
	GtkWidget* _tmp8_;
	GtkWidget* _tmp9_;
	GtkWidget* _tmp10_;
	GtkToggleButton* _tmp14_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (light_icon_name != NULL);
	g_return_if_fail (tooltip != NULL);
	_data43_ = g_slice_new0 (Block43Data);
	_data43_->_ref_count_ = 1;
	_data43_->self = g_object_ref (self);
	_tmp0_ = g_strdup (light_icon_name);
	_g_free0 (_data43_->light_icon_name);
	_data43_->light_icon_name = _tmp0_;
	_tmp1_ = g_strdup (dark_icon_name);
	_g_free0 (_data43_->dark_icon_name);
	_data43_->dark_icon_name = _tmp1_;
	_tmp2_ = (GtkImage*) gtk_image_new_from_icon_name (_data43_->light_icon_name);
	g_object_ref_sink (_tmp2_);
	_data43_->image = _tmp2_;
	if (_data43_->dark_icon_name != NULL) {
		g_signal_connect_data (self, "update-icons", (GCallback) ____lambda4__mode_buttons_update_icons, block43_data_ref (_data43_), (GClosureNotify) block43_data_unref, 0);
	}
	_tmp3_ = _data43_->image;
	_tmp4_ = _g_object_ref0 ((GtkWidget*) _tmp3_);
	_tmp5_ = g_strdup (tooltip);
	_tmp6_ = (GtkToggleButton*) gtk_toggle_button_new ();
	gtk_button_set_child ((GtkButton*) _tmp6_, _tmp4_);
	_g_object_unref0 (_tmp4_);
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp6_, _tmp5_);
	_g_free0 (_tmp5_);
	g_object_ref_sink (_tmp6_);
	_data43_->button = _tmp6_;
	_tmp7_ = _data43_->button;
	g_signal_connect_data ((GtkButton*) _tmp7_, "clicked", (GCallback) ___lambda194__gtk_button_clicked, block43_data_ref (_data43_), (GClosureNotify) block43_data_unref, 0);
	g_signal_connect_data (self, "editable-changed", (GCallback) ___lambda195__mode_buttons_editable_changed, block43_data_ref (_data43_), (GClosureNotify) block43_data_unref, 0);
	_tmp8_ = gtk_widget_get_first_child ((GtkWidget*) self);
	_tmp9_ = _g_object_ref0 (_tmp8_);
	first = _tmp9_;
	_tmp10_ = first;
	if (_tmp10_ != NULL) {
		GtkToggleButton* _tmp11_;
		GtkWidget* _tmp12_;
		_tmp11_ = _data43_->button;
		_tmp12_ = first;
		gtk_toggle_button_set_group (_tmp11_, G_TYPE_CHECK_INSTANCE_CAST (_tmp12_, gtk_toggle_button_get_type (), GtkToggleButton));
	} else {
		GtkToggleButton* _tmp13_;
		_tmp13_ = _data43_->button;
		gtk_toggle_button_set_active (_tmp13_, TRUE);
	}
	_tmp14_ = _data43_->button;
	gtk_box_append ((GtkBox*) self, (GtkWidget*) _tmp14_);
	_g_object_unref0 (first);
	block43_data_unref (_data43_);
	_data43_ = NULL;
}

static Block44Data*
block44_data_ref (Block44Data* _data44_)
{
	g_atomic_int_inc (&_data44_->_ref_count_);
	return _data44_;
}

static void
block44_data_unref (void * _userdata_)
{
	Block44Data* _data44_;
	_data44_ = (Block44Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data44_->_ref_count_)) {
		ModeButtons* self;
		self = _data44_->self;
		_g_object_unref0 (_data44_->button);
		_g_object_unref0 (self);
		g_slice_free (Block44Data, _data44_);
	}
}

static void
__lambda196_ (Block44Data* _data44_)
{
	ModeButtons* self;
	GtkToggleButton* _tmp0_;
	self = _data44_->self;
	_tmp0_ = _data44_->button;
	self->priv->_selected = utils_get_child_index ((GtkWidget*) self, (GtkWidget*) _tmp0_);
	g_signal_emit (self, mode_buttons_signals[MODE_BUTTONS_CHANGED_SIGNAL], 0, self->priv->_selected);
}

static void
___lambda196__gtk_button_clicked (GtkButton* _sender,
                                  gpointer self)
{
	__lambda196_ (self);
}

void
mode_buttons_add_stack_tab (ModeButtons* self,
                            const gchar* label)
{
	Block44Data* _data44_;
	GtkToggleButton* _tmp0_ = NULL;
	GtkToggleButton* _tmp1_;
	GtkWidget* first = NULL;
	GtkWidget* _tmp2_;
	GtkWidget* _tmp3_;
	GtkWidget* _tmp4_;
	GtkToggleButton* _tmp8_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (label != NULL);
	_data44_ = g_slice_new0 (Block44Data);
	_data44_->_ref_count_ = 1;
	_data44_->self = g_object_ref (self);
	_tmp0_ = (GtkToggleButton*) gtk_toggle_button_new_with_label (label);
	gtk_widget_set_halign ((GtkWidget*) _tmp0_, GTK_ALIGN_CENTER);
	g_object_ref_sink (_tmp0_);
	_data44_->button = _tmp0_;
	_tmp1_ = _data44_->button;
	g_signal_connect_data ((GtkButton*) _tmp1_, "clicked", (GCallback) ___lambda196__gtk_button_clicked, block44_data_ref (_data44_), (GClosureNotify) block44_data_unref, 0);
	_tmp2_ = gtk_widget_get_first_child ((GtkWidget*) self);
	_tmp3_ = _g_object_ref0 (_tmp2_);
	first = _tmp3_;
	_tmp4_ = first;
	if (_tmp4_ != NULL) {
		GtkToggleButton* _tmp5_;
		GtkWidget* _tmp6_;
		_tmp5_ = _data44_->button;
		_tmp6_ = first;
		gtk_toggle_button_set_group (_tmp5_, G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, gtk_toggle_button_get_type (), GtkToggleButton));
	} else {
		GtkToggleButton* _tmp7_;
		_tmp7_ = _data44_->button;
		gtk_toggle_button_set_active (_tmp7_, TRUE);
	}
	_tmp8_ = _data44_->button;
	gtk_box_append ((GtkBox*) self, (GtkWidget*) _tmp8_);
	_g_object_unref0 (first);
	block44_data_unref (_data44_);
	_data44_ = NULL;
}

gint
mode_buttons_get_selected (ModeButtons* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	result = self->priv->_selected;
	return result;
}

void
mode_buttons_set_selected (ModeButtons* self,
                           gint value)
{
	g_return_if_fail (self != NULL);
	if (self->priv->_selected != value) {
		GtkToggleButton* button = NULL;
		GtkWidget* _tmp0_;
		GtkToggleButton* _tmp1_;
		self->priv->_selected = value;
		_tmp0_ = utils_get_child_at_index ((GtkWidget*) self, value);
		button = G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_toggle_button_get_type (), GtkToggleButton);
		_tmp1_ = button;
		gtk_toggle_button_set_active (_tmp1_, TRUE);
		_g_object_unref0 (button);
	}
	g_object_notify_by_pspec ((GObject *) self, mode_buttons_properties[MODE_BUTTONS_SELECTED_PROPERTY]);
}

static void
mode_buttons_class_init (ModeButtonsClass * klass,
                         gpointer klass_data)
{
	mode_buttons_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ModeButtons_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_mode_buttons_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_mode_buttons_set_property;
	G_OBJECT_CLASS (klass)->finalize = mode_buttons_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), MODE_BUTTONS_SELECTED_PROPERTY, mode_buttons_properties[MODE_BUTTONS_SELECTED_PROPERTY] = g_param_spec_int ("selected", "selected", "selected", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	mode_buttons_signals[MODE_BUTTONS_CHANGED_SIGNAL] = g_signal_new ("changed", TYPE_MODE_BUTTONS, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
	mode_buttons_signals[MODE_BUTTONS_UPDATE_ICONS_SIGNAL] = g_signal_new ("update-icons", TYPE_MODE_BUTTONS, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	mode_buttons_signals[MODE_BUTTONS_EDITABLE_CHANGED_SIGNAL] = g_signal_new ("editable-changed", TYPE_MODE_BUTTONS, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
}

static void
mode_buttons_instance_init (ModeButtons * self,
                            gpointer klass)
{
	self->priv = mode_buttons_get_instance_private (self);
	self->priv->_selected = -1;
}

static void
mode_buttons_finalize (GObject * obj)
{
	ModeButtons * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_MODE_BUTTONS, ModeButtons);
	G_OBJECT_CLASS (mode_buttons_parent_class)->finalize (obj);
}

static GType
mode_buttons_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ModeButtonsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) mode_buttons_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ModeButtons), 0, (GInstanceInitFunc) mode_buttons_instance_init, NULL };
	GType mode_buttons_type_id;
	mode_buttons_type_id = g_type_register_static (gtk_box_get_type (), "ModeButtons", &g_define_type_info, 0);
	ModeButtons_private_offset = g_type_add_instance_private (mode_buttons_type_id, sizeof (ModeButtonsPrivate));
	return mode_buttons_type_id;
}

GType
mode_buttons_get_type (void)
{
	static volatile gsize mode_buttons_type_id__once = 0;
	if (g_once_init_enter (&mode_buttons_type_id__once)) {
		GType mode_buttons_type_id;
		mode_buttons_type_id = mode_buttons_get_type_once ();
		g_once_init_leave (&mode_buttons_type_id__once, mode_buttons_type_id);
	}
	return mode_buttons_type_id__once;
}

static void
_vala_mode_buttons_get_property (GObject * object,
                                 guint property_id,
                                 GValue * value,
                                 GParamSpec * pspec)
{
	ModeButtons * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_MODE_BUTTONS, ModeButtons);
	switch (property_id) {
		case MODE_BUTTONS_SELECTED_PROPERTY:
		g_value_set_int (value, mode_buttons_get_selected (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_mode_buttons_set_property (GObject * object,
                                 guint property_id,
                                 const GValue * value,
                                 GParamSpec * pspec)
{
	ModeButtons * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_MODE_BUTTONS, ModeButtons);
	switch (property_id) {
		case MODE_BUTTONS_SELECTED_PROPERTY:
		mode_buttons_set_selected (self, g_value_get_int (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;
}

