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

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

#include "granite-7.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <float.h>
#include <math.h>
#include <gdk/gdk.h>
#include <cairo-gobject.h>
#include <glib-object.h>

#define GRANITE_LIST_ITEM_TOUCH_TARGET_WIDTH 44
#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_LIST_ITEM_0_PROPERTY,
	GRANITE_LIST_ITEM_TEXT_PROPERTY,
	GRANITE_LIST_ITEM_DESCRIPTION_PROPERTY,
	GRANITE_LIST_ITEM_CHILD_PROPERTY,
	GRANITE_LIST_ITEM_MENU_MODEL_PROPERTY,
	GRANITE_LIST_ITEM_NUM_PROPERTIES
};
static GParamSpec* granite_list_item_properties[GRANITE_LIST_ITEM_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _gdk_event_unref0(var) ((var == NULL) ? NULL : (var = (gdk_event_unref (var), NULL)))
#define __vala_GdkEventSequence_free0(var) ((var == NULL) ? NULL : (var = (_vala_GdkEventSequence_free (var), NULL)))
typedef struct _Block4Data Block4Data;

struct _GraniteListItemPrivate {
	gchar* _text;
	gchar* _description;
	GtkWidget* _child;
	GMenuModel* _menu_model;
	GtkGestureClick* click_controller;
	GtkGestureLongPress* long_press_controller;
	GtkEventControllerKey* menu_key_controller;
	GtkPopoverMenu* context_menu;
};

struct _Block4Data {
	int _ref_count_;
	GraniteListItem* self;
	GtkLabel* description_label;
	GraniteBox* text_box;
};

static gint GraniteListItem_private_offset;
static gpointer granite_list_item_parent_class = NULL;

static void granite_list_item_construct_menu (GraniteListItem* self);
static void granite_list_item_on_click (GraniteListItem* self,
                                 GtkGestureClick* gesture,
                                 gint n_press,
                                 gdouble x,
                                 gdouble y);
static void _granite_list_item_on_click_gtk_gesture_click_pressed (GtkGestureClick* _sender,
                                                            gint n_press,
                                                            gdouble x,
                                                            gdouble y,
                                                            gpointer self);
static void granite_list_item_on_long_press (GraniteListItem* self,
                                      gdouble x,
                                      gdouble y);
static void _granite_list_item_on_long_press_gtk_gesture_long_press_pressed (GtkGestureLongPress* _sender,
                                                                      gdouble x,
                                                                      gdouble y,
                                                                      gpointer self);
static void granite_list_item_on_key_released (GraniteListItem* self,
                                        guint keyval,
                                        guint keycode,
                                        GdkModifierType state);
static void _granite_list_item_on_key_released_gtk_event_controller_key_key_released (GtkEventControllerKey* _sender,
                                                                               guint keyval,
                                                                               guint keycode,
                                                                               GdkModifierType state,
                                                                               gpointer self);
static void granite_list_item_menu_popup_at_pointer (GraniteListItem* self,
                                              GtkPopoverMenu* popover,
                                              gdouble x,
                                              gdouble y);
static void _vala_GdkEventSequence_free (GdkEventSequence* self);
static void granite_list_item_menu_popup_on_keypress (GraniteListItem* self,
                                               GtkPopoverMenu* popover);
static GObject * granite_list_item_constructor (GType type,
                                         guint n_construct_properties,
                                         GObjectConstructParam * construct_properties);
static Block4Data* block4_data_ref (Block4Data* _data4_);
static void block4_data_unref (void * _userdata_);
static void _granite_list_item___lambda18_ (Block4Data* _data4_);
static void __granite_list_item___lambda18__g_object_notify (GObject* _sender,
                                                      GParamSpec* pspec,
                                                      gpointer self);
static void _granite_list_item_construct_menu_g_object_notify (GObject* _sender,
                                                        GParamSpec* pspec,
                                                        gpointer self);
static void granite_list_item_finalize (GObject * obj);
static GType granite_list_item_get_type_once (void);
static void _vala_granite_list_item_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec);
static void _vala_granite_list_item_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec);

