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

#include "codecore.h"
#include <gtksourceview/gtksource.h>
#include <cairo-gobject.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gee.h>
#include <glib-object.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  {
	SCRATCH_WIDGETS_GIT_GUTTER_RENDERER_0_PROPERTY,
	SCRATCH_WIDGETS_GIT_GUTTER_RENDERER_PROJECT_PROPERTY,
	SCRATCH_WIDGETS_GIT_GUTTER_RENDERER_NUM_PROPERTIES
};
static GParamSpec* scratch_widgets_git_gutter_renderer_properties[SCRATCH_WIDGETS_GIT_GUTTER_RENDERER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define __vala_GdkRGBA_free0(var) ((var == NULL) ? NULL : (var = (_vala_GdkRGBA_free (var), NULL)))

struct _ScratchWidgetsGitGutterRendererPrivate {
	ScratchFolderManagerProjectFolderItem* _project;
};

static gint ScratchWidgetsGitGutterRenderer_private_offset;
static gpointer scratch_widgets_git_gutter_renderer_parent_class = NULL;
static GtkSourceStyleScheme* scratch_widgets_git_gutter_renderer_fallback_scheme;
static GtkSourceStyleScheme* scratch_widgets_git_gutter_renderer_fallback_scheme = NULL;

static void scratch_widgets_git_gutter_renderer_update_status_color_map (ScratchWidgetsGitGutterRenderer* self,
                                                                  ScratchServicesVCStatus status,
                                                                  GtkSourceStyleScheme* scheme,
                                                                  const gchar* style_id,
                                                                  gboolean use_foreground);
static void scratch_widgets_git_gutter_renderer_real_draw (GtkSourceGutterRenderer* base,
                                                    cairo_t* cr,
                                                    GdkRectangle* bg,
                                                    GdkRectangle* area,
                                                    GtkTextIter* start,
                                                    GtkTextIter* end,
                                                    GtkSourceGutterRendererState state);
static void _vala_GdkRGBA_free (GdkRGBA* self);
static GObject * scratch_widgets_git_gutter_renderer_constructor (GType type,
                                                           guint n_construct_properties,
                                                           GObjectConstructParam * construct_properties);
static GdkRGBA* _vala_GdkRGBA_copy (GdkRGBA* self);
static void scratch_widgets_git_gutter_renderer_finalize (GObject * obj);
static GType scratch_widgets_git_gutter_renderer_get_type_once (void);
static void _vala_scratch_widgets_git_gutter_renderer_get_property (GObject * object,
                                                             guint property_id,
                                                             GValue * value,
                                                             GParamSpec * pspec);
static void _vala_scratch_widgets_git_gutter_renderer_set_property (GObject * object,
                                                             guint property_id,
                                                             const GValue * value,
                                                             GParamSpec * pspec);

static inline gpointer
scratch_widgets_git_gutter_renderer_get_instance_private (ScratchWidgetsGitGutterRenderer* self)
{
	return G_STRUCT_MEMBER_P (self, ScratchWidgetsGitGutterRenderer_private_offset);
}

void
scratch_widgets_git_gutter_renderer_set_style_scheme (ScratchWidgetsGitGutterRenderer* self,
                                                      GtkSourceStyleScheme* scheme)
{
	g_return_if_fail (self != NULL);
	scratch_widgets_git_gutter_renderer_update_status_color_map (self, SCRATCH_SERVICES_VC_STATUS_ADDED, scheme, SCRATCH_WIDGETS_GIT_GUTTER_RENDERER_ADDED_STYLE_ID, TRUE);
	scratch_widgets_git_gutter_renderer_update_status_color_map (self, SCRATCH_SERVICES_VC_STATUS_REMOVED, scheme, SCRATCH_WIDGETS_GIT_GUTTER_RENDERER_REMOVED_STYLE_ID, TRUE);
	scratch_widgets_git_gutter_renderer_update_status_color_map (self, SCRATCH_SERVICES_VC_STATUS_CHANGED, scheme, SCRATCH_WIDGETS_GIT_GUTTER_RENDERER_CHANGED_STYLE_ID, TRUE);
	scratch_widgets_git_gutter_renderer_update_status_color_map (self, SCRATCH_SERVICES_VC_STATUS_REPLACES_DELETED, scheme, SCRATCH_WIDGETS_GIT_GUTTER_RENDERER_REPLACES_DELETED_STYLE_ID, TRUE);
	scratch_widgets_git_gutter_renderer_update_status_color_map (self, SCRATCH_SERVICES_VC_STATUS_NONE, scheme, SCRATCH_WIDGETS_GIT_GUTTER_RENDERER_NONE_STYLE_ID, FALSE);
}

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

static void
scratch_widgets_git_gutter_renderer_update_status_color_map (ScratchWidgetsGitGutterRenderer* self,
                                                             ScratchServicesVCStatus status,
                                                             GtkSourceStyleScheme* scheme,
                                                             const gchar* style_id,
                                                             gboolean use_foreground)
{
	GtkSourceStyle* style = NULL;
	GtkSourceStyle* _tmp14_;
	GdkRGBA color = {0};
	gchar* _tmp18_ = NULL;
	GeeHashMap* _tmp25_;
	GdkRGBA _tmp26_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (style_id != NULL);
	style = NULL;
	if (scheme != NULL) {
		GtkSourceStyle* _tmp0_;
		GtkSourceStyle* _tmp1_;
		GtkSourceStyle* _tmp2_;
		_tmp0_ = gtk_source_style_scheme_get_style (scheme, style_id);
		_tmp1_ = _g_object_ref0 (_tmp0_);
		_g_object_unref0 (style);
		style = _tmp1_;
		_tmp2_ = style;
		if (_tmp2_ != NULL) {
			gboolean _tmp3_ = FALSE;
			gboolean _tmp4_ = FALSE;
			if (use_foreground) {
				GtkSourceStyle* _tmp5_;
				gchar* _tmp6_;
				gchar* _tmp7_;
				gchar* _tmp8_;
				_tmp5_ = style;
				g_object_get (_tmp5_, "foreground", &_tmp6_, NULL);
				_tmp7_ = _tmp6_;
				_tmp8_ = _tmp7_;
				_tmp4_ = _tmp8_ == NULL;
				_g_free0 (_tmp8_);
			} else {
				_tmp4_ = FALSE;
			}
			if (_tmp4_) {
				_tmp3_ = TRUE;
			} else {
				gboolean _tmp9_ = FALSE;
				if (!use_foreground) {
					GtkSourceStyle* _tmp10_;
					gchar* _tmp11_;
					gchar* _tmp12_;
					gchar* _tmp13_;
					_tmp10_ = style;
					g_object_get (_tmp10_, "background", &_tmp11_, NULL);
					_tmp12_ = _tmp11_;
					_tmp13_ = _tmp12_;
					_tmp9_ = _tmp13_ == NULL;
					_g_free0 (_tmp13_);
				} else {
					_tmp9_ = FALSE;
				}
				_tmp3_ = _tmp9_;
			}
			if (_tmp3_) {
				_g_object_unref0 (style);
				style = NULL;
			}
		}
	}
	_tmp14_ = style;
	if (_tmp14_ == NULL) {
		GtkSourceStyleScheme* _tmp15_;
		GtkSourceStyle* _tmp16_;
		GtkSourceStyle* _tmp17_;
		_tmp15_ = scratch_widgets_git_gutter_renderer_fallback_scheme;
		_tmp16_ = gtk_source_style_scheme_get_style (_tmp15_, style_id);
		_tmp17_ = _g_object_ref0 (_tmp16_);
		_g_object_unref0 (style);
		style = _tmp17_;
	}
	memset (&color, 0, sizeof (GdkRGBA));
	if (use_foreground) {
		GtkSourceStyle* _tmp19_;
		gchar* _tmp20_;
		gchar* _tmp21_;
		_tmp19_ = style;
		g_object_get (_tmp19_, "foreground", &_tmp20_, NULL);
		_tmp21_ = _tmp20_;
		_g_free0 (_tmp18_);
		_tmp18_ = _tmp21_;
	} else {
		GtkSourceStyle* _tmp22_;
		gchar* _tmp23_;
		gchar* _tmp24_;
		_tmp22_ = style;
		g_object_get (_tmp22_, "background", &_tmp23_, NULL);
		_tmp24_ = _tmp23_;
		_g_free0 (_tmp18_);
		_tmp18_ = _tmp24_;
	}
	gdk_rgba_parse (&color, _tmp18_);
	_tmp25_ = self->status_color_map;
	_tmp26_ = color;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp25_, (gpointer) ((gintptr) status), &_tmp26_);
	_g_free0 (_tmp18_);
	_g_object_unref0 (style);
}

