/* controller-choice-box.c generated by valac 0.56.19, the Vala compiler
 * generated from controller-choice-box.vala, do not modify */

#include "protonplus_core.h"
#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib.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  {
	PROTON_PLUS_WIDGETS_CONTROLLER_CHOICE_BOX_0_PROPERTY,
	PROTON_PLUS_WIDGETS_CONTROLLER_CHOICE_BOX_NUM_PROPERTIES
};
static GParamSpec* proton_plus_widgets_controller_choice_box_properties[PROTON_PLUS_WIDGETS_CONTROLLER_CHOICE_BOX_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

static gpointer proton_plus_widgets_controller_choice_box_parent_class = NULL;
static ProtonPlusUtilsControllerDirectionalFocusIface * proton_plus_widgets_controller_choice_box_proton_plus_utils_controller_directional_focus_parent_iface = NULL;

static gboolean proton_plus_widgets_controller_choice_box_real_controller_focus_direction (ProtonPlusUtilsControllerDirectionalFocus* base,
                                                                                    GObject* focused_object,
                                                                                    ProtonPlusUtilsControllerNavigationDirection direction);
static GtkWidget* proton_plus_widgets_controller_choice_box_find_option_ancestor (ProtonPlusWidgetsControllerChoiceBox* self,
                                                                           GtkWidget* focused);
static GtkWidget* proton_plus_widgets_controller_choice_box_find_adjacent_option (ProtonPlusWidgetsControllerChoiceBox* self,
                                                                           GtkWidget* option,
                                                                           gboolean forward);
static GType proton_plus_widgets_controller_choice_box_get_type_once (void);

ProtonPlusWidgetsControllerChoiceBox*
proton_plus_widgets_controller_choice_box_construct (GType object_type)
{
	ProtonPlusWidgetsControllerChoiceBox * self = NULL;
	self = (ProtonPlusWidgetsControllerChoiceBox*) g_object_new (object_type, "orientation", GTK_ORIENTATION_VERTICAL, "spacing", 12, NULL);
	return self;
}

ProtonPlusWidgetsControllerChoiceBox*
proton_plus_widgets_controller_choice_box_new (void)
{
	return proton_plus_widgets_controller_choice_box_construct (PROTON_PLUS_WIDGETS_TYPE_CONTROLLER_CHOICE_BOX);
}

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

static gboolean
proton_plus_widgets_controller_choice_box_real_controller_focus_direction (ProtonPlusUtilsControllerDirectionalFocus* base,
                                                                           GObject* focused_object,
                                                                           ProtonPlusUtilsControllerNavigationDirection direction)
{
	ProtonPlusWidgetsControllerChoiceBox * self;
	GtkWidget* focused = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* option = NULL;
	GtkWidget* _tmp1_;
	GtkWidget* _tmp2_;
	GtkWidget* _tmp3_;
	gboolean _tmp4_ = FALSE;
	gboolean _tmp9_ = FALSE;
	gboolean result;
	self = (ProtonPlusWidgetsControllerChoiceBox*) base;
	g_return_val_if_fail (focused_object != NULL, FALSE);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (focused_object, gtk_widget_get_type ()) ? ((GtkWidget*) focused_object) : NULL);
	focused = _tmp0_;
	_tmp1_ = focused;
	_tmp2_ = proton_plus_widgets_controller_choice_box_find_option_ancestor (self, _tmp1_);
	option = _tmp2_;
	_tmp3_ = option;
	if (_tmp3_ == NULL) {
		result = FALSE;
		_g_object_unref0 (option);
		_g_object_unref0 (focused);
		return result;
	}
	if (direction == PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_DIRECTION_UP) {
		_tmp4_ = TRUE;
	} else {
		_tmp4_ = direction == PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_DIRECTION_DOWN;
	}
	if (_tmp4_) {
		GtkWidget* adjacent = NULL;
		GtkWidget* _tmp5_;
		GtkWidget* _tmp6_;
		GtkWidget* _tmp7_;
		_tmp5_ = option;
		_tmp6_ = proton_plus_widgets_controller_choice_box_find_adjacent_option (self, G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, gtk_widget_get_type (), GtkWidget), direction == PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_DIRECTION_DOWN);
		adjacent = _tmp6_;
		_tmp7_ = adjacent;
		if (_tmp7_ != NULL) {
			GtkWidget* _tmp8_;
			_tmp8_ = adjacent;
			gtk_widget_grab_focus (G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, gtk_widget_get_type (), GtkWidget));
		}
		result = TRUE;
		_g_object_unref0 (adjacent);
		_g_object_unref0 (option);
		_g_object_unref0 (focused);
		return result;
	}
	if (direction == PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_DIRECTION_LEFT) {
		_tmp9_ = TRUE;
	} else {
		_tmp9_ = direction == PROTON_PLUS_UTILS_CONTROLLER_NAVIGATION_DIRECTION_RIGHT;
	}
	if (_tmp9_) {
		result = TRUE;
		_g_object_unref0 (option);
		_g_object_unref0 (focused);
		return result;
	}
	result = FALSE;
	_g_object_unref0 (option);
	_g_object_unref0 (focused);
	return result;
}