static inline gpointer
granite_list_item_get_instance_private (GraniteListItem* self)
{
	return G_STRUCT_MEMBER_P (self, GraniteListItem_private_offset);
}

const gchar*
granite_list_item_get_text (GraniteListItem* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_text;
	result = _tmp0_;
	return result;
}

void
granite_list_item_set_text (GraniteListItem* self,
                            const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = granite_list_item_get_text (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_text);
		self->priv->_text = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, granite_list_item_properties[GRANITE_LIST_ITEM_TEXT_PROPERTY]);
	}
}

const gchar*
granite_list_item_get_description (GraniteListItem* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_description;
	result = _tmp0_;
	return result;
}

void
granite_list_item_set_description (GraniteListItem* self,
                                   const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = granite_list_item_get_description (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_description);
		self->priv->_description = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, granite_list_item_properties[GRANITE_LIST_ITEM_DESCRIPTION_PROPERTY]);
	}
}

GtkWidget*
granite_list_item_get_child (GraniteListItem* self)
{
	GtkWidget* result;
	GtkWidget* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_child;
	result = _tmp0_;
	return result;
}

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

void
granite_list_item_set_child (GraniteListItem* self,
                             GtkWidget* value)
{
	gboolean _tmp0_ = FALSE;
	GtkWidget* _tmp2_;
	GtkWidget* _tmp4_;
	GtkWidget* _tmp5_;
	g_return_if_fail (self != NULL);
	if (value != NULL) {
		GtkWidget* _tmp1_;
		_tmp1_ = gtk_widget_get_parent (value);
		_tmp0_ = _tmp1_ != NULL;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		g_critical ("ListItem.vala:37: Tried to set a widget as child that already has a pa" \
"rent.");
		return;
	}
	_tmp2_ = self->priv->_child;
	if (_tmp2_ != NULL) {
		GtkWidget* _tmp3_;
		_tmp3_ = self->priv->_child;
		gtk_widget_unparent (_tmp3_);
	}
	_tmp4_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_child);
	self->priv->_child = _tmp4_;
	_tmp5_ = self->priv->_child;
	if (_tmp5_ != NULL) {
		GtkWidget* _tmp6_;
		_tmp6_ = self->priv->_child;
		gtk_widget_set_parent (_tmp6_, (GtkWidget*) self);
	}
	g_object_notify_by_pspec ((GObject *) self, granite_list_item_properties[GRANITE_LIST_ITEM_CHILD_PROPERTY]);
}

GMenuModel*
granite_list_item_get_menu_model (GraniteListItem* self)
{
	GMenuModel* result;
	GMenuModel* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_menu_model;
	result = _tmp0_;
	return result;
}

void
granite_list_item_set_menu_model (GraniteListItem* self,
                                  GMenuModel* value)
{
	GMenuModel* old_value;
	g_return_if_fail (self != NULL);
	old_value = granite_list_item_get_menu_model (self);
	if (old_value != value) {
		GMenuModel* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_menu_model);
		self->priv->_menu_model = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, granite_list_item_properties[GRANITE_LIST_ITEM_MENU_MODEL_PROPERTY]);
	}
}

static void
_granite_list_item_on_click_gtk_gesture_click_pressed (GtkGestureClick* _sender,
                                                       gint n_press,
                                                       gdouble x,
                                                       gdouble y,
                                                       gpointer self)
{
	granite_list_item_on_click ((GraniteListItem*) self, _sender, n_press, x, y);
}

static void
_granite_list_item_on_long_press_gtk_gesture_long_press_pressed (GtkGestureLongPress* _sender,
                                                                 gdouble x,
                                                                 gdouble y,
                                                                 gpointer self)
{
	granite_list_item_on_long_press ((GraniteListItem*) self, x, y);
}

static void
_granite_list_item_on_key_released_gtk_event_controller_key_key_released (GtkEventControllerKey* _sender,
                                                                          guint keyval,
                                                                          guint keycode,
                                                                          GdkModifierType state,
                                                                          gpointer self)
{
	granite_list_item_on_key_released ((GraniteListItem*) self, keyval, keycode, state);
}

