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

#include "codecore.h"
#include <gee.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <gtksourceview/gtksource.h>
#include <gdk/gdk.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

enum  {
	SCRATCH_WIDGETS_NAV_MARK_GUTTER_RENDERER_0_PROPERTY,
	SCRATCH_WIDGETS_NAV_MARK_GUTTER_RENDERER_BUFFER_PROPERTY,
	SCRATCH_WIDGETS_NAV_MARK_GUTTER_RENDERER_HAS_MARKS_PROPERTY,
	SCRATCH_WIDGETS_NAV_MARK_GUTTER_RENDERER_NUM_PROPERTIES
};
static GParamSpec* scratch_widgets_nav_mark_gutter_renderer_properties[SCRATCH_WIDGETS_NAV_MARK_GUTTER_RENDERER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define __vala_GtkTextIter_free0(var) ((var == NULL) ? NULL : (var = (_vala_GtkTextIter_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _ScratchWidgetsNavMarkGutterRendererPrivate {
	GeeArrayList* mark_list;
	GeeList* sorted_line_list;
	GtkTextBuffer* _buffer;
};

static gint ScratchWidgetsNavMarkGutterRenderer_private_offset;
static gpointer scratch_widgets_nav_mark_gutter_renderer_parent_class = NULL;
static gint scratch_widgets_nav_mark_gutter_renderer_navmark_number;
static gint scratch_widgets_nav_mark_gutter_renderer_navmark_number = 0;

static gint scratch_widgets_nav_mark_gutter_renderer_get_next_navmark_number (void);
static void scratch_widgets_nav_mark_gutter_renderer_add_mark (ScratchWidgetsNavMarkGutterRenderer* self,
                                                        GtkTextMark* mark);
static void scratch_widgets_nav_mark_gutter_renderer_purge_and_sort_mark_list (ScratchWidgetsNavMarkGutterRenderer* self);
static void _vala_GtkTextIter_free (GtkTextIter* self);
static GtkTextIter* _vala_GtkTextIter_copy (GtkTextIter* self);
static gint scratch_widgets_nav_mark_gutter_renderer_get_line_from_mark (ScratchWidgetsNavMarkGutterRenderer* self,
                                                                  GtkTextMark* mark);
static void scratch_widgets_nav_mark_gutter_renderer_real_query_data (GtkSourceGutterRenderer* base,
                                                               GtkTextIter* start,
                                                               GtkTextIter* end,
                                                               GtkSourceGutterRendererState state);
static void scratch_widgets_nav_mark_gutter_renderer_real_activate (GtkSourceGutterRenderer* base,
                                                             GtkTextIter* iter,
                                                             GdkRectangle* rect,
                                                             GdkEvent* event);
static gboolean scratch_widgets_nav_mark_gutter_renderer_real_query_activatable (GtkSourceGutterRenderer* base,
                                                                          GtkTextIter* iter,
                                                                          GdkRectangle* rect,
                                                                          GdkEvent* event);
static GObject * scratch_widgets_nav_mark_gutter_renderer_constructor (GType type,
                                                                guint n_construct_properties,
                                                                GObjectConstructParam * construct_properties);
static void scratch_widgets_nav_mark_gutter_renderer_finalize (GObject * obj);
static GType scratch_widgets_nav_mark_gutter_renderer_get_type_once (void);
static void _vala_scratch_widgets_nav_mark_gutter_renderer_get_property (GObject * object,
                                                                  guint property_id,
                                                                  GValue * value,
                                                                  GParamSpec * pspec);
static void _vala_scratch_widgets_nav_mark_gutter_renderer_set_property (GObject * object,
                                                                  guint property_id,
                                                                  const GValue * value,
                                                                  GParamSpec * pspec);

static inline gpointer
scratch_widgets_nav_mark_gutter_renderer_get_instance_private (ScratchWidgetsNavMarkGutterRenderer* self)
{
	return G_STRUCT_MEMBER_P (self, ScratchWidgetsNavMarkGutterRenderer_private_offset);
}

static gint
scratch_widgets_nav_mark_gutter_renderer_get_next_navmark_number (void)
{
	gint _tmp0_;
	gint result;
	_tmp0_ = scratch_widgets_nav_mark_gutter_renderer_navmark_number;
	scratch_widgets_nav_mark_gutter_renderer_navmark_number = _tmp0_ + 1;
	result = _tmp0_;
	return result;
}

ScratchWidgetsNavMarkGutterRenderer*
scratch_widgets_nav_mark_gutter_renderer_construct (GType object_type,
                                                    GtkTextBuffer* buffer)
{
	ScratchWidgetsNavMarkGutterRenderer * self = NULL;
	g_return_val_if_fail (buffer != NULL, NULL);
	self = (ScratchWidgetsNavMarkGutterRenderer*) g_object_new (object_type, "buffer", buffer, NULL);
	return self;
}

ScratchWidgetsNavMarkGutterRenderer*
scratch_widgets_nav_mark_gutter_renderer_new (GtkTextBuffer* buffer)
{
	return scratch_widgets_nav_mark_gutter_renderer_construct (SCRATCH_WIDGETS_TYPE_NAV_MARK_GUTTER_RENDERER, buffer);
}

static void
scratch_widgets_nav_mark_gutter_renderer_add_mark (ScratchWidgetsNavMarkGutterRenderer* self,
                                                   GtkTextMark* mark)
{
	GeeArrayList* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (mark != NULL);
	_tmp0_ = self->priv->mark_list;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp0_, mark);
	scratch_widgets_nav_mark_gutter_renderer_purge_and_sort_mark_list (self);
}

void
scratch_widgets_nav_mark_gutter_renderer_remove_mark (ScratchWidgetsNavMarkGutterRenderer* self,
                                                      GtkTextMark* mark)
{
	GeeArrayList* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (mark != NULL);
	_tmp0_ = self->priv->mark_list;
	gee_abstract_collection_remove ((GeeAbstractCollection*) _tmp0_, mark);
	scratch_widgets_nav_mark_gutter_renderer_purge_and_sort_mark_list (self);
}

static void
_vala_GtkTextIter_free (GtkTextIter* self)
{
	g_boxed_free (gtk_text_iter_get_type (), self);
}

static GtkTextIter*
_vala_GtkTextIter_copy (GtkTextIter* self)
{
	return g_boxed_copy (gtk_text_iter_get_type (), self);
}

static gpointer
__vala_GtkTextIter_copy0 (gpointer self)
{
	return self ? _vala_GtkTextIter_copy (self) : NULL;
}

void
scratch_widgets_nav_mark_gutter_renderer_get_nearest_marked_line (ScratchWidgetsNavMarkGutterRenderer* self,
                                                                  gint current_line,
                                                                  gboolean before,
                                                                  gint* nearest_line)
{
	gint _vala_nearest_line = 0;
	gint _tmp0_ = 0;
	GtkTextIter* iter = NULL;
	gboolean _tmp21_ = FALSE;
	g_return_if_fail (self != NULL);
	if (before) {
		_tmp0_ = -1;
	} else {
		_tmp0_ = G_MAXINT;
	}
	_vala_nearest_line = _tmp0_;
	scratch_widgets_nav_mark_gutter_renderer_purge_and_sort_mark_list (self);
	{
		GeeArrayList* _mark_list = NULL;
		GeeArrayList* _tmp1_;
		gint _mark_size = 0;
		GeeArrayList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _mark_index = 0;
		_tmp1_ = self->priv->mark_list;
		_mark_list = _tmp1_;
		_tmp2_ = _mark_list;
		_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp2_);
		_tmp4_ = _tmp3_;
		_mark_size = _tmp4_;
		_mark_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			GtkTextMark* mark = NULL;
			GeeArrayList* _tmp7_;
			gpointer _tmp8_;
			GtkTextBuffer* _tmp9_;
			GtkTextMark* _tmp10_;
			GtkTextIter _tmp11_ = {0};
			GtkTextIter _tmp12_;
			GtkTextIter* _tmp13_;
			GtkTextIter* _tmp14_;
			_mark_index = _mark_index + 1;
			_tmp5_ = _mark_index;
			_tmp6_ = _mark_size;
			if (!(_tmp5_ < _tmp6_)) {
				break;
			}
			_tmp7_ = _mark_list;
			_tmp8_ = gee_abstract_list_get ((GeeAbstractList*) _tmp7_, _mark_index);
			mark = (GtkTextMark*) _tmp8_;
			_tmp9_ = self->priv->_buffer;
			_tmp10_ = mark;
			gtk_text_buffer_get_iter_at_mark (_tmp9_, &_tmp11_, _tmp10_);
			__vala_GtkTextIter_free0 (iter);
			_tmp12_ = _tmp11_;
			_tmp13_ = __vala_GtkTextIter_copy0 (&_tmp12_);
			iter = _tmp13_;
			_tmp14_ = iter;
			if (_tmp14_ != NULL) {
				gint line = 0;
				GtkTextIter* _tmp15_;
				gboolean _tmp16_ = FALSE;
				gboolean _tmp17_ = FALSE;
				gboolean _tmp18_ = FALSE;
				_tmp15_ = iter;
				line = gtk_text_iter_get_line (_tmp15_);
				if (before) {
					_tmp18_ = line < current_line;
				} else {
					_tmp18_ = FALSE;
				}
				if (_tmp18_) {
					_tmp17_ = line > _vala_nearest_line;
				} else {
					_tmp17_ = FALSE;
				}
				if (_tmp17_) {
					_tmp16_ = TRUE;
				} else {
					gboolean _tmp19_ = FALSE;
					gboolean _tmp20_ = FALSE;
					if (!before) {
						_tmp20_ = line > current_line;
					} else {
						_tmp20_ = FALSE;
					}
					if (_tmp20_) {
						_tmp19_ = line < _vala_nearest_line;
					} else {
						_tmp19_ = FALSE;
					}
					_tmp16_ = _tmp19_;
				}
				if (_tmp16_) {
					_vala_nearest_line = line;
				}
			}
			_g_object_unref0 (mark);
		}
	}
	if (_vala_nearest_line < 0) {
		_tmp21_ = TRUE;
	} else {
		_tmp21_ = _vala_nearest_line == G_MAXINT;
	}
	if (_tmp21_) {
		_vala_nearest_line = current_line;
	}
	__vala_GtkTextIter_free0 (iter);
	if (nearest_line) {
		*nearest_line = _vala_nearest_line;
	}
}

gboolean
scratch_widgets_nav_mark_gutter_renderer_has_mark_at_line (ScratchWidgetsNavMarkGutterRenderer* self,
                                                           gint line)
{
	GeeList* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->sorted_line_list;
	result = gee_collection_contains ((GeeCollection*) _tmp0_, (gpointer) ((gintptr) line));
	return result;
}

static gint
scratch_widgets_nav_mark_gutter_renderer_get_line_from_mark (ScratchWidgetsNavMarkGutterRenderer* self,
                                                             GtkTextMark* mark)
{
	GtkTextIter* iter = NULL;
	GtkTextBuffer* _tmp0_;
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_;
	GtkTextIter* _tmp3_;
	GtkTextIter* _tmp4_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	g_return_val_if_fail (mark != NULL, -1);
	_vala_return_val_if_fail (!gtk_text_mark_get_deleted (mark), "!mark.get_deleted ()", -1);
	iter = NULL;
	_tmp0_ = self->priv->_buffer;
	gtk_text_buffer_get_iter_at_mark (_tmp0_, &_tmp1_, mark);
	__vala_GtkTextIter_free0 (iter);
	_tmp2_ = _tmp1_;
	_tmp3_ = __vala_GtkTextIter_copy0 (&_tmp2_);
	iter = _tmp3_;
	_tmp4_ = iter;
	result = gtk_text_iter_get_line (_tmp4_);
	__vala_GtkTextIter_free0 (iter);
	return result;
}

static void
scratch_widgets_nav_mark_gutter_renderer_purge_and_sort_mark_list (ScratchWidgetsNavMarkGutterRenderer* self)
{
	GList* to_delete = NULL;
	GList* _tmp10_;
	GeeList* _tmp13_;
	GList* _tmp26_;
	GeeList* _tmp31_;
	g_return_if_fail (self != NULL);
	to_delete = NULL;
	{
		GeeArrayList* _mark_list = NULL;
		GeeArrayList* _tmp0_;
		gint _mark_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _mark_index = 0;
		_tmp0_ = self->priv->mark_list;
		_mark_list = _tmp0_;
		_tmp1_ = _mark_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_mark_size = _tmp3_;
		_mark_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			GtkTextMark* mark = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			GtkTextMark* _tmp8_;
			_mark_index = _mark_index + 1;
			_tmp4_ = _mark_index;
			_tmp5_ = _mark_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _mark_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _mark_index);
			mark = (GtkTextMark*) _tmp7_;
			_tmp8_ = mark;
			if (gtk_text_mark_get_deleted (_tmp8_)) {
				GtkTextMark* _tmp9_;
				_tmp9_ = mark;
				to_delete = g_list_append (to_delete, _tmp9_);
			}
			_g_object_unref0 (mark);
		}
	}
	_tmp10_ = to_delete;
	{
		GList* mark_collection = NULL;
		GList* mark_it = NULL;
		mark_collection = _tmp10_;
		for (mark_it = mark_collection; mark_it != NULL; mark_it = mark_it->next) {
			GtkTextMark* mark = NULL;
			mark = (GtkTextMark*) mark_it->data;
			{
				GeeArrayList* _tmp11_;
				GtkTextMark* _tmp12_;
				_tmp11_ = self->priv->mark_list;
				_tmp12_ = mark;
				gee_abstract_collection_remove ((GeeAbstractCollection*) _tmp11_, _tmp12_);
			}
		}
	}
	_tmp13_ = self->priv->sorted_line_list;
	gee_collection_clear ((GeeCollection*) _tmp13_);
	(to_delete == NULL) ? NULL : (to_delete = (g_list_free (to_delete), NULL));
	to_delete = NULL;
	{
		GeeArrayList* _mark_list = NULL;
		GeeArrayList* _tmp14_;
		gint _mark_size = 0;
		GeeArrayList* _tmp15_;
		gint _tmp16_;
		gint _tmp17_;
		gint _mark_index = 0;
		_tmp14_ = self->priv->mark_list;
		_mark_list = _tmp14_;
		_tmp15_ = _mark_list;
		_tmp16_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp15_);
		_tmp17_ = _tmp16_;
		_mark_size = _tmp17_;
		_mark_index = -1;
		while (TRUE) {
			gint _tmp18_;
			gint _tmp19_;
			GtkTextMark* mark = NULL;
			GeeArrayList* _tmp20_;
			gpointer _tmp21_;
			gint line = 0;
			GtkTextMark* _tmp22_;
			GeeList* _tmp23_;
			_mark_index = _mark_index + 1;
			_tmp18_ = _mark_index;
			_tmp19_ = _mark_size;
			if (!(_tmp18_ < _tmp19_)) {
				break;
			}
			_tmp20_ = _mark_list;
			_tmp21_ = gee_abstract_list_get ((GeeAbstractList*) _tmp20_, _mark_index);
			mark = (GtkTextMark*) _tmp21_;
			_tmp22_ = mark;
			line = scratch_widgets_nav_mark_gutter_renderer_get_line_from_mark (self, _tmp22_);
			_tmp23_ = self->priv->sorted_line_list;
			if (!gee_collection_contains ((GeeCollection*) _tmp23_, (gpointer) ((gintptr) line))) {
				GeeList* _tmp24_;
				_tmp24_ = self->priv->sorted_line_list;
				gee_collection_add ((GeeCollection*) _tmp24_, (gpointer) ((gintptr) line));
			} else {
				GtkTextMark* _tmp25_;
				_tmp25_ = mark;
				to_delete = g_list_append (to_delete, _tmp25_);
			}
			_g_object_unref0 (mark);
		}
	}
	_tmp26_ = to_delete;
	{
		GList* mark_collection = NULL;
		GList* mark_it = NULL;
		mark_collection = _tmp26_;
		for (mark_it = mark_collection; mark_it != NULL; mark_it = mark_it->next) {
			GtkTextMark* mark = NULL;
			mark = (GtkTextMark*) mark_it->data;
			{
				GtkTextBuffer* _tmp27_;
				GtkTextMark* _tmp28_;
				GeeArrayList* _tmp29_;
				GtkTextMark* _tmp30_;
				_tmp27_ = self->priv->_buffer;
				_tmp28_ = mark;
				gtk_text_buffer_delete_mark (_tmp27_, _tmp28_);
				_tmp29_ = self->priv->mark_list;
				_tmp30_ = mark;
				gee_abstract_collection_remove ((GeeAbstractCollection*) _tmp29_, _tmp30_);
			}
		}
	}
	_tmp31_ = self->priv->sorted_line_list;
	gee_list_sort (_tmp31_, NULL, NULL, NULL);
	(to_delete == NULL) ? NULL : (to_delete = (g_list_free (to_delete), NULL));
}

