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

/*
* Copyright (c) 2009-2013 Yorba Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/

#include <glib-object.h>
#include <gdk/gdk.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <pango/pango.h>
#include "io.elementary.photos.h"
#include <gtk/gtk.h>
#include <gobject/gvaluecollector.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

#define TYPE_CHECKERBOARD_ITEM_TEXT (checkerboard_item_text_get_type ())
#define CHECKERBOARD_ITEM_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHECKERBOARD_ITEM_TEXT, CheckerboardItemText))
#define CHECKERBOARD_ITEM_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHECKERBOARD_ITEM_TEXT, CheckerboardItemTextClass))
#define IS_CHECKERBOARD_ITEM_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHECKERBOARD_ITEM_TEXT))
#define IS_CHECKERBOARD_ITEM_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHECKERBOARD_ITEM_TEXT))
#define CHECKERBOARD_ITEM_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHECKERBOARD_ITEM_TEXT, CheckerboardItemTextClass))

typedef struct _CheckerboardItemText CheckerboardItemText;
typedef struct _CheckerboardItemTextClass CheckerboardItemTextClass;
typedef struct _CheckerboardItemTextPrivate CheckerboardItemTextPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _ParamSpecCheckerboardItemText ParamSpecCheckerboardItemText;

struct _CheckerboardItemText {
	GTypeInstance parent_instance;
	volatile int ref_count;
	CheckerboardItemTextPrivate * priv;
	GdkRectangle allocation;
};

struct _CheckerboardItemTextClass {
	GTypeClass parent_class;
	void (*finalize) (CheckerboardItemText *self);
};

struct _CheckerboardItemTextPrivate {
	gchar* text;
	gboolean marked_up;
	PangoAlignment alignment;
	PangoLayout* layout;
	gboolean single_line;
	gint height;
};

struct _ParamSpecCheckerboardItemText {
	GParamSpec parent_instance;
};

static gint CheckerboardItemText_private_offset;
static gpointer checkerboard_item_text_parent_class = NULL;
static gint checkerboard_item_text_one_line_height;
static gint checkerboard_item_text_one_line_height = 0;

VALA_EXTERN gpointer checkerboard_item_text_ref (gpointer instance);
VALA_EXTERN void checkerboard_item_text_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_checkerboard_item_text (const gchar* name,
                                               const gchar* nick,
                                               const gchar* blurb,
                                               GType object_type,
                                               GParamFlags flags);
VALA_EXTERN void value_set_checkerboard_item_text (GValue* value,
                                       gpointer v_object);
VALA_EXTERN void value_take_checkerboard_item_text (GValue* value,
                                        gpointer v_object);
VALA_EXTERN gpointer value_get_checkerboard_item_text (const GValue* value);
VALA_EXTERN GType checkerboard_item_text_get_type (void) G_GNUC_CONST ;
VALA_EXTERN CheckerboardItemText* checkerboard_item_text_new (const gchar* text,
                                                  PangoAlignment alignment,
                                                  gboolean marked_up);
VALA_EXTERN CheckerboardItemText* checkerboard_item_text_construct (GType object_type,
                                                        const gchar* text,
                                                        PangoAlignment alignment,
                                                        gboolean marked_up);
static gboolean checkerboard_item_text_is_single_line (CheckerboardItemText* self);
VALA_EXTERN gboolean checkerboard_item_text_is_marked_up (CheckerboardItemText* self);
VALA_EXTERN gboolean checkerboard_item_text_is_set_to (CheckerboardItemText* self,
                                           const gchar* text,
                                           gboolean marked_up,
                                           PangoAlignment alignment);
VALA_EXTERN gchar* checkerboard_item_text_get_text (CheckerboardItemText* self);
VALA_EXTERN gint checkerboard_item_text_get_height (CheckerboardItemText* self);
static void checkerboard_item_text_update_height (CheckerboardItemText* self);
VALA_EXTERN PangoLayout* checkerboard_item_text_get_pango_layout (CheckerboardItemText* self,
                                                      gint max_width);
static void checkerboard_item_text_create_pango (CheckerboardItemText* self);
VALA_EXTERN void checkerboard_item_text_clear_pango_layout (CheckerboardItemText* self);
static void checkerboard_item_text_finalize (CheckerboardItemText * obj);
static GType checkerboard_item_text_get_type_once (void);

static inline gpointer
checkerboard_item_text_get_instance_private (CheckerboardItemText* self)
{
	return G_STRUCT_MEMBER_P (self, CheckerboardItemText_private_offset);
}

CheckerboardItemText*
checkerboard_item_text_construct (GType object_type,
                                  const gchar* text,
                                  PangoAlignment alignment,
                                  gboolean marked_up)
{
	CheckerboardItemText* self = NULL;
	gchar* _tmp0_;
	g_return_val_if_fail (text != NULL, NULL);
	self = (CheckerboardItemText*) g_type_create_instance (object_type);
	_tmp0_ = g_strdup (text);
	_g_free0 (self->priv->text);
	self->priv->text = _tmp0_;
	self->priv->marked_up = marked_up;
	self->priv->alignment = alignment;
	self->priv->single_line = checkerboard_item_text_is_single_line (self);
	return self;
}

CheckerboardItemText*
checkerboard_item_text_new (const gchar* text,
                            PangoAlignment alignment,
                            gboolean marked_up)
{
	return checkerboard_item_text_construct (TYPE_CHECKERBOARD_ITEM_TEXT, text, alignment, marked_up);
}

static gboolean
checkerboard_item_text_is_single_line (CheckerboardItemText* self)
{
	const gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->text;
	result = !string_contains_char (_tmp0_, (gunichar) '\n');
	return result;
}

gboolean
checkerboard_item_text_is_marked_up (CheckerboardItemText* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->marked_up;
	return result;
}

gboolean
checkerboard_item_text_is_set_to (CheckerboardItemText* self,
                                  const gchar* text,
                                  gboolean marked_up,
                                  PangoAlignment alignment)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (text != NULL, FALSE);
	if (self->priv->marked_up == marked_up) {
		_tmp1_ = self->priv->alignment == alignment;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		const gchar* _tmp2_;
		_tmp2_ = self->priv->text;
		_tmp0_ = g_strcmp0 (_tmp2_, text) == 0;
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

gchar*
checkerboard_item_text_get_text (CheckerboardItemText* self)
{
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->text;
	_tmp1_ = g_strdup (_tmp0_);
	result = _tmp1_;
	return result;
}

gint
checkerboard_item_text_get_height (CheckerboardItemText* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	if (self->priv->height == 0) {
		checkerboard_item_text_update_height (self);
	}
	result = self->priv->height;
	return result;
}

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

PangoLayout*
checkerboard_item_text_get_pango_layout (CheckerboardItemText* self,
                                         gint max_width)
{
	PangoLayout* _tmp0_;
	PangoLayout* _tmp2_;
	PangoLayout* _tmp3_;
	PangoLayout* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->layout;
	if (_tmp0_ == NULL) {
		checkerboard_item_text_create_pango (self);
	}
	if (max_width > 0) {
		PangoLayout* _tmp1_;
		_tmp1_ = self->priv->layout;
		pango_layout_set_width (_tmp1_, max_width * PANGO_SCALE);
	}
	_tmp2_ = self->priv->layout;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}

void
checkerboard_item_text_clear_pango_layout (CheckerboardItemText* self)
{
	g_return_if_fail (self != NULL);
	_g_object_unref0 (self->priv->layout);
	self->priv->layout = NULL;
}

static void
checkerboard_item_text_update_height (CheckerboardItemText* self)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	if (checkerboard_item_text_one_line_height != 0) {
		_tmp0_ = self->priv->single_line;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		self->priv->height = checkerboard_item_text_one_line_height;
	} else {
		checkerboard_item_text_create_pango (self);
	}
}

static void
checkerboard_item_text_create_pango (CheckerboardItemText* self)
{
	AppWindow* _tmp0_;
	AppWindow* _tmp1_;
	PangoLayout* _tmp2_;
	PangoLayout* _tmp7_;
	PangoLayout* _tmp8_;
	gboolean _tmp9_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp0_ = app_window_get_instance ();
	_tmp1_ = _tmp0_;
	_tmp2_ = gtk_widget_create_pango_layout ((GtkWidget*) _tmp1_, NULL);
	_g_object_unref0 (self->priv->layout);
	self->priv->layout = _tmp2_;
	_g_object_unref0 (_tmp1_);
	if (!self->priv->marked_up) {
		PangoLayout* _tmp3_;
		const gchar* _tmp4_;
		_tmp3_ = self->priv->layout;
		_tmp4_ = self->priv->text;
		pango_layout_set_text (_tmp3_, _tmp4_, -1);
	} else {
		PangoLayout* _tmp5_;
		const gchar* _tmp6_;
		_tmp5_ = self->priv->layout;
		_tmp6_ = self->priv->text;
		pango_layout_set_markup (_tmp5_, _tmp6_, -1);
	}
	_tmp7_ = self->priv->layout;
	pango_layout_set_ellipsize (_tmp7_, PANGO_ELLIPSIZE_END);
	_tmp8_ = self->priv->layout;
	pango_layout_set_alignment (_tmp8_, self->priv->alignment);
	if (checkerboard_item_text_one_line_height != 0) {
		_tmp9_ = self->priv->single_line;
	} else {
		_tmp9_ = FALSE;
	}
	if (_tmp9_) {
		self->priv->height = checkerboard_item_text_one_line_height;
	} else {
		gint width = 0;
		PangoLayout* _tmp10_;
		gint _tmp11_ = 0;
		gint _tmp12_ = 0;
		gboolean _tmp13_ = FALSE;
		_tmp10_ = self->priv->layout;
		pango_layout_get_pixel_size (_tmp10_, &_tmp11_, &_tmp12_);
		width = _tmp11_;
		self->priv->height = _tmp12_;
		if (checkerboard_item_text_one_line_height == 0) {
			_tmp13_ = self->priv->single_line;
		} else {
			_tmp13_ = FALSE;
		}
		if (_tmp13_) {
			checkerboard_item_text_one_line_height = self->priv->height;
		}
	}
}

static void
value_checkerboard_item_text_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
value_checkerboard_item_text_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		checkerboard_item_text_unref (value->data[0].v_pointer);
	}
}

static void
value_checkerboard_item_text_copy_value (const GValue* src_value,
                                         GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = checkerboard_item_text_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
value_checkerboard_item_text_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
value_checkerboard_item_text_collect_value (GValue* value,
                                            guint n_collect_values,
                                            GTypeCValue* collect_values,
                                            guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		CheckerboardItemText * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = checkerboard_item_text_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
value_checkerboard_item_text_lcopy_value (const GValue* value,
                                          guint n_collect_values,
                                          GTypeCValue* collect_values,
                                          guint collect_flags)
{
	CheckerboardItemText ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = checkerboard_item_text_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
param_spec_checkerboard_item_text (const gchar* name,
                                   const gchar* nick,
                                   const gchar* blurb,
                                   GType object_type,
                                   GParamFlags flags)
{
	ParamSpecCheckerboardItemText* spec;
	g_return_val_if_fail (g_type_is_a (object_type, TYPE_CHECKERBOARD_ITEM_TEXT), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
value_get_checkerboard_item_text (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_CHECKERBOARD_ITEM_TEXT), NULL);
	return value->data[0].v_pointer;
}

void
value_set_checkerboard_item_text (GValue* value,
                                  gpointer v_object)
{
	CheckerboardItemText * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_CHECKERBOARD_ITEM_TEXT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_CHECKERBOARD_ITEM_TEXT));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		checkerboard_item_text_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		checkerboard_item_text_unref (old);
	}
}

void
value_take_checkerboard_item_text (GValue* value,
                                   gpointer v_object)
{
	CheckerboardItemText * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_CHECKERBOARD_ITEM_TEXT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_CHECKERBOARD_ITEM_TEXT));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		checkerboard_item_text_unref (old);
	}
}

static void
checkerboard_item_text_class_init (CheckerboardItemTextClass * klass,
                                   gpointer klass_data)
{
	checkerboard_item_text_parent_class = g_type_class_peek_parent (klass);
	((CheckerboardItemTextClass *) klass)->finalize = checkerboard_item_text_finalize;
	g_type_class_adjust_private_offset (klass, &CheckerboardItemText_private_offset);
}

static void
checkerboard_item_text_instance_init (CheckerboardItemText * self,
                                      gpointer klass)
{
	self->priv = checkerboard_item_text_get_instance_private (self);
	self->priv->layout = NULL;
	self->priv->single_line = TRUE;
	self->priv->height = 0;
	memset (&self->allocation, 0, sizeof (GdkRectangle));
	self->ref_count = 1;
}

static void
checkerboard_item_text_finalize (CheckerboardItemText * obj)
{
	CheckerboardItemText * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_CHECKERBOARD_ITEM_TEXT, CheckerboardItemText);
	g_signal_handlers_destroy (self);
	_g_free0 (self->priv->text);
	_g_object_unref0 (self->priv->layout);
}

static GType
checkerboard_item_text_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { value_checkerboard_item_text_init, value_checkerboard_item_text_free_value, value_checkerboard_item_text_copy_value, value_checkerboard_item_text_peek_pointer, "p", value_checkerboard_item_text_collect_value, "p", value_checkerboard_item_text_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (CheckerboardItemTextClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) checkerboard_item_text_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (CheckerboardItemText), 0, (GInstanceInitFunc) checkerboard_item_text_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType checkerboard_item_text_type_id;
	checkerboard_item_text_type_id = g_type_register_fundamental (g_type_fundamental_next (), "CheckerboardItemText", &g_define_type_info, &g_define_type_fundamental_info, 0);
	CheckerboardItemText_private_offset = g_type_add_instance_private (checkerboard_item_text_type_id, sizeof (CheckerboardItemTextPrivate));
	return checkerboard_item_text_type_id;
}

GType
checkerboard_item_text_get_type (void)
{
	static volatile gsize checkerboard_item_text_type_id__once = 0;
	if (g_once_init_enter (&checkerboard_item_text_type_id__once)) {
		GType checkerboard_item_text_type_id;
		checkerboard_item_text_type_id = checkerboard_item_text_get_type_once ();
		g_once_init_leave (&checkerboard_item_text_type_id__once, checkerboard_item_text_type_id);
	}
	return checkerboard_item_text_type_id__once;
}

gpointer
checkerboard_item_text_ref (gpointer instance)
{
	CheckerboardItemText * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
checkerboard_item_text_unref (gpointer instance)
{
	CheckerboardItemText * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		CHECKERBOARD_ITEM_TEXT_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