static void
_vala_GdkRGBA_free (GdkRGBA* self)
{
	g_boxed_free (gdk_rgba_get_type (), self);
}

static void
scratch_widgets_git_gutter_renderer_real_draw (GtkSourceGutterRenderer* base,
                                               cairo_t* cr,
                                               GdkRectangle* bg,
                                               GdkRectangle* area,
                                               GtkTextIter* start,
                                               GtkTextIter* end,
                                               GtkSourceGutterRendererState state)
{
	ScratchWidgetsGitGutterRenderer * self;
	gint gutter_line_no = 0;
	GeeHashMap* _tmp0_;
	GdkRectangle _tmp9_;
	GdkRectangle _tmp10_;
	GtkTextIter _tmp11_;
	GtkTextIter _tmp12_;
	self = (ScratchWidgetsGitGutterRenderer*) base;
	g_return_if_fail (cr != NULL);
	g_return_if_fail (bg != NULL);
	g_return_if_fail (area != NULL);
	g_return_if_fail (start != NULL);
	g_return_if_fail (end != NULL);
	gutter_line_no = gtk_text_iter_get_line (start) + 1;
	_tmp0_ = self->line_status_map;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp0_, (gpointer) ((gintptr) gutter_line_no))) {
		GeeHashMap* _tmp1_;
		GeeHashMap* _tmp2_;
		gpointer _tmp3_;
		gpointer _tmp4_;
		GdkRGBA* _tmp5_;
		_tmp1_ = self->status_color_map;
		_tmp2_ = self->line_status_map;
		_tmp3_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp2_, (gpointer) ((gintptr) gutter_line_no));
		_tmp4_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp1_, (gpointer) ((gintptr) _tmp3_));
		_tmp5_ = (GdkRGBA*) _tmp4_;
		gtk_source_gutter_renderer_set_background ((GtkSourceGutterRenderer*) self, _tmp5_);
		__vala_GdkRGBA_free0 (_tmp5_);
	} else {
		GeeHashMap* _tmp6_;
		gpointer _tmp7_;
		GdkRGBA* _tmp8_;
		_tmp6_ = self->status_color_map;
		_tmp7_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp6_, (gpointer) ((gintptr) SCRATCH_SERVICES_VC_STATUS_NONE));
		_tmp8_ = (GdkRGBA*) _tmp7_;
		gtk_source_gutter_renderer_set_background ((GtkSourceGutterRenderer*) self, _tmp8_);
		__vala_GdkRGBA_free0 (_tmp8_);
	}
	_tmp9_ = *bg;
	_tmp10_ = *area;
	_tmp11_ = *start;
	_tmp12_ = *end;
	GTK_SOURCE_GUTTER_RENDERER_CLASS (scratch_widgets_git_gutter_renderer_parent_class)->draw (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_source_gutter_renderer_get_type (), GtkSourceGutterRenderer), cr, &_tmp9_, &_tmp10_, &_tmp11_, &_tmp12_, state);
}

