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

/*
 * This file is part of budgie-desktop
 *
 * Copyright Budgie Desktop Developers
 *
 * 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.
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <cairo-gobject.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 BUDGIE_TYPE_CONSTRAINED_BOX (budgie_constrained_box_get_type ())
#define BUDGIE_CONSTRAINED_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BUDGIE_TYPE_CONSTRAINED_BOX, BudgieConstrainedBox))
#define BUDGIE_CONSTRAINED_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BUDGIE_TYPE_CONSTRAINED_BOX, BudgieConstrainedBoxClass))
#define BUDGIE_IS_CONSTRAINED_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BUDGIE_TYPE_CONSTRAINED_BOX))
#define BUDGIE_IS_CONSTRAINED_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BUDGIE_TYPE_CONSTRAINED_BOX))
#define BUDGIE_CONSTRAINED_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BUDGIE_TYPE_CONSTRAINED_BOX, BudgieConstrainedBoxClass))

typedef struct _BudgieConstrainedBox BudgieConstrainedBox;
typedef struct _BudgieConstrainedBoxClass BudgieConstrainedBoxClass;
typedef struct _BudgieConstrainedBoxPrivate BudgieConstrainedBoxPrivate;
enum  {
	BUDGIE_CONSTRAINED_BOX_0_PROPERTY,
	BUDGIE_CONSTRAINED_BOX_NUM_PROPERTIES
};
static GParamSpec* budgie_constrained_box_properties[BUDGIE_CONSTRAINED_BOX_NUM_PROPERTIES];

#define BUDGIE_TYPE_MAIN_PANEL (budgie_main_panel_get_type ())
#define BUDGIE_MAIN_PANEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BUDGIE_TYPE_MAIN_PANEL, BudgieMainPanel))
#define BUDGIE_MAIN_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BUDGIE_TYPE_MAIN_PANEL, BudgieMainPanelClass))
#define BUDGIE_IS_MAIN_PANEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BUDGIE_TYPE_MAIN_PANEL))
#define BUDGIE_IS_MAIN_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BUDGIE_TYPE_MAIN_PANEL))
#define BUDGIE_MAIN_PANEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BUDGIE_TYPE_MAIN_PANEL, BudgieMainPanelClass))

typedef struct _BudgieMainPanel BudgieMainPanel;
typedef struct _BudgieMainPanelClass BudgieMainPanelClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _BudgieConstrainedBox {
	GtkBox parent_instance;
	BudgieConstrainedBoxPrivate * priv;
};

struct _BudgieConstrainedBoxClass {
	GtkBoxClass parent_class;
};

struct _BudgieConstrainedBoxPrivate {
	gboolean calculating_preferred_width;
	gboolean calculating_preferred_height;
};

static gint BudgieConstrainedBox_private_offset;
static gpointer budgie_constrained_box_parent_class = NULL;

VALA_EXTERN GType budgie_constrained_box_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BudgieConstrainedBox, g_object_unref)
VALA_EXTERN BudgieConstrainedBox* budgie_constrained_box_new (GtkOrientation orientation,
                                                  gint spacing);
VALA_EXTERN BudgieConstrainedBox* budgie_constrained_box_construct (GType object_type,
                                                        GtkOrientation orientation,
                                                        gint spacing);
static void budgie_constrained_box_real_get_preferred_width (GtkWidget* base,
                                                      gint* minimum_width,
                                                      gint* natural_width);
static void budgie_constrained_box_real_get_preferred_height (GtkWidget* base,
                                                       gint* minimum_height,
                                                       gint* natural_height);
static void budgie_constrained_box_real_size_allocate (GtkWidget* base,
                                                GtkAllocation* allocation);
VALA_EXTERN GType budgie_main_panel_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BudgieMainPanel, g_object_unref)
static void budgie_constrained_box_finalize (GObject * obj);
static GType budgie_constrained_box_get_type_once (void);

static inline gpointer
budgie_constrained_box_get_instance_private (BudgieConstrainedBox* self)
{
	return G_STRUCT_MEMBER_P (self, BudgieConstrainedBox_private_offset);
}

BudgieConstrainedBox*
budgie_constrained_box_construct (GType object_type,
                                  GtkOrientation orientation,
                                  gint spacing)
{
	BudgieConstrainedBox * self = NULL;
	self = (BudgieConstrainedBox*) g_object_new (object_type, "orientation", orientation, "spacing", spacing, NULL);
	gtk_widget_set_hexpand ((GtkWidget*) self, FALSE);
	gtk_widget_set_vexpand ((GtkWidget*) self, FALSE);
	return self;
}

BudgieConstrainedBox*
budgie_constrained_box_new (GtkOrientation orientation,
                            gint spacing)
{
	return budgie_constrained_box_construct (BUDGIE_TYPE_CONSTRAINED_BOX, orientation, spacing);
}

static void
budgie_constrained_box_real_get_preferred_width (GtkWidget* base,
                                                 gint* minimum_width,
                                                 gint* natural_width)
{
	BudgieConstrainedBox * self;
	gint _vala_minimum_width = 0;
	gint _vala_natural_width = 0;
	gint _tmp2_ = 0;
	gint _tmp3_ = 0;
	static const gint MAX_REASONABLE_WIDTH = 10000;
	self = (BudgieConstrainedBox*) base;
	if (self->priv->calculating_preferred_width) {
		gint _tmp0_ = 0;
		gint _tmp1_ = 0;
		GTK_WIDGET_CLASS (budgie_constrained_box_parent_class)->get_preferred_width ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_box_get_type (), GtkBox), &_tmp0_, &_tmp1_);
		_vala_minimum_width = _tmp0_;
		_vala_natural_width = _tmp1_;
		if (_vala_natural_width < 0) {
			_vala_natural_width = 0;
		}
		if (_vala_minimum_width < 0) {
			_vala_minimum_width = 0;
		}
		if (minimum_width) {
			*minimum_width = _vala_minimum_width;
		}
		if (natural_width) {
			*natural_width = _vala_natural_width;
		}
		return;
	}
	self->priv->calculating_preferred_width = TRUE;
	GTK_WIDGET_CLASS (budgie_constrained_box_parent_class)->get_preferred_width ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_box_get_type (), GtkBox), &_tmp2_, &_tmp3_);
	_vala_minimum_width = _tmp2_;
	_vala_natural_width = _tmp3_;
	self->priv->calculating_preferred_width = FALSE;
	if (_vala_natural_width < 0) {
		_vala_natural_width = 0;
	}
	if (_vala_minimum_width < 0) {
		_vala_minimum_width = 0;
	}
	if (_vala_natural_width > MAX_REASONABLE_WIDTH) {
		_vala_natural_width = MAX_REASONABLE_WIDTH;
	}
	if (_vala_minimum_width > MAX_REASONABLE_WIDTH) {
		_vala_minimum_width = MAX_REASONABLE_WIDTH;
	}
	if (minimum_width) {
		*minimum_width = _vala_minimum_width;
	}
	if (natural_width) {
		*natural_width = _vala_natural_width;
	}
}

static void
budgie_constrained_box_real_get_preferred_height (GtkWidget* base,
                                                  gint* minimum_height,
                                                  gint* natural_height)
{
	BudgieConstrainedBox * self;
	gint _vala_minimum_height = 0;
	gint _vala_natural_height = 0;
	gint _tmp2_ = 0;
	gint _tmp3_ = 0;
	static const gint MAX_REASONABLE_HEIGHT = 10000;
	self = (BudgieConstrainedBox*) base;
	if (self->priv->calculating_preferred_height) {
		gint _tmp0_ = 0;
		gint _tmp1_ = 0;
		GTK_WIDGET_CLASS (budgie_constrained_box_parent_class)->get_preferred_height ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_box_get_type (), GtkBox), &_tmp0_, &_tmp1_);
		_vala_minimum_height = _tmp0_;
		_vala_natural_height = _tmp1_;
		if (_vala_natural_height < 0) {
			_vala_natural_height = 0;
		}
		if (_vala_minimum_height < 0) {
			_vala_minimum_height = 0;
		}
		if (minimum_height) {
			*minimum_height = _vala_minimum_height;
		}
		if (natural_height) {
			*natural_height = _vala_natural_height;
		}
		return;
	}
	self->priv->calculating_preferred_height = TRUE;
	GTK_WIDGET_CLASS (budgie_constrained_box_parent_class)->get_preferred_height ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_box_get_type (), GtkBox), &_tmp2_, &_tmp3_);
	_vala_minimum_height = _tmp2_;
	_vala_natural_height = _tmp3_;
	self->priv->calculating_preferred_height = FALSE;
	if (_vala_natural_height < 0) {
		_vala_natural_height = 0;
	}
	if (_vala_minimum_height < 0) {
		_vala_minimum_height = 0;
	}
	if (_vala_natural_height > MAX_REASONABLE_HEIGHT) {
		_vala_natural_height = MAX_REASONABLE_HEIGHT;
	}
	if (_vala_minimum_height > MAX_REASONABLE_HEIGHT) {
		_vala_minimum_height = MAX_REASONABLE_HEIGHT;
	}
	if (minimum_height) {
		*minimum_height = _vala_minimum_height;
	}
	if (natural_height) {
		*natural_height = _vala_natural_height;
	}
}

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

static void
budgie_constrained_box_real_size_allocate (GtkWidget* base,
                                           GtkAllocation* allocation)
{
	BudgieConstrainedBox * self;
	GtkContainer* parent = NULL;
	GtkContainer* _tmp0_;
	GtkContainer* _tmp1_;
	GtkAllocation constrained_alloc = {0};
	GtkAllocation _tmp2_;
	gboolean _tmp3_ = FALSE;
	GtkContainer* _tmp4_;
	GtkAllocation _tmp19_;
	GList* _tmp20_;
	self = (BudgieConstrainedBox*) base;
	g_return_if_fail (allocation != NULL);
	_tmp0_ = gtk_widget_get_parent ((GtkWidget*) self);
	_tmp1_ = _g_object_ref0 (_tmp0_);
	parent = _tmp1_;
	_tmp2_ = *allocation;
	constrained_alloc = _tmp2_;
	_tmp4_ = parent;
	if (_tmp4_ != NULL) {
		GtkContainer* _tmp5_;
		_tmp5_ = parent;
		_tmp3_ = BUDGIE_IS_MAIN_PANEL (_tmp5_);
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		BudgieMainPanel* main_panel = NULL;
		GtkContainer* _tmp6_;
		BudgieMainPanel* _tmp7_;
		GtkAllocation parent_alloc = {0};
		BudgieMainPanel* _tmp8_;
		GtkAllocation _tmp9_ = {0};
		BudgieMainPanel* _tmp10_;
		_tmp6_ = parent;
		_tmp7_ = _g_object_ref0 (BUDGIE_IS_MAIN_PANEL (_tmp6_) ? ((BudgieMainPanel*) _tmp6_) : NULL);
		main_panel = _tmp7_;
		_tmp8_ = main_panel;
		gtk_widget_get_allocation ((GtkWidget*) _tmp8_, &_tmp9_);
		parent_alloc = _tmp9_;
		_tmp10_ = main_panel;
		if (gtk_orientable_get_orientation ((GtkOrientable*) _tmp10_) == GTK_ORIENTATION_HORIZONTAL) {
			gint max_width = 0;
			GtkAllocation _tmp11_;
			gint relative_x = 0;
			GtkAllocation _tmp12_;
			GtkAllocation _tmp13_;
			GtkAllocation _tmp14_;
			_tmp11_ = parent_alloc;
			max_width = _tmp11_.width;
			_tmp12_ = *allocation;
			_tmp13_ = parent_alloc;
			relative_x = _tmp12_.x - _tmp13_.x;
			_tmp14_ = *allocation;
			if ((relative_x + _tmp14_.width) > max_width) {
				constrained_alloc.width = MAX (0, max_width - relative_x);
			}
		} else {
			gint max_height = 0;
			GtkAllocation _tmp15_;
			gint relative_y = 0;
			GtkAllocation _tmp16_;
			GtkAllocation _tmp17_;
			GtkAllocation _tmp18_;
			_tmp15_ = parent_alloc;
			max_height = _tmp15_.height;
			_tmp16_ = *allocation;
			_tmp17_ = parent_alloc;
			relative_y = _tmp16_.y - _tmp17_.y;
			_tmp18_ = *allocation;
			if ((relative_y + _tmp18_.height) > max_height) {
				constrained_alloc.height = MAX (0, max_height - relative_y);
			}
		}
		_g_object_unref0 (main_panel);
	}
	_tmp19_ = constrained_alloc;
	GTK_WIDGET_CLASS (budgie_constrained_box_parent_class)->size_allocate ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_box_get_type (), GtkBox), &_tmp19_);
	_tmp20_ = gtk_container_get_children ((GtkContainer*) self);
	{
		GList* child_collection = NULL;
		GList* child_it = NULL;
		child_collection = _tmp20_;
		for (child_it = child_collection; child_it != NULL; child_it = child_it->next) {
			GtkWidget* child = NULL;
			child = (GtkWidget*) child_it->data;
			{
				GtkAllocation child_alloc = {0};
				GtkWidget* _tmp21_;
				GtkAllocation _tmp22_ = {0};
				gint relative_x = 0;
				GtkAllocation _tmp23_;
				GtkAllocation _tmp24_;
				gint relative_y = 0;
				GtkAllocation _tmp25_;
				GtkAllocation _tmp26_;
				_tmp21_ = child;
				gtk_widget_get_allocation (_tmp21_, &_tmp22_);
				child_alloc = _tmp22_;
				_tmp23_ = child_alloc;
				_tmp24_ = constrained_alloc;
				relative_x = _tmp23_.x - _tmp24_.x;
				_tmp25_ = child_alloc;
				_tmp26_ = constrained_alloc;
				relative_y = _tmp25_.y - _tmp26_.y;
				if (gtk_orientable_get_orientation ((GtkOrientable*) self) == GTK_ORIENTATION_HORIZONTAL) {
					GtkAllocation _tmp27_;
					GtkAllocation _tmp28_;
					_tmp27_ = child_alloc;
					_tmp28_ = constrained_alloc;
					if ((relative_x + _tmp27_.width) > _tmp28_.width) {
						GtkAllocation _tmp29_;
						GtkWidget* _tmp30_;
						GtkAllocation _tmp31_;
						_tmp29_ = constrained_alloc;
						child_alloc.width = MAX (0, _tmp29_.width - relative_x);
						_tmp30_ = child;
						_tmp31_ = child_alloc;
						gtk_widget_size_allocate (_tmp30_, &_tmp31_);
					}
				} else {
					GtkAllocation _tmp32_;
					GtkAllocation _tmp33_;
					_tmp32_ = child_alloc;
					_tmp33_ = constrained_alloc;
					if ((relative_y + _tmp32_.height) > _tmp33_.height) {
						GtkAllocation _tmp34_;
						GtkWidget* _tmp35_;
						GtkAllocation _tmp36_;
						_tmp34_ = constrained_alloc;
						child_alloc.height = MAX (0, _tmp34_.height - relative_y);
						_tmp35_ = child;
						_tmp36_ = child_alloc;
						gtk_widget_size_allocate (_tmp35_, &_tmp36_);
					}
				}
			}
		}
		(child_collection == NULL) ? NULL : (child_collection = (g_list_free (child_collection), NULL));
	}
	_g_object_unref0 (parent);
}

static void
budgie_constrained_box_class_init (BudgieConstrainedBoxClass * klass,
                                   gpointer klass_data)
{
	budgie_constrained_box_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BudgieConstrainedBox_private_offset);
	((GtkWidgetClass *) klass)->get_preferred_width = (void (*) (GtkWidget*, gint*, gint*)) budgie_constrained_box_real_get_preferred_width;
	((GtkWidgetClass *) klass)->get_preferred_height = (void (*) (GtkWidget*, gint*, gint*)) budgie_constrained_box_real_get_preferred_height;
	((GtkWidgetClass *) klass)->size_allocate = (void (*) (GtkWidget*, GtkAllocation*)) budgie_constrained_box_real_size_allocate;
	G_OBJECT_CLASS (klass)->finalize = budgie_constrained_box_finalize;
}

static void
budgie_constrained_box_instance_init (BudgieConstrainedBox * self,
                                      gpointer klass)
{
	self->priv = budgie_constrained_box_get_instance_private (self);
	self->priv->calculating_preferred_width = FALSE;
	self->priv->calculating_preferred_height = FALSE;
}

static void
budgie_constrained_box_finalize (GObject * obj)
{
	BudgieConstrainedBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BUDGIE_TYPE_CONSTRAINED_BOX, BudgieConstrainedBox);
	G_OBJECT_CLASS (budgie_constrained_box_parent_class)->finalize (obj);
}

/**
 * A Box that constrains its preferred size and children to prevent overflow
 */
static GType
budgie_constrained_box_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BudgieConstrainedBoxClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) budgie_constrained_box_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BudgieConstrainedBox), 0, (GInstanceInitFunc) budgie_constrained_box_instance_init, NULL };
	GType budgie_constrained_box_type_id;
	budgie_constrained_box_type_id = g_type_register_static (gtk_box_get_type (), "BudgieConstrainedBox", &g_define_type_info, 0);
	BudgieConstrainedBox_private_offset = g_type_add_instance_private (budgie_constrained_box_type_id, sizeof (BudgieConstrainedBoxPrivate));
	return budgie_constrained_box_type_id;
}

GType
budgie_constrained_box_get_type (void)
{
	static volatile gsize budgie_constrained_box_type_id__once = 0;
	if (g_once_init_enter (&budgie_constrained_box_type_id__once)) {
		GType budgie_constrained_box_type_id;
		budgie_constrained_box_type_id = budgie_constrained_box_get_type_once ();
		g_once_init_leave (&budgie_constrained_box_type_id__once, budgie_constrained_box_type_id);
	}
	return budgie_constrained_box_type_id__once;
}