static void
granite_list_item_construct_menu (GraniteListItem* self)
{
	GMenuModel* _tmp0_;
	GtkPopoverMenu* _tmp6_;
	GMenuModel* _tmp9_;
	GtkPopoverMenu* _tmp10_ = NULL;
	GtkPopoverMenu* _tmp11_;
	GtkGestureClick* _tmp12_ = NULL;
	GtkGestureClick* _tmp13_;
	GtkGestureLongPress* _tmp14_ = NULL;
	GtkGestureLongPress* _tmp15_;
	GtkEventControllerKey* _tmp16_;
	GtkEventControllerKey* _tmp17_;
	GtkGestureClick* _tmp18_;
	GtkEventController* _tmp19_;
	GtkGestureLongPress* _tmp20_;
	GtkEventController* _tmp21_;
	GtkEventControllerKey* _tmp22_;
	GtkEventController* _tmp23_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_menu_model;
	if (_tmp0_ == NULL) {
		GtkPopoverMenu* _tmp1_;
		_tmp1_ = self->priv->context_menu;
		if (_tmp1_ != NULL) {
			GtkGestureClick* _tmp2_;
			GtkGestureLongPress* _tmp3_;
			GtkEventControllerKey* _tmp4_;
			GtkPopoverMenu* _tmp5_;
			_tmp2_ = self->priv->click_controller;
			gtk_widget_remove_controller ((GtkWidget*) self, (GtkEventController*) _tmp2_);
			_tmp3_ = self->priv->long_press_controller;
			gtk_widget_remove_controller ((GtkWidget*) self, (GtkEventController*) _tmp3_);
			_tmp4_ = self->priv->menu_key_controller;
			gtk_widget_remove_controller ((GtkWidget*) self, (GtkEventController*) _tmp4_);
			_g_object_unref0 (self->priv->click_controller);
			self->priv->click_controller = NULL;
			_g_object_unref0 (self->priv->long_press_controller);
			self->priv->long_press_controller = NULL;
			_g_object_unref0 (self->priv->menu_key_controller);
			self->priv->menu_key_controller = NULL;
			_tmp5_ = self->priv->context_menu;
			gtk_widget_unparent ((GtkWidget*) _tmp5_);
			_g_object_unref0 (self->priv->context_menu);
			self->priv->context_menu = NULL;
		}
		return;
	}
	_tmp6_ = self->priv->context_menu;
	if (_tmp6_ != NULL) {
		GtkPopoverMenu* _tmp7_;
		GMenuModel* _tmp8_;
		_tmp7_ = self->priv->context_menu;
		_tmp8_ = self->priv->_menu_model;
		gtk_popover_menu_set_menu_model (_tmp7_, _tmp8_);
		return;
	}
	_tmp9_ = self->priv->_menu_model;
	_tmp10_ = (GtkPopoverMenu*) gtk_popover_menu_new_from_model (_tmp9_);
	gtk_popover_set_has_arrow ((GtkPopover*) _tmp10_, FALSE);
	gtk_popover_set_position ((GtkPopover*) _tmp10_, GTK_POS_BOTTOM);
	g_object_ref_sink (_tmp10_);
	_g_object_unref0 (self->priv->context_menu);
	self->priv->context_menu = _tmp10_;
	_tmp11_ = self->priv->context_menu;
	gtk_widget_set_parent ((GtkWidget*) _tmp11_, (GtkWidget*) self);
	_tmp12_ = (GtkGestureClick*) gtk_gesture_click_new ();
	gtk_gesture_single_set_button ((GtkGestureSingle*) _tmp12_, (guint) 0);
	gtk_gesture_single_set_exclusive ((GtkGestureSingle*) _tmp12_, TRUE);
	_g_object_unref0 (self->priv->click_controller);
	self->priv->click_controller = _tmp12_;
	_tmp13_ = self->priv->click_controller;
	g_signal_connect_object (_tmp13_, "pressed", (GCallback) _granite_list_item_on_click_gtk_gesture_click_pressed, self, 0);
	_tmp14_ = (GtkGestureLongPress*) gtk_gesture_long_press_new ();
	gtk_gesture_single_set_touch_only ((GtkGestureSingle*) _tmp14_, TRUE);
	_g_object_unref0 (self->priv->long_press_controller);
	self->priv->long_press_controller = _tmp14_;
	_tmp15_ = self->priv->long_press_controller;
	g_signal_connect_object (_tmp15_, "pressed", (GCallback) _granite_list_item_on_long_press_gtk_gesture_long_press_pressed, self, 0);
	_tmp16_ = (GtkEventControllerKey*) gtk_event_controller_key_new ();
	_g_object_unref0 (self->priv->menu_key_controller);
	self->priv->menu_key_controller = _tmp16_;
	_tmp17_ = self->priv->menu_key_controller;
	g_signal_connect_object (_tmp17_, "key-released", (GCallback) _granite_list_item_on_key_released_gtk_event_controller_key_key_released, self, 0);
	_tmp18_ = self->priv->click_controller;
	_tmp19_ = _g_object_ref0 ((GtkEventController*) _tmp18_);
	gtk_widget_add_controller ((GtkWidget*) self, _tmp19_);
	_tmp20_ = self->priv->long_press_controller;
	_tmp21_ = _g_object_ref0 ((GtkEventController*) _tmp20_);
	gtk_widget_add_controller ((GtkWidget*) self, _tmp21_);
	_tmp22_ = self->priv->menu_key_controller;
	_tmp23_ = _g_object_ref0 ((GtkEventController*) _tmp22_);
	gtk_widget_add_controller ((GtkWidget*) self, _tmp23_);
}

