/* sidebar-count-cell-renderer.c generated by valac 0.56.19, the Vala compiler
 * generated from sidebar-count-cell-renderer.vala, do not modify */

/* Copyright 2016 Software Freedom Conservancy Inc.
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later).  See the COPYING file in this distribution.
 */

#include "geary-client-46.0.h"
#include <glib.h>
#include <gtk/gtk.h>
#include <cairo-gobject.h>
#include <gdk/gdk.h>
#include <glib-object.h>

#define SIDEBAR_COUNT_CELL_RENDERER_HORIZONTAL_MARGIN 4
#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  {
	SIDEBAR_COUNT_CELL_RENDERER_0_PROPERTY,
	SIDEBAR_COUNT_CELL_RENDERER_COUNTER_PROPERTY,
	SIDEBAR_COUNT_CELL_RENDERER_NUM_PROPERTIES
};
static GParamSpec* sidebar_count_cell_renderer_properties[SIDEBAR_COUNT_CELL_RENDERER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _SidebarCountCellRendererPrivate {
	gint _counter;
	CountBadge* unread_count;
};

static gint SidebarCountCellRenderer_private_offset;
static gpointer sidebar_count_cell_renderer_parent_class = NULL;

static GtkSizeRequestMode sidebar_count_cell_renderer_real_get_request_mode (GtkCellRenderer* base);
static void sidebar_count_cell_renderer_real_get_preferred_width (GtkCellRenderer* base,
                                                           GtkWidget* widget,
                                                           gint* minimum_size,
                                                           gint* natural_size);
static void sidebar_count_cell_renderer_real_render (GtkCellRenderer* base,
                                              cairo_t* ctx,
                                              GtkWidget* widget,
                                              GdkRectangle* background_area,
                                              GdkRectangle* cell_area,
                                              GtkCellRendererState flags);
static void sidebar_count_cell_renderer_real_get_size (GtkCellRenderer* base,
                                                GtkWidget* widget,
                                                GdkRectangle* cell_area,
                                                gint* x_offset,
                                                gint* y_offset,
                                                gint* width,
                                                gint* height);
static void sidebar_count_cell_renderer_finalize (GObject * obj);
static GType sidebar_count_cell_renderer_get_type_once (void);
static void _vala_sidebar_count_cell_renderer_get_property (GObject * object,
                                                     guint property_id,
                                                     GValue * value,
                                                     GParamSpec * pspec);
static void _vala_sidebar_count_cell_renderer_set_property (GObject * object,
                                                     guint property_id,
                                                     const GValue * value,
                                                     GParamSpec * pspec);

static inline gpointer
sidebar_count_cell_renderer_get_instance_private (SidebarCountCellRenderer* self)
{
	return G_STRUCT_MEMBER_P (self, SidebarCountCellRenderer_private_offset);
}

gint
sidebar_count_cell_renderer_get_counter (SidebarCountCellRenderer* self)
{
	gint result;
	g_return_val_if_fail (IS_SIDEBAR_COUNT_CELL_RENDERER (self), -1);
	result = self->priv->_counter;
	return result;
}

void
sidebar_count_cell_renderer_set_counter (SidebarCountCellRenderer* self,
                                         gint value)
{
	gint old_value;
	g_return_if_fail (IS_SIDEBAR_COUNT_CELL_RENDERER (self));
	old_value = sidebar_count_cell_renderer_get_counter (self);
	if (old_value != value) {
		self->priv->_counter = value;
		g_object_notify_by_pspec ((GObject *) self, sidebar_count_cell_renderer_properties[SIDEBAR_COUNT_CELL_RENDERER_COUNTER_PROPERTY]);
	}
}

SidebarCountCellRenderer*
sidebar_count_cell_renderer_construct (GType object_type)
{
	SidebarCountCellRenderer * self = NULL;
	self = (SidebarCountCellRenderer*) g_object_new (object_type, NULL);
	return self;
}

SidebarCountCellRenderer*
sidebar_count_cell_renderer_new (void)
{
	return sidebar_count_cell_renderer_construct (TYPE_SIDEBAR_COUNT_CELL_RENDERER);
}

static GtkSizeRequestMode
sidebar_count_cell_renderer_real_get_request_mode (GtkCellRenderer* base)
{
	SidebarCountCellRenderer * self;
	GtkSizeRequestMode result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, TYPE_SIDEBAR_COUNT_CELL_RENDERER, SidebarCountCellRenderer);
	result = GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
	return result;
}

