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

/*
 * Copyright 2026 elementary, Inc. (https://elementary.io)
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Authored by: Leonhard Kargl <leo.kargl@proton.me>
 */

#include <granite-7.h>
#include <glib-object.h>
#include <ibus.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <float.h>
#include <math.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 GALA_DAEMON_TYPE_CANDIDATE_BOX (gala_daemon_candidate_box_get_type ())
#define GALA_DAEMON_CANDIDATE_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_DAEMON_TYPE_CANDIDATE_BOX, GalaDaemonCandidateBox))
#define GALA_DAEMON_CANDIDATE_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_DAEMON_TYPE_CANDIDATE_BOX, GalaDaemonCandidateBoxClass))
#define GALA_DAEMON_IS_CANDIDATE_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_DAEMON_TYPE_CANDIDATE_BOX))
#define GALA_DAEMON_IS_CANDIDATE_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_DAEMON_TYPE_CANDIDATE_BOX))
#define GALA_DAEMON_CANDIDATE_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_DAEMON_TYPE_CANDIDATE_BOX, GalaDaemonCandidateBoxClass))

typedef struct _GalaDaemonCandidateBox GalaDaemonCandidateBox;
typedef struct _GalaDaemonCandidateBoxClass GalaDaemonCandidateBoxClass;
typedef struct _GalaDaemonCandidateBoxPrivate GalaDaemonCandidateBoxPrivate;
enum  {
	GALA_DAEMON_CANDIDATE_BOX_0_PROPERTY,
	GALA_DAEMON_CANDIDATE_BOX_SERVICE_PROPERTY,
	GALA_DAEMON_CANDIDATE_BOX_LIST_ITEM_PROPERTY,
	GALA_DAEMON_CANDIDATE_BOX_NUM_PROPERTIES
};
static GParamSpec* gala_daemon_candidate_box_properties[GALA_DAEMON_CANDIDATE_BOX_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define GALA_DAEMON_TYPE_CANDIDATE (gala_daemon_candidate_get_type ())
#define GALA_DAEMON_CANDIDATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_DAEMON_TYPE_CANDIDATE, GalaDaemonCandidate))
#define GALA_DAEMON_CANDIDATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_DAEMON_TYPE_CANDIDATE, GalaDaemonCandidateClass))
#define GALA_DAEMON_IS_CANDIDATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_DAEMON_TYPE_CANDIDATE))
#define GALA_DAEMON_IS_CANDIDATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_DAEMON_TYPE_CANDIDATE))
#define GALA_DAEMON_CANDIDATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_DAEMON_TYPE_CANDIDATE, GalaDaemonCandidateClass))

typedef struct _GalaDaemonCandidate GalaDaemonCandidate;
typedef struct _GalaDaemonCandidateClass GalaDaemonCandidateClass;

struct _GalaDaemonCandidateBox {
	GraniteBin parent_instance;
	GalaDaemonCandidateBoxPrivate * priv;
};

struct _GalaDaemonCandidateBoxClass {
	GraniteBinClass parent_class;
};

struct _GalaDaemonCandidateBoxPrivate {
	IBusPanelService* _service;
	GtkListItem* _list_item;
	GtkLabel* label_label;
	GtkLabel* candidate_label;
};

static gint GalaDaemonCandidateBox_private_offset;
static gpointer gala_daemon_candidate_box_parent_class = NULL;

VALA_EXTERN GType gala_daemon_candidate_box_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaDaemonCandidateBox, g_object_unref)
VALA_EXTERN GalaDaemonCandidateBox* gala_daemon_candidate_box_new (IBusPanelService* service,
                                                       GtkListItem* list_item);
VALA_EXTERN GalaDaemonCandidateBox* gala_daemon_candidate_box_construct (GType object_type,
                                                             IBusPanelService* service,
                                                             GtkListItem* list_item);
static void gala_daemon_candidate_box_on_clicked (GalaDaemonCandidateBox* self,
                                           GtkGestureClick* gesture,
                                           gint n_press,
                                           gdouble x,
                                           gdouble y);
VALA_EXTERN IBusPanelService* gala_daemon_candidate_box_get_service (GalaDaemonCandidateBox* self);
VALA_EXTERN GtkListItem* gala_daemon_candidate_box_get_list_item (GalaDaemonCandidateBox* self);
VALA_EXTERN GType gala_daemon_candidate_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaDaemonCandidate, g_object_unref)
VALA_EXTERN void gala_daemon_candidate_box_set_candidate (GalaDaemonCandidateBox* self,
                                              GalaDaemonCandidate* candidate);