static gpointer
_gdk_event_ref0 (gpointer self)
{
	return self ? gdk_event_ref (self) : NULL;
}

static void
_vala_GdkEventSequence_free (GdkEventSequence* self)
{
	g_boxed_free (gdk_event_sequence_get_type (), self);
}

static void
granite_list_item_on_click (GraniteListItem* self,
                            GtkGestureClick* gesture,
                            gint n_press,
                            gdouble x,
                            gdouble y)
{
	GdkEventSequence* sequence = NULL;
	GdkEventSequence* _tmp0_;
	GdkEvent* event = NULL;
	GdkEventSequence* _tmp1_;
	GdkEvent* _tmp2_;
	GdkEvent* _tmp3_;
	GdkEvent* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (gesture != NULL);
	_tmp0_ = gtk_gesture_single_get_current_sequence ((GtkGestureSingle*) gesture);
	sequence = _tmp0_;
	_tmp1_ = sequence;
	_tmp2_ = gtk_gesture_get_last_event ((GtkGesture*) gesture, _tmp1_);
	_tmp3_ = _gdk_event_ref0 (_tmp2_);
	event = _tmp3_;
	_tmp4_ = event;
	if (gdk_event_triggers_context_menu (_tmp4_)) {
		GtkPopoverMenu* _tmp5_;
		GtkPopoverMenu* _tmp6_;
		_tmp5_ = self->priv->context_menu;
		gtk_widget_set_halign ((GtkWidget*) _tmp5_, GTK_ALIGN_START);
		_tmp6_ = self->priv->context_menu;
		granite_list_item_menu_popup_at_pointer (self, _tmp6_, x, y);
		gtk_gesture_set_state ((GtkGesture*) gesture, GTK_EVENT_SEQUENCE_CLAIMED);
		gtk_event_controller_reset ((GtkEventController*) gesture);
	}
	_gdk_event_unref0 (event);
	__vala_GdkEventSequence_free0 (sequence);
}