static GtkWidget*
proton_plus_widgets_controller_choice_box_find_option_ancestor (ProtonPlusWidgetsControllerChoiceBox* self,
                                                                GtkWidget* focused)
{
	GtkWidget* current = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = _g_object_ref0 (focused);
	current = _tmp0_;
	while (TRUE) {
		gboolean _tmp1_ = FALSE;
		GtkWidget* _tmp2_;
		GtkWidget* _tmp4_;
		GtkWidget* _tmp5_;
		GtkWidget* _tmp6_;
		GtkWidget* _tmp7_;
		GtkWidget* _tmp8_;
		_tmp2_ = current;
		if (_tmp2_ != NULL) {
			GtkWidget* _tmp3_;
			_tmp3_ = current;
			_tmp1_ = _tmp3_ != G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget);
		} else {
			_tmp1_ = FALSE;
		}
		if (!_tmp1_) {
			break;
		}
		_tmp4_ = current;
		_tmp5_ = gtk_widget_get_parent (_tmp4_);
		if (_tmp5_ == G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget)) {
			result = current;
			return result;
		}
		_tmp6_ = current;
		_tmp7_ = gtk_widget_get_parent (_tmp6_);
		_tmp8_ = _g_object_ref0 (_tmp7_);
		_g_object_unref0 (current);
		current = _tmp8_;
	}
	result = NULL;
	_g_object_unref0 (current);
	return result;
}

static GtkWidget*
proton_plus_widgets_controller_choice_box_find_adjacent_option (ProtonPlusWidgetsControllerChoiceBox* self,
                                                                GtkWidget* option,
                                                                gboolean forward)
{
	GtkWidget* _tmp0_ = NULL;
	GtkWidget* sibling = NULL;
	GtkWidget* _tmp3_;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (option != NULL, NULL);
	if (forward) {
		GtkWidget* _tmp1_;
		_tmp1_ = gtk_widget_get_next_sibling (option);
		_tmp0_ = _tmp1_;
	} else {
		GtkWidget* _tmp2_;
		_tmp2_ = gtk_widget_get_prev_sibling (option);
		_tmp0_ = _tmp2_;
	}
	_tmp3_ = _g_object_ref0 (_tmp0_);
	sibling = _tmp3_;
	while (TRUE) {
		GtkWidget* _tmp4_;
		gboolean _tmp5_ = FALSE;
		gboolean _tmp6_ = FALSE;
		gboolean _tmp7_ = FALSE;
		GtkWidget* _tmp8_;
		GtkWidget* _tmp12_ = NULL;
		GtkWidget* _tmp17_;
		_tmp4_ = sibling;
		if (!(_tmp4_ != NULL)) {
			break;
		}
		_tmp8_ = sibling;
		if (gtk_widget_get_mapped (_tmp8_)) {
			GtkWidget* _tmp9_;
			_tmp9_ = sibling;
			_tmp7_ = gtk_widget_is_visible (_tmp9_);
		} else {
			_tmp7_ = FALSE;
		}
		if (_tmp7_) {
			GtkWidget* _tmp10_;
			_tmp10_ = sibling;
			_tmp6_ = gtk_widget_is_sensitive (_tmp10_);
		} else {
			_tmp6_ = FALSE;
		}
		if (_tmp6_) {
			GtkWidget* _tmp11_;
			_tmp11_ = sibling;
			_tmp5_ = gtk_widget_get_focusable (_tmp11_);
		} else {
			_tmp5_ = FALSE;
		}
		if (_tmp5_) {
			result = sibling;
			return result;
		}
		if (forward) {
			GtkWidget* _tmp13_;
			GtkWidget* _tmp14_;
			_tmp13_ = sibling;
			_tmp14_ = gtk_widget_get_next_sibling (_tmp13_);
			_tmp12_ = _tmp14_;
		} else {
			GtkWidget* _tmp15_;
			GtkWidget* _tmp16_;
			_tmp15_ = sibling;
			_tmp16_ = gtk_widget_get_prev_sibling (_tmp15_);
			_tmp12_ = _tmp16_;
		}
		_tmp17_ = _g_object_ref0 (_tmp12_);
		_g_object_unref0 (sibling);
		sibling = _tmp17_;
	}
	result = NULL;
	_g_object_unref0 (sibling);
	return result;
}