VALA_EXTERN const gchar* gala_daemon_candidate_get_label (GalaDaemonCandidate* self);
VALA_EXTERN const gchar* gala_daemon_candidate_get_candidate (GalaDaemonCandidate* self);
static void gala_daemon_candidate_box_set_service (GalaDaemonCandidateBox* self,
                                            IBusPanelService* value);
static void gala_daemon_candidate_box_set_list_item (GalaDaemonCandidateBox* self,
                                              GtkListItem* value);
static GObject * gala_daemon_candidate_box_constructor (GType type,
                                                 guint n_construct_properties,
                                                 GObjectConstructParam * construct_properties);
static void _gala_daemon_candidate_box_on_clicked_gtk_gesture_click_released (GtkGestureClick* _sender,
                                                                       gint n_press,
                                                                       gdouble x,
                                                                       gdouble y,
                                                                       gpointer self);
static void gala_daemon_candidate_box_finalize (GObject * obj);
static GType gala_daemon_candidate_box_get_type_once (void);
static void _vala_gala_daemon_candidate_box_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);
static void _vala_gala_daemon_candidate_box_set_property (GObject * object,
                                                   guint property_id,
                                                   const GValue * value,
                                                   GParamSpec * pspec);

static inline gpointer
gala_daemon_candidate_box_get_instance_private (GalaDaemonCandidateBox* self)
{
	return G_STRUCT_MEMBER_P (self, GalaDaemonCandidateBox_private_offset);
}

GalaDaemonCandidateBox*
gala_daemon_candidate_box_construct (GType object_type,
                                     IBusPanelService* service,
                                     GtkListItem* list_item)
{
	GalaDaemonCandidateBox * self = NULL;
	g_return_val_if_fail (service != NULL, NULL);
	g_return_val_if_fail (list_item != NULL, NULL);
	self = (GalaDaemonCandidateBox*) g_object_new (object_type, "service", service, "list-item", list_item, NULL);
	return self;
}

GalaDaemonCandidateBox*
gala_daemon_candidate_box_new (IBusPanelService* service,
                               GtkListItem* list_item)
{
	return gala_daemon_candidate_box_construct (GALA_DAEMON_TYPE_CANDIDATE_BOX, service, list_item);
}

static void
gala_daemon_candidate_box_on_clicked (GalaDaemonCandidateBox* self,
                                      GtkGestureClick* gesture,
                                      gint n_press,
                                      gdouble x,
                                      gdouble y)
{
	IBusPanelService* _tmp0_;
	GtkListItem* _tmp1_;
	guint _tmp2_;
	guint _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (gesture != NULL);
	_tmp0_ = self->priv->_service;
	_tmp1_ = self->priv->_list_item;
	_tmp2_ = gtk_list_item_get_position (_tmp1_);
	_tmp3_ = _tmp2_;
	ibus_panel_service_candidate_clicked (_tmp0_, _tmp3_, gtk_gesture_single_get_current_button ((GtkGestureSingle*) gesture), (guint) gtk_event_controller_get_current_event_state ((GtkEventController*) gesture));
}

void
gala_daemon_candidate_box_set_candidate (GalaDaemonCandidateBox* self,
                                         GalaDaemonCandidate* candidate)
{
	GtkLabel* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	GtkLabel* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (candidate != NULL);
	_tmp0_ = self->priv->label_label;
	_tmp1_ = gala_daemon_candidate_get_label (candidate);
	_tmp2_ = _tmp1_;
	gtk_label_set_label (_tmp0_, _tmp2_);
	_tmp3_ = self->priv->candidate_label;
	_tmp4_ = gala_daemon_candidate_get_candidate (candidate);
	_tmp5_ = _tmp4_;
	gtk_label_set_label (_tmp3_, _tmp5_);
}

IBusPanelService*
gala_daemon_candidate_box_get_service (GalaDaemonCandidateBox* self)
{
	IBusPanelService* result;
	IBusPanelService* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_service;
	result = _tmp0_;
	return result;
}

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