static void
granite_list_item_on_long_press (GraniteListItem* self,
                                 gdouble x,
                                 gdouble y)
{
	GtkRoot* _tmp0_;
	GtkPopoverMenu* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gtk_widget_get_root ((GtkWidget*) self);
	if (x > ((gdouble) (gtk_widget_get_width ((GtkWidget*) _tmp0_) / 2))) {
		GtkPopoverMenu* _tmp1_;
		_tmp1_ = self->priv->context_menu;
		gtk_widget_set_halign ((GtkWidget*) _tmp1_, GTK_ALIGN_END);
		x = x - GRANITE_LIST_ITEM_TOUCH_TARGET_WIDTH;
	} else {
		GtkPopoverMenu* _tmp2_;
		_tmp2_ = self->priv->context_menu;
		gtk_widget_set_halign ((GtkWidget*) _tmp2_, GTK_ALIGN_START);
		x = x + GRANITE_LIST_ITEM_TOUCH_TARGET_WIDTH;
	}
	_tmp3_ = self->priv->context_menu;
	granite_list_item_menu_popup_at_pointer (self, _tmp3_, x, y - (GRANITE_LIST_ITEM_TOUCH_TARGET_WIDTH * 0.75));
}

static void
granite_list_item_on_key_released (GraniteListItem* self,
                                   guint keyval,
                                   guint keycode,
                                   GdkModifierType state)
{
	GdkModifierType mods = 0U;
	g_return_if_fail (self != NULL);
	mods = state & gtk_accelerator_get_default_mod_mask ();
	switch (keyval) {
		case GDK_KEY_F10:
		{
			if (mods == GDK_SHIFT_MASK) {
				GtkPopoverMenu* _tmp0_;
				_tmp0_ = self->priv->context_menu;
				granite_list_item_menu_popup_on_keypress (self, _tmp0_);
			}
			break;
		}
		case GDK_KEY_Menu:
		case GDK_KEY_MenuKB:
		{
			GtkPopoverMenu* _tmp1_;
			_tmp1_ = self->priv->context_menu;
			granite_list_item_menu_popup_on_keypress (self, _tmp1_);
			break;
		}
		default:
		{
			return;
		}
	}
}

static void
granite_list_item_menu_popup_on_keypress (GraniteListItem* self,
                                          GtkPopoverMenu* popover)
{
	GdkRectangle _tmp0_ = {0};
	g_return_if_fail (self != NULL);
	g_return_if_fail (popover != NULL);
	gtk_widget_set_halign ((GtkWidget*) popover, GTK_ALIGN_END);
	memset (&_tmp0_, 0, sizeof (GdkRectangle));
	_tmp0_.x = (gint) gtk_widget_get_width ((GtkWidget*) self);
	_tmp0_.y = ((gint) gtk_widget_get_height ((GtkWidget*) self)) / 2;
	gtk_popover_set_pointing_to ((GtkPopover*) popover, &_tmp0_);
	gtk_popover_popup ((GtkPopover*) popover);
}

static void
granite_list_item_menu_popup_at_pointer (GraniteListItem* self,
                                         GtkPopoverMenu* popover,
                                         gdouble x,
                                         gdouble y)
{
	GdkRectangle rect = {0};
	GdkRectangle _tmp0_ = {0};
	GdkRectangle _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (popover != NULL);
	memset (&_tmp0_, 0, sizeof (GdkRectangle));
	_tmp0_.x = (gint) x;
	_tmp0_.y = (gint) y;
	rect = _tmp0_;
	_tmp1_ = rect;
	g_object_set ((GtkPopover*) popover, "pointing-to", &_tmp1_, NULL);
	gtk_popover_popup ((GtkPopover*) popover);
}

GraniteListItem*
granite_list_item_construct (GType object_type)
{
	GraniteListItem * self = NULL;
	self = (GraniteListItem*) g_object_new (object_type, NULL);
	return self;
}

GraniteListItem*
granite_list_item_new (void)
{
	return granite_list_item_construct (GRANITE_TYPE_LIST_ITEM);
}

static Block4Data*
block4_data_ref (Block4Data* _data4_)
{
	g_atomic_int_inc (&_data4_->_ref_count_);
	return _data4_;
}