static void
sidebar_count_cell_renderer_real_get_preferred_width (GtkCellRenderer* base,
                                                      GtkWidget* widget,
                                                      gint* minimum_size,
                                                      gint* natural_size)
{
	SidebarCountCellRenderer * self;
	gint _vala_minimum_size = 0;
	gint _vala_natural_size = 0;
	CountBadge* _tmp0_;
	gint _tmp1_;
	CountBadge* _tmp2_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, TYPE_SIDEBAR_COUNT_CELL_RENDERER, SidebarCountCellRenderer);
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (widget, gtk_widget_get_type ()));
	_tmp0_ = self->priv->unread_count;
	_tmp1_ = self->priv->_counter;
	count_badge_set_count (_tmp0_, _tmp1_);
	_tmp2_ = self->priv->unread_count;
	_vala_minimum_size = count_badge_get_width (_tmp2_, widget) + COUNT_BADGE_SPACING;
	_vala_natural_size = _vala_minimum_size;
	if (minimum_size) {
		*minimum_size = _vala_minimum_size;
	}
	if (natural_size) {
		*natural_size = _vala_natural_size;
	}
}

static void
sidebar_count_cell_renderer_real_render (GtkCellRenderer* base,
                                         cairo_t* ctx,
                                         GtkWidget* widget,
                                         GdkRectangle* background_area,
                                         GdkRectangle* cell_area,
                                         GtkCellRendererState flags)
{
	SidebarCountCellRenderer * self;
	CountBadge* _tmp0_;
	gint _tmp1_;
	gint x = 0;
	GdkRectangle _tmp2_;
	GdkRectangle _tmp3_;
	CountBadge* _tmp4_;
	gint y = 0;
	GdkRectangle _tmp5_;
	GdkRectangle _tmp6_;
	CountBadge* _tmp7_;
	CountBadge* _tmp8_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, TYPE_SIDEBAR_COUNT_CELL_RENDERER, SidebarCountCellRenderer);
	g_return_if_fail (ctx != NULL);
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (widget, gtk_widget_get_type ()));
	g_return_if_fail (background_area != NULL);
	g_return_if_fail (cell_area != NULL);
	_tmp0_ = self->priv->unread_count;
	_tmp1_ = self->priv->_counter;
	count_badge_set_count (_tmp0_, _tmp1_);
	_tmp2_ = *cell_area;
	_tmp3_ = *cell_area;
	_tmp4_ = self->priv->unread_count;
	x = (_tmp2_.x + (_tmp3_.width - count_badge_get_width (_tmp4_, widget))) - SIDEBAR_COUNT_CELL_RENDERER_HORIZONTAL_MARGIN;
	_tmp5_ = *cell_area;
	_tmp6_ = *cell_area;
	_tmp7_ = self->priv->unread_count;
	y = _tmp5_.y + ((_tmp6_.height - count_badge_get_height (_tmp7_, widget)) / 2);
	_tmp8_ = self->priv->unread_count;
	count_badge_render (_tmp8_, widget, ctx, x, y, FALSE);
}

static void
sidebar_count_cell_renderer_real_get_size (GtkCellRenderer* base,
                                           GtkWidget* widget,
                                           GdkRectangle* cell_area,
                                           gint* x_offset,
                                           gint* y_offset,
                                           gint* width,
                                           gint* height)
{
	SidebarCountCellRenderer * self;
	gint _vala_x_offset = 0;
	gint _vala_y_offset = 0;
	gint _vala_width = 0;
	gint _vala_height = 0;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, TYPE_SIDEBAR_COUNT_CELL_RENDERER, SidebarCountCellRenderer);
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (widget, gtk_widget_get_type ()));
	_vala_x_offset = 0;
	_vala_y_offset = 0;
	_vala_width = 0;
	_vala_height = 0;
	if (x_offset) {
		*x_offset = _vala_x_offset;
	}
	if (y_offset) {
		*y_offset = _vala_y_offset;
	}
	if (width) {
		*width = _vala_width;
	}
	if (height) {
		*height = _vala_height;
	}
}