ScratchWidgetsGitGutterRenderer*
scratch_widgets_git_gutter_renderer_construct (GType object_type)
{
	ScratchWidgetsGitGutterRenderer * self = NULL;
	self = (ScratchWidgetsGitGutterRenderer*) g_object_new (object_type, NULL);
	return self;
}

ScratchWidgetsGitGutterRenderer*
scratch_widgets_git_gutter_renderer_new (void)
{
	return scratch_widgets_git_gutter_renderer_construct (SCRATCH_WIDGETS_TYPE_GIT_GUTTER_RENDERER);
}

ScratchFolderManagerProjectFolderItem*
scratch_widgets_git_gutter_renderer_get_project (ScratchWidgetsGitGutterRenderer* self)
{
	ScratchFolderManagerProjectFolderItem* result;
	ScratchFolderManagerProjectFolderItem* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_project;
	result = _tmp0_;
	return result;
}

void
scratch_widgets_git_gutter_renderer_set_project (ScratchWidgetsGitGutterRenderer* self,
                                                 ScratchFolderManagerProjectFolderItem* value)
{
	ScratchFolderManagerProjectFolderItem* old_value;
	g_return_if_fail (self != NULL);
	old_value = scratch_widgets_git_gutter_renderer_get_project (self);
	if (old_value != value) {
		ScratchFolderManagerProjectFolderItem* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_project);
		self->priv->_project = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, scratch_widgets_git_gutter_renderer_properties[SCRATCH_WIDGETS_GIT_GUTTER_RENDERER_PROJECT_PROPERTY]);
	}
}