static void
proton_plus_widgets_controller_choice_box_class_init (ProtonPlusWidgetsControllerChoiceBoxClass * klass,
                                                      gpointer klass_data)
{
	proton_plus_widgets_controller_choice_box_parent_class = g_type_class_peek_parent (klass);
}

static void
proton_plus_widgets_controller_choice_box_proton_plus_utils_controller_directional_focus_interface_init (ProtonPlusUtilsControllerDirectionalFocusIface * iface,
                                                                                                         gpointer iface_data)
{
	proton_plus_widgets_controller_choice_box_proton_plus_utils_controller_directional_focus_parent_iface = g_type_interface_peek_parent (iface);
	iface->controller_focus_direction = (gboolean (*) (ProtonPlusUtilsControllerDirectionalFocus*, GObject*, ProtonPlusUtilsControllerNavigationDirection)) proton_plus_widgets_controller_choice_box_real_controller_focus_direction;
}

static void
proton_plus_widgets_controller_choice_box_instance_init (ProtonPlusWidgetsControllerChoiceBox * self,
                                                         gpointer klass)
{
}

static GType
proton_plus_widgets_controller_choice_box_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ProtonPlusWidgetsControllerChoiceBoxClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) proton_plus_widgets_controller_choice_box_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ProtonPlusWidgetsControllerChoiceBox), 0, (GInstanceInitFunc) proton_plus_widgets_controller_choice_box_instance_init, NULL };
	static const GInterfaceInfo proton_plus_utils_controller_directional_focus_info = { (GInterfaceInitFunc) proton_plus_widgets_controller_choice_box_proton_plus_utils_controller_directional_focus_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType proton_plus_widgets_controller_choice_box_type_id;
	proton_plus_widgets_controller_choice_box_type_id = g_type_register_static (gtk_box_get_type (), "ProtonPlusWidgetsControllerChoiceBox", &g_define_type_info, 0);
	g_type_add_interface_static (proton_plus_widgets_controller_choice_box_type_id, PROTON_PLUS_UTILS_TYPE_CONTROLLER_DIRECTIONAL_FOCUS, &proton_plus_utils_controller_directional_focus_info);
	return proton_plus_widgets_controller_choice_box_type_id;
}

GType
proton_plus_widgets_controller_choice_box_get_type (void)
{
	static volatile gsize proton_plus_widgets_controller_choice_box_type_id__once = 0;
	if (g_once_init_enter (&proton_plus_widgets_controller_choice_box_type_id__once)) {
		GType proton_plus_widgets_controller_choice_box_type_id;
		proton_plus_widgets_controller_choice_box_type_id = proton_plus_widgets_controller_choice_box_get_type_once ();
		g_once_init_leave (&proton_plus_widgets_controller_choice_box_type_id__once, proton_plus_widgets_controller_choice_box_type_id);
	}
	return proton_plus_widgets_controller_choice_box_type_id__once;
}