void
scratch_widgets_nav_mark_gutter_renderer_delete_mark_at_line (ScratchWidgetsNavMarkGutterRenderer* self,
                                                              gint line)
{
	g_return_if_fail (self != NULL);
	{
		GeeArrayList* _mark_list = NULL;
		GeeArrayList* _tmp0_;
		gint _mark_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _mark_index = 0;
		_tmp0_ = self->priv->mark_list;
		_mark_list = _tmp0_;
		_tmp1_ = _mark_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_mark_size = _tmp3_;
		_mark_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			GtkTextMark* mark = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			GtkTextMark* _tmp8_;
			_mark_index = _mark_index + 1;
			_tmp4_ = _mark_index;
			_tmp5_ = _mark_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _mark_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _mark_index);
			mark = (GtkTextMark*) _tmp7_;
			_tmp8_ = mark;
			if (line == scratch_widgets_nav_mark_gutter_renderer_get_line_from_mark (self, _tmp8_)) {
				GtkTextBuffer* _tmp9_;
				GtkTextMark* _tmp10_;
				GeeArrayList* _tmp11_;
				GtkTextMark* _tmp12_;
				_tmp9_ = self->priv->_buffer;
				_tmp10_ = mark;
				gtk_text_buffer_delete_mark (_tmp9_, _tmp10_);
				_tmp11_ = self->priv->mark_list;
				_tmp12_ = mark;
				gee_abstract_collection_remove ((GeeAbstractCollection*) _tmp11_, _tmp12_);
				gtk_source_gutter_renderer_queue_draw ((GtkSourceGutterRenderer*) self);
				_g_object_unref0 (mark);
				break;
			}
			_g_object_unref0 (mark);
		}
	}
}

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