static GdkRGBA*
_vala_GdkRGBA_copy (GdkRGBA* self)
{
	return g_boxed_copy (gdk_rgba_get_type (), self);
}

static GObject *
scratch_widgets_git_gutter_renderer_constructor (GType type,
                                                 guint n_construct_properties,
                                                 GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	ScratchWidgetsGitGutterRenderer * self;
	GeeHashMap* _tmp0_;
	GeeHashMap* _tmp1_;
	parent_class = G_OBJECT_CLASS (scratch_widgets_git_gutter_renderer_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SCRATCH_WIDGETS_TYPE_GIT_GUTTER_RENDERER, ScratchWidgetsGitGutterRenderer);
	_tmp0_ = gee_hash_map_new (G_TYPE_INT, NULL, NULL, SCRATCH_SERVICES_TYPE_VC_STATUS, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_g_object_unref0 (self->line_status_map);
	self->line_status_map = _tmp0_;
	_tmp1_ = gee_hash_map_new (SCRATCH_SERVICES_TYPE_VC_STATUS, NULL, NULL, gdk_rgba_get_type (), (GBoxedCopyFunc) _vala_GdkRGBA_copy, (GDestroyNotify) _vala_GdkRGBA_free, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_g_object_unref0 (self->status_color_map);
	self->status_color_map = _tmp1_;
	gtk_source_gutter_renderer_set_size ((GtkSourceGutterRenderer*) self, 5);
	gtk_source_gutter_renderer_set_visible ((GtkSourceGutterRenderer*) self, TRUE);
	return obj;
}

static void
scratch_widgets_git_gutter_renderer_class_init (ScratchWidgetsGitGutterRendererClass * klass,
                                                gpointer klass_data)
{
	GtkSourceStyleSchemeManager* _tmp0_;
	GtkSourceStyleScheme* _tmp1_;
	GtkSourceStyleScheme* _tmp2_;
	scratch_widgets_git_gutter_renderer_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ScratchWidgetsGitGutterRenderer_private_offset);
	((GtkSourceGutterRendererClass *) klass)->draw = (void (*) (GtkSourceGutterRenderer*, cairo_t*, GdkRectangle*, GdkRectangle*, GtkTextIter*, GtkTextIter*, GtkSourceGutterRendererState)) scratch_widgets_git_gutter_renderer_real_draw;
	G_OBJECT_CLASS (klass)->get_property = _vala_scratch_widgets_git_gutter_renderer_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_scratch_widgets_git_gutter_renderer_set_property;
	G_OBJECT_CLASS (klass)->constructor = scratch_widgets_git_gutter_renderer_constructor;
	G_OBJECT_CLASS (klass)->finalize = scratch_widgets_git_gutter_renderer_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_WIDGETS_GIT_GUTTER_RENDERER_PROJECT_PROPERTY, scratch_widgets_git_gutter_renderer_properties[SCRATCH_WIDGETS_GIT_GUTTER_RENDERER_PROJECT_PROPERTY] = g_param_spec_object ("project", "project", "project", SCRATCH_FOLDER_MANAGER_TYPE_PROJECT_FOLDER_ITEM, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	_tmp0_ = gtk_source_style_scheme_manager_get_default ();
	_tmp1_ = gtk_source_style_scheme_manager_get_scheme (_tmp0_, "classic");
	_tmp2_ = _g_object_ref0 (_tmp1_);
	_g_object_unref0 (scratch_widgets_git_gutter_renderer_fallback_scheme);
	scratch_widgets_git_gutter_renderer_fallback_scheme = _tmp2_;
}

static void
scratch_widgets_git_gutter_renderer_instance_init (ScratchWidgetsGitGutterRenderer * self,
                                                   gpointer klass)
{
	self->priv = scratch_widgets_git_gutter_renderer_get_instance_private (self);
	self->priv->_project = NULL;
}

static void
scratch_widgets_git_gutter_renderer_finalize (GObject * obj)
{
	ScratchWidgetsGitGutterRenderer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SCRATCH_WIDGETS_TYPE_GIT_GUTTER_RENDERER, ScratchWidgetsGitGutterRenderer);
	_g_object_unref0 (self->line_status_map);
	_g_object_unref0 (self->status_color_map);
	_g_object_unref0 (self->priv->_project);
	G_OBJECT_CLASS (scratch_widgets_git_gutter_renderer_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
scratch_widgets_git_gutter_renderer_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ScratchWidgetsGitGutterRendererClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) scratch_widgets_git_gutter_renderer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ScratchWidgetsGitGutterRenderer), 0, (GInstanceInitFunc) scratch_widgets_git_gutter_renderer_instance_init, NULL };
	GType scratch_widgets_git_gutter_renderer_type_id;
	scratch_widgets_git_gutter_renderer_type_id = g_type_register_static (gtk_source_gutter_renderer_get_type (), "ScratchWidgetsGitGutterRenderer", &g_define_type_info, G_TYPE_FLAG_NONE);
	ScratchWidgetsGitGutterRenderer_private_offset = g_type_add_instance_private (scratch_widgets_git_gutter_renderer_type_id, sizeof (ScratchWidgetsGitGutterRendererPrivate));
	return scratch_widgets_git_gutter_renderer_type_id;
}