static void
sidebar_count_cell_renderer_class_init (SidebarCountCellRendererClass * klass,
                                        gpointer klass_data)
{
	sidebar_count_cell_renderer_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SidebarCountCellRenderer_private_offset);
	((GtkCellRendererClass *) klass)->get_request_mode = (GtkSizeRequestMode (*) (GtkCellRenderer*)) sidebar_count_cell_renderer_real_get_request_mode;
	((GtkCellRendererClass *) klass)->get_preferred_width = (void (*) (GtkCellRenderer*, GtkWidget*, gint*, gint*)) sidebar_count_cell_renderer_real_get_preferred_width;
	((GtkCellRendererClass *) klass)->render = (void (*) (GtkCellRenderer*, cairo_t*, GtkWidget*, GdkRectangle*, GdkRectangle*, GtkCellRendererState)) sidebar_count_cell_renderer_real_render;
	((GtkCellRendererClass *) klass)->get_size = (void (*) (GtkCellRenderer*, GtkWidget*, GdkRectangle*, gint*, gint*, gint*, gint*)) sidebar_count_cell_renderer_real_get_size;
	G_OBJECT_CLASS (klass)->get_property = _vala_sidebar_count_cell_renderer_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_sidebar_count_cell_renderer_set_property;
	G_OBJECT_CLASS (klass)->finalize = sidebar_count_cell_renderer_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SIDEBAR_COUNT_CELL_RENDERER_COUNTER_PROPERTY, sidebar_count_cell_renderer_properties[SIDEBAR_COUNT_CELL_RENDERER_COUNTER_PROPERTY] = g_param_spec_int ("counter", "counter", "counter", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
sidebar_count_cell_renderer_instance_init (SidebarCountCellRenderer * self,
                                           gpointer klass)
{
	CountBadge* _tmp0_;
	self->priv = sidebar_count_cell_renderer_get_instance_private (self);
	_tmp0_ = count_badge_new (1);
	self->priv->unread_count = _tmp0_;
}

static void
sidebar_count_cell_renderer_finalize (GObject * obj)
{
	SidebarCountCellRenderer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_SIDEBAR_COUNT_CELL_RENDERER, SidebarCountCellRenderer);
	_g_object_unref0 (self->priv->unread_count);
	G_OBJECT_CLASS (sidebar_count_cell_renderer_parent_class)->finalize (obj);
}

/**
 * Cell renderer for counter in sidebar.
 */
static GType
sidebar_count_cell_renderer_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SidebarCountCellRendererClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) sidebar_count_cell_renderer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SidebarCountCellRenderer), 0, (GInstanceInitFunc) sidebar_count_cell_renderer_instance_init, NULL };
	GType sidebar_count_cell_renderer_type_id;
	sidebar_count_cell_renderer_type_id = g_type_register_static (gtk_cell_renderer_get_type (), "SidebarCountCellRenderer", &g_define_type_info, 0);
	SidebarCountCellRenderer_private_offset = g_type_add_instance_private (sidebar_count_cell_renderer_type_id, sizeof (SidebarCountCellRendererPrivate));
	return sidebar_count_cell_renderer_type_id;
}

GType
sidebar_count_cell_renderer_get_type (void)
{
	static volatile gsize sidebar_count_cell_renderer_type_id__once = 0;
	if (g_once_init_enter (&sidebar_count_cell_renderer_type_id__once)) {
		GType sidebar_count_cell_renderer_type_id;
		sidebar_count_cell_renderer_type_id = sidebar_count_cell_renderer_get_type_once ();
		g_once_init_leave (&sidebar_count_cell_renderer_type_id__once, sidebar_count_cell_renderer_type_id);
	}
	return sidebar_count_cell_renderer_type_id__once;
}

static void
_vala_sidebar_count_cell_renderer_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec)
{
	SidebarCountCellRenderer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_SIDEBAR_COUNT_CELL_RENDERER, SidebarCountCellRenderer);
	switch (property_id) {
		case SIDEBAR_COUNT_CELL_RENDERER_COUNTER_PROPERTY:
		g_value_set_int (value, sidebar_count_cell_renderer_get_counter (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_sidebar_count_cell_renderer_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec)
{
	SidebarCountCellRenderer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_SIDEBAR_COUNT_CELL_RENDERER, SidebarCountCellRenderer);
	switch (property_id) {
		case SIDEBAR_COUNT_CELL_RENDERER_COUNTER_PROPERTY:
		sidebar_count_cell_renderer_set_counter (self, g_value_get_int (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