static void
gala_daemon_candidate_box_set_service (GalaDaemonCandidateBox* self,
                                       IBusPanelService* value)
{
	IBusPanelService* old_value;
	g_return_if_fail (self != NULL);
	old_value = gala_daemon_candidate_box_get_service (self);
	if (old_value != value) {
		IBusPanelService* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_service);
		self->priv->_service = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, gala_daemon_candidate_box_properties[GALA_DAEMON_CANDIDATE_BOX_SERVICE_PROPERTY]);
	}
}

GtkListItem*
gala_daemon_candidate_box_get_list_item (GalaDaemonCandidateBox* self)
{
	GtkListItem* result;
	GtkListItem* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_list_item;
	result = _tmp0_;
	return result;
}

static void
gala_daemon_candidate_box_set_list_item (GalaDaemonCandidateBox* self,
                                         GtkListItem* value)
{
	GtkListItem* old_value;
	g_return_if_fail (self != NULL);
	old_value = gala_daemon_candidate_box_get_list_item (self);
	if (old_value != value) {
		self->priv->_list_item = value;
		g_object_notify_by_pspec ((GObject *) self, gala_daemon_candidate_box_properties[GALA_DAEMON_CANDIDATE_BOX_LIST_ITEM_PROPERTY]);
	}
}

static void
_gala_daemon_candidate_box_on_clicked_gtk_gesture_click_released (GtkGestureClick* _sender,
                                                                  gint n_press,
                                                                  gdouble x,
                                                                  gdouble y,
                                                                  gpointer self)
{
	gala_daemon_candidate_box_on_clicked ((GalaDaemonCandidateBox*) self, _sender, n_press, x, y);
}

static GObject *
gala_daemon_candidate_box_constructor (GType type,
                                       guint n_construct_properties,
                                       GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GalaDaemonCandidateBox * self;
	GtkLabel* _tmp0_;
	GtkLabel* _tmp1_;
	GtkLabel* _tmp2_;
	GraniteBox* content_box = NULL;
	GraniteBox* _tmp3_;
	GraniteBox* _tmp4_;
	GtkLabel* _tmp5_;
	GraniteBox* _tmp6_;
	GtkLabel* _tmp7_;
	GraniteBox* _tmp8_;
	GtkGestureClick* gesture_click = NULL;
	GtkGestureClick* _tmp9_;
	GtkGestureClick* _tmp10_;
	GtkGestureClick* _tmp11_;
	GtkEventController* _tmp12_;
	parent_class = G_OBJECT_CLASS (gala_daemon_candidate_box_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_DAEMON_TYPE_CANDIDATE_BOX, GalaDaemonCandidateBox);
	_tmp0_ = (GtkLabel*) gtk_label_new (NULL);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->label_label);
	self->priv->label_label = _tmp0_;
	_tmp1_ = self->priv->label_label;
	gtk_widget_add_css_class ((GtkWidget*) _tmp1_, GRANITE_CSS_CLASS_DIM);
	_tmp2_ = (GtkLabel*) gtk_label_new (NULL);
	g_object_ref_sink (_tmp2_);
	_g_object_unref0 (self->priv->candidate_label);
	self->priv->candidate_label = _tmp2_;
	_tmp3_ = granite_box_new (GTK_ORIENTATION_HORIZONTAL, GRANITE_BOX_SPACING_HALF);
	g_object_ref_sink (_tmp3_);
	content_box = _tmp3_;
	_tmp4_ = content_box;
	_tmp5_ = self->priv->label_label;
	gtk_box_append ((GtkBox*) _tmp4_, (GtkWidget*) _tmp5_);
	_tmp6_ = content_box;
	_tmp7_ = self->priv->candidate_label;
	gtk_box_append ((GtkBox*) _tmp6_, (GtkWidget*) _tmp7_);
	_tmp8_ = content_box;
	granite_bin_set_child ((GraniteBin*) self, (GtkWidget*) _tmp8_);
	_tmp9_ = (GtkGestureClick*) gtk_gesture_click_new ();
	gesture_click = _tmp9_;
	_tmp10_ = gesture_click;
	g_signal_connect_object (_tmp10_, "released", (GCallback) _gala_daemon_candidate_box_on_clicked_gtk_gesture_click_released, self, 0);
	_tmp11_ = gesture_click;
	_tmp12_ = _g_object_ref0 ((GtkEventController*) _tmp11_);
	gtk_widget_add_controller ((GtkWidget*) self, _tmp12_);
	_g_object_unref0 (gesture_click);
	_g_object_unref0 (content_box);
	return obj;
}