GType
scratch_widgets_git_gutter_renderer_get_type (void)
{
	static gsize scratch_widgets_git_gutter_renderer_type_id__once = 0;
	if (g_once_init_enter (&scratch_widgets_git_gutter_renderer_type_id__once)) {
		GType scratch_widgets_git_gutter_renderer_type_id;
		scratch_widgets_git_gutter_renderer_type_id = scratch_widgets_git_gutter_renderer_get_type_once ();
		g_once_init_leave (&scratch_widgets_git_gutter_renderer_type_id__once, scratch_widgets_git_gutter_renderer_type_id);
	}
	return scratch_widgets_git_gutter_renderer_type_id__once;
}

static void
_vala_scratch_widgets_git_gutter_renderer_get_property (GObject * object,
                                                        guint property_id,
                                                        GValue * value,
                                                        GParamSpec * pspec)
{
	ScratchWidgetsGitGutterRenderer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SCRATCH_WIDGETS_TYPE_GIT_GUTTER_RENDERER, ScratchWidgetsGitGutterRenderer);
	switch (property_id) {
		case SCRATCH_WIDGETS_GIT_GUTTER_RENDERER_PROJECT_PROPERTY:
		g_value_set_object (value, scratch_widgets_git_gutter_renderer_get_project (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_scratch_widgets_git_gutter_renderer_set_property (GObject * object,
                                                        guint property_id,
                                                        const GValue * value,
                                                        GParamSpec * pspec)
{
	ScratchWidgetsGitGutterRenderer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SCRATCH_WIDGETS_TYPE_GIT_GUTTER_RENDERER, ScratchWidgetsGitGutterRenderer);
	switch (property_id) {
		case SCRATCH_WIDGETS_GIT_GUTTER_RENDERER_PROJECT_PROPERTY:
		scratch_widgets_git_gutter_renderer_set_project (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