void
scratch_widgets_nav_mark_gutter_renderer_add_mark_at_line (ScratchWidgetsNavMarkGutterRenderer* self,
                                                           gint line)
{
	GtkTextIter* iter = NULL;
	GtkTextBuffer* _tmp0_;
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_;
	GtkTextIter* _tmp3_;
	GtkTextMark* mark = NULL;
	GtkTextBuffer* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	GtkTextIter* _tmp7_;
	GtkTextIter _tmp8_;
	GtkTextMark* _tmp9_;
	GtkTextMark* _tmp10_;
	GtkTextMark* _tmp11_;
	GtkTextMark* _tmp12_;
	g_return_if_fail (self != NULL);
	if (scratch_widgets_nav_mark_gutter_renderer_has_mark_at_line (self, line)) {
		return;
	}
	iter = NULL;
	_tmp0_ = self->priv->_buffer;
	gtk_text_buffer_get_iter_at_line_offset (_tmp0_, &_tmp1_, line, 0);
	__vala_GtkTextIter_free0 (iter);
	_tmp2_ = _tmp1_;
	_tmp3_ = __vala_GtkTextIter_copy0 (&_tmp2_);
	iter = _tmp3_;
	_tmp4_ = self->priv->_buffer;
	_tmp5_ = g_strdup_printf ("NavMark%i", scratch_widgets_nav_mark_gutter_renderer_get_next_navmark_number ());
	_tmp6_ = _tmp5_;
	_tmp7_ = iter;
	_tmp8_ = *_tmp7_;
	_tmp9_ = gtk_text_buffer_create_mark (_tmp4_, _tmp6_, &_tmp8_, TRUE);
	_tmp10_ = _g_object_ref0 (_tmp9_);
	_tmp11_ = _tmp10_;
	_g_free0 (_tmp6_);
	mark = _tmp11_;
	_tmp12_ = mark;
	scratch_widgets_nav_mark_gutter_renderer_add_mark (self, _tmp12_);
	gtk_source_gutter_renderer_queue_draw ((GtkSourceGutterRenderer*) self);
	_g_object_unref0 (mark);
	__vala_GtkTextIter_free0 (iter);
}

