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

/*
 * Copyright 2025 elementary, Inc. (https://elementary.io)
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "granite-7.h"
#include <gtk/gtk.h>
#include <glib.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  {
	GRANITE_TOOL_BOX_0_PROPERTY,
	GRANITE_TOOL_BOX_CONTENT_PROPERTY,
	GRANITE_TOOL_BOX_NUM_PROPERTIES
};
static GParamSpec* granite_tool_box_properties[GRANITE_TOOL_BOX_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _GraniteToolBoxPrivate {
	GtkWidget* _content;
	GtkBox* bottom_box;
	GtkBox* top_box;
	GtkWindowHandle* top_handle;
};

static gint GraniteToolBox_private_offset;
static gpointer granite_tool_box_parent_class = NULL;
static GtkAccessibleInterface * granite_tool_box_gtk_accessible_parent_iface = NULL;

static GObject * granite_tool_box_constructor (GType type,
                                        guint n_construct_properties,
                                        GObjectConstructParam * construct_properties);
static void granite_tool_box_finalize (GObject * obj);
static GType granite_tool_box_get_type_once (void);
static void _vala_granite_tool_box_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec);
static void _vala_granite_tool_box_set_property (GObject * object,
                                          guint property_id,
                                          const GValue * value,
                                          GParamSpec * pspec);

static inline gpointer
granite_tool_box_get_instance_private (GraniteToolBox* self)
{
	return G_STRUCT_MEMBER_P (self, GraniteToolBox_private_offset);
}

GtkWidget*
granite_tool_box_get_content (GraniteToolBox* self)
{
	GtkWidget* result;
	GtkWidget* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_content;
	result = _tmp0_;
	return result;
}

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

void
granite_tool_box_set_content (GraniteToolBox* self,
                              GtkWidget* value)
{
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* _tmp2_;
	GtkWidget* _tmp3_;
	GtkWidget* _tmp4_;
	GtkWidget* _tmp5_;
	GtkWindowHandle* _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp0_ = granite_tool_box_get_content (self);
	_tmp1_ = _tmp0_;
	g_return_if_fail (_tmp1_ == NULL);
	_tmp2_ = gtk_widget_get_parent (value);
	_tmp3_ = _tmp2_;
	g_return_if_fail (_tmp3_ == NULL);
	_tmp4_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_content);
	self->priv->_content = _tmp4_;
	_tmp5_ = self->priv->_content;
	_tmp6_ = self->priv->top_handle;
	gtk_widget_insert_after (_tmp5_, (GtkWidget*) self, (GtkWidget*) _tmp6_);
	g_object_notify_by_pspec ((GObject *) self, granite_tool_box_properties[GRANITE_TOOL_BOX_CONTENT_PROPERTY]);
}

/**
     * Adds a top bar to #this
     *
     * Top bars can be dragged to move the window, equivalent to putting them into a {@link Gtk.WindowHandle}
     */
void
granite_tool_box_add_top_bar (GraniteToolBox* self,
                              GtkWidget* widget)
{
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	GtkBox* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (widget != NULL);
	_tmp0_ = gtk_widget_get_parent (widget);
	_tmp1_ = _tmp0_;
	_vala_return_if_fail (_tmp1_ == NULL, "widget.parent == null");
	_tmp2_ = self->priv->top_box;
	gtk_box_append (_tmp2_, widget);
}

/**
     * Adds a bottom bar to #this
     *
     * bottom bars can be dragged to move the window, equivalent to putting them into a {@link Gtk.WindowHandle}
     */
void
granite_tool_box_add_bottom_bar (GraniteToolBox* self,
                                 GtkWidget* widget)
{
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	GtkBox* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (widget != NULL);
	_tmp0_ = gtk_widget_get_parent (widget);
	_tmp1_ = _tmp0_;
	_vala_return_if_fail (_tmp1_ == NULL, "widget.parent == null");
	_tmp2_ = self->priv->bottom_box;
	gtk_box_append (_tmp2_, widget);
}

/**
     * Remove a previously added child from #this
     */