static void
gala_daemon_candidate_box_class_init (GalaDaemonCandidateBoxClass * klass,
                                      gpointer klass_data)
{
	gala_daemon_candidate_box_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GalaDaemonCandidateBox_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_gala_daemon_candidate_box_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gala_daemon_candidate_box_set_property;
	G_OBJECT_CLASS (klass)->constructor = gala_daemon_candidate_box_constructor;
	G_OBJECT_CLASS (klass)->finalize = gala_daemon_candidate_box_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_DAEMON_CANDIDATE_BOX_SERVICE_PROPERTY, gala_daemon_candidate_box_properties[GALA_DAEMON_CANDIDATE_BOX_SERVICE_PROPERTY] = g_param_spec_object ("service", "service", "service", ibus_panel_service_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_DAEMON_CANDIDATE_BOX_LIST_ITEM_PROPERTY, gala_daemon_candidate_box_properties[GALA_DAEMON_CANDIDATE_BOX_LIST_ITEM_PROPERTY] = g_param_spec_object ("list-item", "list-item", "list-item", gtk_list_item_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}

static void
gala_daemon_candidate_box_instance_init (GalaDaemonCandidateBox * self,
                                         gpointer klass)
{
	self->priv = gala_daemon_candidate_box_get_instance_private (self);
}

static void
gala_daemon_candidate_box_finalize (GObject * obj)
{
	GalaDaemonCandidateBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_DAEMON_TYPE_CANDIDATE_BOX, GalaDaemonCandidateBox);
	_g_object_unref0 (self->priv->_service);
	_g_object_unref0 (self->priv->label_label);
	_g_object_unref0 (self->priv->candidate_label);
	G_OBJECT_CLASS (gala_daemon_candidate_box_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gala_daemon_candidate_box_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaDaemonCandidateBoxClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_daemon_candidate_box_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaDaemonCandidateBox), 0, (GInstanceInitFunc) gala_daemon_candidate_box_instance_init, NULL };
	GType gala_daemon_candidate_box_type_id;
	gala_daemon_candidate_box_type_id = g_type_register_static (GRANITE_TYPE_BIN, "GalaDaemonCandidateBox", &g_define_type_info, G_TYPE_FLAG_NONE);
	GalaDaemonCandidateBox_private_offset = g_type_add_instance_private (gala_daemon_candidate_box_type_id, sizeof (GalaDaemonCandidateBoxPrivate));
	return gala_daemon_candidate_box_type_id;
}

GType
gala_daemon_candidate_box_get_type (void)
{
	static gsize gala_daemon_candidate_box_type_id__once = 0;
	if (g_once_init_enter (&gala_daemon_candidate_box_type_id__once)) {
		GType gala_daemon_candidate_box_type_id;
		gala_daemon_candidate_box_type_id = gala_daemon_candidate_box_get_type_once ();
		g_once_init_leave (&gala_daemon_candidate_box_type_id__once, gala_daemon_candidate_box_type_id);
	}
	return gala_daemon_candidate_box_type_id__once;
}

static void
_vala_gala_daemon_candidate_box_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	GalaDaemonCandidateBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_DAEMON_TYPE_CANDIDATE_BOX, GalaDaemonCandidateBox);
	switch (property_id) {
		case GALA_DAEMON_CANDIDATE_BOX_SERVICE_PROPERTY:
		g_value_set_object (value, gala_daemon_candidate_box_get_service (self));
		break;
		case GALA_DAEMON_CANDIDATE_BOX_LIST_ITEM_PROPERTY:
		g_value_set_object (value, gala_daemon_candidate_box_get_list_item (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gala_daemon_candidate_box_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec)
{
	GalaDaemonCandidateBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_DAEMON_TYPE_CANDIDATE_BOX, GalaDaemonCandidateBox);
	switch (property_id) {
		case GALA_DAEMON_CANDIDATE_BOX_SERVICE_PROPERTY:
		gala_daemon_candidate_box_set_service (self, g_value_get_object (value));
		break;
		case GALA_DAEMON_CANDIDATE_BOX_LIST_ITEM_PROPERTY:
		gala_daemon_candidate_box_set_list_item (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