static void
block4_data_unref (void * _userdata_)
{
	Block4Data* _data4_;
	_data4_ = (Block4Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data4_->_ref_count_)) {
		GraniteListItem* self;
		self = _data4_->self;
		_g_object_unref0 (_data4_->text_box);
		_g_object_unref0 (_data4_->description_label);
		_g_object_unref0 (self);
		g_slice_free (Block4Data, _data4_);
	}
}

static void
_granite_list_item___lambda18_ (Block4Data* _data4_)
{
	GraniteListItem* self;
	const gchar* _tmp0_;
	gboolean _tmp1_ = FALSE;
	const gchar* _tmp2_;
	self = _data4_->self;
	_tmp0_ = self->priv->_description;
	gtk_accessible_update_property ((GtkAccessible*) self, GTK_ACCESSIBLE_PROPERTY_DESCRIPTION, _tmp0_, -1, -1);
	_tmp2_ = self->priv->_description;
	if (_tmp2_ == NULL) {
		_tmp1_ = TRUE;
	} else {
		const gchar* _tmp3_;
		_tmp3_ = self->priv->_description;
		_tmp1_ = g_strcmp0 (_tmp3_, "") == 0;
	}
	if (_tmp1_) {
		GraniteBox* _tmp4_;
		GtkLabel* _tmp5_;
		_tmp4_ = _data4_->text_box;
		_tmp5_ = _data4_->description_label;
		gtk_box_remove ((GtkBox*) _tmp4_, (GtkWidget*) _tmp5_);
	} else {
		GraniteBox* _tmp6_;
		GtkLabel* _tmp7_;
		_tmp6_ = _data4_->text_box;
		_tmp7_ = _data4_->description_label;
		gtk_box_append ((GtkBox*) _tmp6_, (GtkWidget*) _tmp7_);
	}
}

static void
__granite_list_item___lambda18__g_object_notify (GObject* _sender,
                                                 GParamSpec* pspec,
                                                 gpointer self)
{
	_granite_list_item___lambda18_ (self);
}

static void
_granite_list_item_construct_menu_g_object_notify (GObject* _sender,
                                                   GParamSpec* pspec,
                                                   gpointer self)
{
	granite_list_item_construct_menu ((GraniteListItem*) self);
}