void
granite_tool_box_remove (GraniteToolBox* self,
                         GtkWidget* widget)
{
	GtkWidget* parent = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	gboolean _tmp2_ = FALSE;
	GtkWidget* _tmp3_;
	GtkBox* _tmp4_;
	GtkWidget* _tmp8_;
	GtkWidget* _tmp9_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (widget != NULL);
	_tmp0_ = gtk_widget_get_parent (widget);
	_tmp1_ = _g_object_ref0 (_tmp0_);
	parent = _tmp1_;
	_tmp3_ = parent;
	_tmp4_ = self->priv->top_box;
	if (_tmp3_ == G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, gtk_widget_get_type (), GtkWidget)) {
		_tmp2_ = TRUE;
	} else {
		GtkWidget* _tmp5_;
		GtkBox* _tmp6_;
		_tmp5_ = parent;
		_tmp6_ = self->priv->bottom_box;
		_tmp2_ = _tmp5_ == G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, gtk_widget_get_type (), GtkWidget);
	}
	if (_tmp2_) {
		GtkWidget* _tmp7_;
		_tmp7_ = parent;
		gtk_box_remove (G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, gtk_box_get_type (), GtkBox), widget);
		_g_object_unref0 (parent);
		return;
	}
	_tmp8_ = granite_tool_box_get_content (self);
	_tmp9_ = _tmp8_;
	if (widget == _tmp9_) {
		gtk_widget_unparent (widget);
	}
	_g_object_unref0 (parent);
}

GraniteToolBox*
granite_tool_box_construct (GType object_type)
{
	GraniteToolBox * self = NULL;
	self = (GraniteToolBox*) g_object_new (object_type, NULL);
	return self;
}

GraniteToolBox*
granite_tool_box_new (void)
{
	return granite_tool_box_construct (GRANITE_TYPE_TOOL_BOX);
}

static GObject *
granite_tool_box_constructor (GType type,
                              guint n_construct_properties,
                              GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GraniteToolBox * self;
	GtkBoxLayout* layout_manager = NULL;
	GtkLayoutManager* _tmp0_;
	GtkBoxLayout* _tmp1_;
	GtkBoxLayout* _tmp2_;
	GtkBox* _tmp3_;
	GtkBox* _tmp4_;
	GtkBox* _tmp5_;
	GtkWidget* _tmp6_;
	GtkWindowHandle* _tmp7_ = NULL;
	GtkBox* _tmp8_;
	GtkBox* _tmp9_;
	GtkWindowHandle* bottom_handle = NULL;
	GtkBox* _tmp10_;
	GtkWidget* _tmp11_;
	GtkWindowHandle* _tmp12_ = NULL;
	GtkWindowHandle* _tmp13_;
	GtkWindowHandle* _tmp14_;
	GtkWindowHandle* _tmp15_;
	parent_class = G_OBJECT_CLASS (granite_tool_box_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GRANITE_TYPE_TOOL_BOX, GraniteToolBox);
	_tmp0_ = gtk_widget_get_layout_manager ((GtkWidget*) self);
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_box_layout_get_type (), GtkBoxLayout));
	layout_manager = _tmp1_;
	_tmp2_ = layout_manager;
	gtk_orientable_set_orientation ((GtkOrientable*) _tmp2_, GTK_ORIENTATION_VERTICAL);
	_tmp3_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp3_);
	_g_object_unref0 (self->priv->top_box);
	self->priv->top_box = _tmp3_;
	_tmp4_ = self->priv->top_box;
	gtk_widget_add_css_class ((GtkWidget*) _tmp4_, "top");
	_tmp5_ = self->priv->top_box;
	_tmp6_ = _g_object_ref0 ((GtkWidget*) _tmp5_);
	_tmp7_ = (GtkWindowHandle*) gtk_window_handle_new ();
	gtk_window_handle_set_child (_tmp7_, _tmp6_);
	_g_object_unref0 (_tmp6_);
	g_object_ref_sink (_tmp7_);
	_g_object_unref0 (self->priv->top_handle);
	self->priv->top_handle = _tmp7_;
	_tmp8_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp8_);
	_g_object_unref0 (self->priv->bottom_box);
	self->priv->bottom_box = _tmp8_;
	_tmp9_ = self->priv->bottom_box;
	gtk_widget_add_css_class ((GtkWidget*) _tmp9_, "bottom");
	_tmp10_ = self->priv->bottom_box;
	_tmp11_ = _g_object_ref0 ((GtkWidget*) _tmp10_);
	_tmp12_ = (GtkWindowHandle*) gtk_window_handle_new ();
	gtk_window_handle_set_child (_tmp12_, _tmp11_);
	_g_object_unref0 (_tmp11_);
	g_object_ref_sink (_tmp12_);
	bottom_handle = _tmp12_;
	_tmp13_ = self->priv->top_handle;
	gtk_widget_set_parent ((GtkWidget*) _tmp13_, (GtkWidget*) self);
	_tmp14_ = bottom_handle;
	_tmp15_ = self->priv->top_handle;
	gtk_widget_insert_after ((GtkWidget*) _tmp14_, (GtkWidget*) self, (GtkWidget*) _tmp15_);
	_g_object_unref0 (bottom_handle);
	_g_object_unref0 (layout_manager);
	return obj;
}