static void
scratch_widgets_nav_mark_gutter_renderer_real_query_data (GtkSourceGutterRenderer* base,
                                                          GtkTextIter* start,
                                                          GtkTextIter* end,
                                                          GtkSourceGutterRendererState state)
{
	ScratchWidgetsNavMarkGutterRenderer * self;
	gint line = 0;
	GeeList* _tmp0_;
	self = (ScratchWidgetsNavMarkGutterRenderer*) base;
	g_return_if_fail (start != NULL);
	g_return_if_fail (end != NULL);
	line = gtk_text_iter_get_line (start);
	_tmp0_ = self->priv->sorted_line_list;
	if (gee_collection_contains ((GeeCollection*) _tmp0_, (gpointer) ((gintptr) line))) {
		gtk_source_gutter_renderer_pixbuf_set_icon_name ((GtkSourceGutterRendererPixbuf*) self, "edit-symbolic");
	} else {
		gtk_source_gutter_renderer_pixbuf_set_icon_name ((GtkSourceGutterRendererPixbuf*) self, "");
	}
}

static void
scratch_widgets_nav_mark_gutter_renderer_real_activate (GtkSourceGutterRenderer* base,
                                                        GtkTextIter* iter,
                                                        GdkRectangle* rect,
                                                        GdkEvent* event)
{
	ScratchWidgetsNavMarkGutterRenderer * self;
	self = (ScratchWidgetsNavMarkGutterRenderer*) base;
	g_return_if_fail (iter != NULL);
	g_return_if_fail (rect != NULL);
	g_return_if_fail (event != NULL);
	if (scratch_widgets_nav_mark_gutter_renderer_has_mark_at_line (self, gtk_text_iter_get_line (iter))) {
		scratch_widgets_nav_mark_gutter_renderer_delete_mark_at_line (self, gtk_text_iter_get_line (iter));
	} else {
		scratch_widgets_nav_mark_gutter_renderer_add_mark_at_line (self, gtk_text_iter_get_line (iter));
	}
	gtk_source_gutter_renderer_queue_draw ((GtkSourceGutterRenderer*) self);
}