static GObject *
granite_list_item_constructor (GType type,
                               guint n_construct_properties,
                               GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GraniteListItem * self;
	Block4Data* _data4_;
	GtkLabel* label = NULL;
	GtkWidget* _tmp0_;
	GtkLabel* _tmp1_ = NULL;
	GtkLabel* _tmp2_ = NULL;
	GtkLabel* _tmp3_;
	GtkLabel* _tmp4_;
	GraniteBox* _tmp5_;
	GraniteBox* _tmp6_;
	GtkLabel* _tmp7_;
	GraniteBox* _tmp8_;
	GraniteBox* _tmp9_;
	GtkLabel* _tmp10_;
	GtkLabel* _tmp11_;
	parent_class = G_OBJECT_CLASS (granite_list_item_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GRANITE_TYPE_LIST_ITEM, GraniteListItem);
	_data4_ = g_slice_new0 (Block4Data);
	_data4_->_ref_count_ = 1;
	_data4_->self = g_object_ref (self);
	_tmp0_ = _g_object_ref0 ((GtkWidget*) self);
	_tmp1_ = (GtkLabel*) gtk_label_new ("");
	gtk_widget_set_hexpand ((GtkWidget*) _tmp1_, TRUE);
	gtk_widget_set_vexpand ((GtkWidget*) _tmp1_, TRUE);
	gtk_label_set_wrap (_tmp1_, TRUE);
	gtk_label_set_xalign (_tmp1_, (gfloat) 0);
	gtk_label_set_mnemonic_widget (_tmp1_, _tmp0_);
	_g_object_unref0 (_tmp0_);
	g_object_ref_sink (_tmp1_);
	label = _tmp1_;
	_tmp2_ = (GtkLabel*) gtk_label_new ("");
	gtk_label_set_wrap (_tmp2_, TRUE);
	gtk_label_set_xalign (_tmp2_, (gfloat) 0);
	g_object_ref_sink (_tmp2_);
	_data4_->description_label = _tmp2_;
	_tmp3_ = _data4_->description_label;
	gtk_widget_add_css_class ((GtkWidget*) _tmp3_, GRANITE_STYLE_CLASS_SMALL_LABEL);
	_tmp4_ = _data4_->description_label;
	gtk_widget_add_css_class ((GtkWidget*) _tmp4_, GRANITE_STYLE_CLASS_DIM_LABEL);
	_tmp5_ = granite_box_new (GTK_ORIENTATION_VERTICAL, GRANITE_BOX_SPACING_NONE);
	g_object_ref_sink (_tmp5_);
	_data4_->text_box = _tmp5_;
	_tmp6_ = _data4_->text_box;
	_tmp7_ = label;
	gtk_box_append ((GtkBox*) _tmp6_, (GtkWidget*) _tmp7_);
	_tmp8_ = _data4_->text_box;
	gtk_widget_add_css_class ((GtkWidget*) _tmp8_, "text-box");
	gtk_widget_set_focusable ((GtkWidget*) self, TRUE);
	_tmp9_ = _data4_->text_box;
	granite_list_item_set_child (self, (GtkWidget*) _tmp9_);
	_tmp10_ = label;
	g_object_bind_property_with_closures ((GObject*) self, "text", (GObject*) _tmp10_, "label", G_BINDING_DEFAULT, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_tmp11_ = _data4_->description_label;
	g_object_bind_property_with_closures ((GObject*) self, "description", (GObject*) _tmp11_, "label", G_BINDING_DEFAULT, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	g_signal_connect_data ((GObject*) self, "notify::description", (GCallback) __granite_list_item___lambda18__g_object_notify, block4_data_ref (_data4_), (GClosureNotify) block4_data_unref, 0);
	g_signal_connect_object ((GObject*) self, "notify::menu-model", (GCallback) _granite_list_item_construct_menu_g_object_notify, self, 0);
	_g_object_unref0 (label);
	block4_data_unref (_data4_);
	_data4_ = NULL;
	return obj;
}

static void
granite_list_item_base_init (GraniteListItemClass * klass)
{
	gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (klass), "granite-listitem");
	gtk_widget_class_set_layout_manager_type (GTK_WIDGET_CLASS (klass), gtk_bin_layout_get_type ());
}

static void
granite_list_item_class_init (GraniteListItemClass * klass,
                              gpointer klass_data)
{
	granite_list_item_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GraniteListItem_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_granite_list_item_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_granite_list_item_set_property;
	G_OBJECT_CLASS (klass)->constructor = granite_list_item_constructor;
	G_OBJECT_CLASS (klass)->finalize = granite_list_item_finalize;
	/**
	     * The main label for #this
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRANITE_LIST_ITEM_TEXT_PROPERTY, granite_list_item_properties[GRANITE_LIST_ITEM_TEXT_PROPERTY] = g_param_spec_string ("text", "text", "text", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	/**
	     * Small, dim description text
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRANITE_LIST_ITEM_DESCRIPTION_PROPERTY, granite_list_item_properties[GRANITE_LIST_ITEM_DESCRIPTION_PROPERTY] = g_param_spec_string ("description", "description", "description", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	/**
	     * The child widget of #this
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRANITE_LIST_ITEM_CHILD_PROPERTY, granite_list_item_properties[GRANITE_LIST_ITEM_CHILD_PROPERTY] = g_param_spec_object ("child", "child", "child", gtk_widget_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	/**
	     * Context menu model
	     * When a menu is shown with secondary click or long press will be constructed from the provided menu model
	     *
	     * @since 7.8.0
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRANITE_LIST_ITEM_MENU_MODEL_PROPERTY, granite_list_item_properties[GRANITE_LIST_ITEM_MENU_MODEL_PROPERTY] = g_param_spec_object ("menu-model", "menu-model", "menu-model", g_menu_model_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
granite_list_item_instance_init (GraniteListItem * self,
                                 gpointer klass)
{
	self->priv = granite_list_item_get_instance_private (self);
}

static void
granite_list_item_finalize (GObject * obj)
{
	GraniteListItem * self;
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GRANITE_TYPE_LIST_ITEM, GraniteListItem);
	_tmp0_ = granite_list_item_get_child (self);
	_tmp1_ = _tmp0_;
	if (_tmp1_ != NULL) {
		GtkWidget* _tmp2_;
		GtkWidget* _tmp3_;
		_tmp2_ = granite_list_item_get_child (self);
		_tmp3_ = _tmp2_;
		gtk_widget_unparent (_tmp3_);
	}
	_g_free0 (self->priv->_text);
	_g_free0 (self->priv->_description);
	_g_object_unref0 (self->priv->_child);
	_g_object_unref0 (self->priv->_menu_model);
	_g_object_unref0 (self->priv->click_controller);
	_g_object_unref0 (self->priv->long_press_controller);
	_g_object_unref0 (self->priv->menu_key_controller);
	_g_object_unref0 (self->priv->context_menu);
	G_OBJECT_CLASS (granite_list_item_parent_class)->finalize (obj);
}

/**
 * A standard list item widget for use in {@link Gtk.ListBox} and {@link Gtk.ListView}
 *
 * @since 7.7.0
 */
static GType
granite_list_item_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GraniteListItemClass), (GBaseInitFunc) granite_list_item_base_init, (GBaseFinalizeFunc) NULL, (GClassInitFunc) granite_list_item_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GraniteListItem), 0, (GInstanceInitFunc) granite_list_item_instance_init, NULL };
	GType granite_list_item_type_id;
	granite_list_item_type_id = g_type_register_static (gtk_widget_get_type (), "GraniteListItem", &g_define_type_info, 0);
	GraniteListItem_private_offset = g_type_add_instance_private (granite_list_item_type_id, sizeof (GraniteListItemPrivate));
	return granite_list_item_type_id;
}