static void
granite_tool_box_base_init (GraniteToolBoxClass * klass)
{
	gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (klass), "toolbox");
	gtk_widget_class_set_accessible_role (GTK_WIDGET_CLASS (klass), GTK_ACCESSIBLE_ROLE_GROUP);
	gtk_widget_class_set_layout_manager_type (GTK_WIDGET_CLASS (klass), gtk_box_layout_get_type ());
}

static void
granite_tool_box_class_init (GraniteToolBoxClass * klass,
                             gpointer klass_data)
{
	granite_tool_box_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GraniteToolBox_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_granite_tool_box_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_granite_tool_box_set_property;
	G_OBJECT_CLASS (klass)->constructor = granite_tool_box_constructor;
	G_OBJECT_CLASS (klass)->finalize = granite_tool_box_finalize;
	/**
	     * The child widget for the content area
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRANITE_TOOL_BOX_CONTENT_PROPERTY, granite_tool_box_properties[GRANITE_TOOL_BOX_CONTENT_PROPERTY] = g_param_spec_object ("content", "content", "content", gtk_widget_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
granite_tool_box_gtk_accessible_interface_init (GtkAccessibleInterface * iface,
                                                gpointer iface_data)
{
	granite_tool_box_gtk_accessible_parent_iface = g_type_interface_peek_parent (iface);
}

static void
granite_tool_box_instance_init (GraniteToolBox * self,
                                gpointer klass)
{
	self->priv = granite_tool_box_get_instance_private (self);
}

static void
granite_tool_box_finalize (GObject * obj)
{
	GraniteToolBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GRANITE_TYPE_TOOL_BOX, GraniteToolBox);
	while (TRUE) {
		GtkWidget* _tmp0_;
		GtkWidget* _tmp1_;
		_tmp0_ = gtk_widget_get_first_child ((GtkWidget*) self);
		if (!(_tmp0_ != NULL)) {
			break;
		}
		_tmp1_ = gtk_widget_get_first_child ((GtkWidget*) self);
		gtk_widget_unparent (_tmp1_);
	}
	_g_object_unref0 (self->priv->_content);
	_g_object_unref0 (self->priv->bottom_box);
	_g_object_unref0 (self->priv->top_box);
	_g_object_unref0 (self->priv->top_handle);
	G_OBJECT_CLASS (granite_tool_box_parent_class)->finalize (obj);
}

/**
 * A widget containing a page, as well as top and/or bottom bars
 *
 * @since 7.7.0
 */
static GType
granite_tool_box_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GraniteToolBoxClass), (GBaseInitFunc) granite_tool_box_base_init, (GBaseFinalizeFunc) NULL, (GClassInitFunc) granite_tool_box_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GraniteToolBox), 0, (GInstanceInitFunc) granite_tool_box_instance_init, NULL };
	static const GInterfaceInfo gtk_accessible_info = { (GInterfaceInitFunc) granite_tool_box_gtk_accessible_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType granite_tool_box_type_id;
	granite_tool_box_type_id = g_type_register_static (gtk_widget_get_type (), "GraniteToolBox", &g_define_type_info, 0);
	g_type_add_interface_static (granite_tool_box_type_id, gtk_accessible_get_type (), &gtk_accessible_info);
	GraniteToolBox_private_offset = g_type_add_instance_private (granite_tool_box_type_id, sizeof (GraniteToolBoxPrivate));
	return granite_tool_box_type_id;
}

GType
granite_tool_box_get_type (void)
{
	static volatile gsize granite_tool_box_type_id__once = 0;
	if (g_once_init_enter (&granite_tool_box_type_id__once)) {
		GType granite_tool_box_type_id;
		granite_tool_box_type_id = granite_tool_box_get_type_once ();
		g_once_init_leave (&granite_tool_box_type_id__once, granite_tool_box_type_id);
	}
	return granite_tool_box_type_id__once;
}

static void
_vala_granite_tool_box_get_property (GObject * object,
                                     guint property_id,
                                     GValue * value,
                                     GParamSpec * pspec)
{
	GraniteToolBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GRANITE_TYPE_TOOL_BOX, GraniteToolBox);
	switch (property_id) {
		case GRANITE_TOOL_BOX_CONTENT_PROPERTY:
		g_value_set_object (value, granite_tool_box_get_content (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_granite_tool_box_set_property (GObject * object,
                                     guint property_id,
                                     const GValue * value,
                                     GParamSpec * pspec)
{
	GraniteToolBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GRANITE_TYPE_TOOL_BOX, GraniteToolBox);
	switch (property_id) {
		case GRANITE_TOOL_BOX_CONTENT_PROPERTY:
		granite_tool_box_set_content (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