static gboolean
scratch_widgets_nav_mark_gutter_renderer_real_query_activatable (GtkSourceGutterRenderer* base,
                                                                 GtkTextIter* iter,
                                                                 GdkRectangle* rect,
                                                                 GdkEvent* event)
{
	ScratchWidgetsNavMarkGutterRenderer * self;
	gboolean result;
	self = (ScratchWidgetsNavMarkGutterRenderer*) base;
	g_return_val_if_fail (iter != NULL, FALSE);
	g_return_val_if_fail (rect != NULL, FALSE);
	g_return_val_if_fail (event != NULL, FALSE);
	result = TRUE;
	return result;
}

GtkTextBuffer*
scratch_widgets_nav_mark_gutter_renderer_get_buffer (ScratchWidgetsNavMarkGutterRenderer* self)
{
	GtkTextBuffer* result;
	GtkTextBuffer* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_buffer;
	result = _tmp0_;
	return result;
}

static void
scratch_widgets_nav_mark_gutter_renderer_set_buffer (ScratchWidgetsNavMarkGutterRenderer* self,
                                                     GtkTextBuffer* value)
{
	GtkTextBuffer* old_value;
	g_return_if_fail (self != NULL);
	old_value = scratch_widgets_nav_mark_gutter_renderer_get_buffer (self);
	if (old_value != value) {
		GtkTextBuffer* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_buffer);
		self->priv->_buffer = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, scratch_widgets_nav_mark_gutter_renderer_properties[SCRATCH_WIDGETS_NAV_MARK_GUTTER_RENDERER_BUFFER_PROPERTY]);
	}
}