GType
granite_list_item_get_type (void)
{
	static volatile gsize granite_list_item_type_id__once = 0;
	if (g_once_init_enter (&granite_list_item_type_id__once)) {
		GType granite_list_item_type_id;
		granite_list_item_type_id = granite_list_item_get_type_once ();
		g_once_init_leave (&granite_list_item_type_id__once, granite_list_item_type_id);
	}
	return granite_list_item_type_id__once;
}

static void
_vala_granite_list_item_get_property (GObject * object,
                                      guint property_id,
                                      GValue * value,
                                      GParamSpec * pspec)
{
	GraniteListItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GRANITE_TYPE_LIST_ITEM, GraniteListItem);
	switch (property_id) {
		case GRANITE_LIST_ITEM_TEXT_PROPERTY:
		g_value_set_string (value, granite_list_item_get_text (self));
		break;
		case GRANITE_LIST_ITEM_DESCRIPTION_PROPERTY:
		g_value_set_string (value, granite_list_item_get_description (self));
		break;
		case GRANITE_LIST_ITEM_CHILD_PROPERTY:
		g_value_set_object (value, granite_list_item_get_child (self));
		break;
		case GRANITE_LIST_ITEM_MENU_MODEL_PROPERTY:
		g_value_set_object (value, granite_list_item_get_menu_model (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_granite_list_item_set_property (GObject * object,
                                      guint property_id,
                                      const GValue * value,
                                      GParamSpec * pspec)
{
	GraniteListItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GRANITE_TYPE_LIST_ITEM, GraniteListItem);
	switch (property_id) {
		case GRANITE_LIST_ITEM_TEXT_PROPERTY:
		granite_list_item_set_text (self, g_value_get_string (value));
		break;
		case GRANITE_LIST_ITEM_DESCRIPTION_PROPERTY:
		granite_list_item_set_description (self, g_value_get_string (value));
		break;
		case GRANITE_LIST_ITEM_CHILD_PROPERTY:
		granite_list_item_set_child (self, g_value_get_object (value));
		break;
		case GRANITE_LIST_ITEM_MENU_MODEL_PROPERTY:
		granite_list_item_set_menu_model (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