gboolean
scratch_widgets_nav_mark_gutter_renderer_get_has_marks (ScratchWidgetsNavMarkGutterRenderer* self)
{
	gboolean result;
	GeeArrayList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	g_return_val_if_fail (self != NULL, FALSE);
	scratch_widgets_nav_mark_gutter_renderer_purge_and_sort_mark_list (self);
	_tmp0_ = self->priv->mark_list;
	_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_ > 0;
	return result;
}

static GObject *
scratch_widgets_nav_mark_gutter_renderer_constructor (GType type,
                                                      guint n_construct_properties,
                                                      GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	ScratchWidgetsNavMarkGutterRenderer * self;
	GeeArrayList* _tmp0_;
	GeeArrayList* _tmp1_;
	parent_class = G_OBJECT_CLASS (scratch_widgets_nav_mark_gutter_renderer_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SCRATCH_WIDGETS_TYPE_NAV_MARK_GUTTER_RENDERER, ScratchWidgetsNavMarkGutterRenderer);
	_tmp0_ = gee_array_list_new (gtk_text_mark_get_type (), (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->mark_list);
	self->priv->mark_list = _tmp0_;
	_tmp1_ = gee_array_list_new (G_TYPE_INT, NULL, NULL, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->sorted_line_list);
	self->priv->sorted_line_list = (GeeList*) _tmp1_;
	gtk_source_gutter_renderer_set_size ((GtkSourceGutterRenderer*) self, 16);
	gtk_source_gutter_renderer_set_visible ((GtkSourceGutterRenderer*) self, TRUE);
	return obj;
}

static void
scratch_widgets_nav_mark_gutter_renderer_class_init (ScratchWidgetsNavMarkGutterRendererClass * klass,
                                                     gpointer klass_data)
{
	scratch_widgets_nav_mark_gutter_renderer_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ScratchWidgetsNavMarkGutterRenderer_private_offset);
	((GtkSourceGutterRendererClass *) klass)->query_data = (void (*) (GtkSourceGutterRenderer*, GtkTextIter*, GtkTextIter*, GtkSourceGutterRendererState)) scratch_widgets_nav_mark_gutter_renderer_real_query_data;
	((GtkSourceGutterRendererClass *) klass)->activate = (void (*) (GtkSourceGutterRenderer*, GtkTextIter*, GdkRectangle*, GdkEvent*)) scratch_widgets_nav_mark_gutter_renderer_real_activate;
	((GtkSourceGutterRendererClass *) klass)->query_activatable = (gboolean (*) (GtkSourceGutterRenderer*, GtkTextIter*, GdkRectangle*, GdkEvent*)) scratch_widgets_nav_mark_gutter_renderer_real_query_activatable;
	G_OBJECT_CLASS (klass)->get_property = _vala_scratch_widgets_nav_mark_gutter_renderer_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_scratch_widgets_nav_mark_gutter_renderer_set_property;
	G_OBJECT_CLASS (klass)->constructor = scratch_widgets_nav_mark_gutter_renderer_constructor;
	G_OBJECT_CLASS (klass)->finalize = scratch_widgets_nav_mark_gutter_renderer_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_WIDGETS_NAV_MARK_GUTTER_RENDERER_BUFFER_PROPERTY, scratch_widgets_nav_mark_gutter_renderer_properties[SCRATCH_WIDGETS_NAV_MARK_GUTTER_RENDERER_BUFFER_PROPERTY] = g_param_spec_object ("buffer", "buffer", "buffer", gtk_text_buffer_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), SCRATCH_WIDGETS_NAV_MARK_GUTTER_RENDERER_HAS_MARKS_PROPERTY, scratch_widgets_nav_mark_gutter_renderer_properties[SCRATCH_WIDGETS_NAV_MARK_GUTTER_RENDERER_HAS_MARKS_PROPERTY] = g_param_spec_boolean ("has-marks", "has-marks", "has-marks", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
scratch_widgets_nav_mark_gutter_renderer_instance_init (ScratchWidgetsNavMarkGutterRenderer * self,
                                                        gpointer klass)
{
	self->priv = scratch_widgets_nav_mark_gutter_renderer_get_instance_private (self);
}

static void
scratch_widgets_nav_mark_gutter_renderer_finalize (GObject * obj)
{
	ScratchWidgetsNavMarkGutterRenderer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SCRATCH_WIDGETS_TYPE_NAV_MARK_GUTTER_RENDERER, ScratchWidgetsNavMarkGutterRenderer);
	_g_object_unref0 (self->priv->mark_list);
	_g_object_unref0 (self->priv->sorted_line_list);
	_g_object_unref0 (self->priv->_buffer);
	G_OBJECT_CLASS (scratch_widgets_nav_mark_gutter_renderer_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
scratch_widgets_nav_mark_gutter_renderer_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ScratchWidgetsNavMarkGutterRendererClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) scratch_widgets_nav_mark_gutter_renderer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ScratchWidgetsNavMarkGutterRenderer), 0, (GInstanceInitFunc) scratch_widgets_nav_mark_gutter_renderer_instance_init, NULL };
	GType scratch_widgets_nav_mark_gutter_renderer_type_id;
	scratch_widgets_nav_mark_gutter_renderer_type_id = g_type_register_static (gtk_source_gutter_renderer_pixbuf_get_type (), "ScratchWidgetsNavMarkGutterRenderer", &g_define_type_info, G_TYPE_FLAG_NONE);
	ScratchWidgetsNavMarkGutterRenderer_private_offset = g_type_add_instance_private (scratch_widgets_nav_mark_gutter_renderer_type_id, sizeof (ScratchWidgetsNavMarkGutterRendererPrivate));
	return scratch_widgets_nav_mark_gutter_renderer_type_id;
}

GType
scratch_widgets_nav_mark_gutter_renderer_get_type (void)
{
	static gsize scratch_widgets_nav_mark_gutter_renderer_type_id__once = 0;
	if (g_once_init_enter (&scratch_widgets_nav_mark_gutter_renderer_type_id__once)) {
		GType scratch_widgets_nav_mark_gutter_renderer_type_id;
		scratch_widgets_nav_mark_gutter_renderer_type_id = scratch_widgets_nav_mark_gutter_renderer_get_type_once ();
		g_once_init_leave (&scratch_widgets_nav_mark_gutter_renderer_type_id__once, scratch_widgets_nav_mark_gutter_renderer_type_id);
	}
	return scratch_widgets_nav_mark_gutter_renderer_type_id__once;
}

static void
_vala_scratch_widgets_nav_mark_gutter_renderer_get_property (GObject * object,
                                                             guint property_id,
                                                             GValue * value,
                                                             GParamSpec * pspec)
{
	ScratchWidgetsNavMarkGutterRenderer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SCRATCH_WIDGETS_TYPE_NAV_MARK_GUTTER_RENDERER, ScratchWidgetsNavMarkGutterRenderer);
	switch (property_id) {
		case SCRATCH_WIDGETS_NAV_MARK_GUTTER_RENDERER_BUFFER_PROPERTY:
		g_value_set_object (value, scratch_widgets_nav_mark_gutter_renderer_get_buffer (self));
		break;
		case SCRATCH_WIDGETS_NAV_MARK_GUTTER_RENDERER_HAS_MARKS_PROPERTY:
		g_value_set_boolean (value, scratch_widgets_nav_mark_gutter_renderer_get_has_marks (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_scratch_widgets_nav_mark_gutter_renderer_set_property (GObject * object,
                                                             guint property_id,
                                                             const GValue * value,
                                                             GParamSpec * pspec)
{
	ScratchWidgetsNavMarkGutterRenderer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SCRATCH_WIDGETS_TYPE_NAV_MARK_GUTTER_RENDERER, ScratchWidgetsNavMarkGutterRenderer);
	switch (property_id) {
		case SCRATCH_WIDGETS_NAV_MARK_GUTTER_RENDERER_BUFFER_PROPERTY:
		scratch_widgets_nav_mark_gutter_renderer_set_buffer (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

