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

/* cell.vala
 *
 * Copyright 2022 Vojtěch Perník
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
 */

#include <glib-object.h>
#include <adwaita.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gtk/gtk.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

typedef enum  {
	WG_CELL_STATE_CORRECT,
	WG_CELL_STATE_WRONG,
	WG_CELL_STATE_WRONG_POSITION,
	WG_CELL_STATE_UNKNOWN,
	WG_CELL_STATE_NONE
} WGCellState;

#define WG_TYPE_CELL_STATE (wg_cell_state_get_type ())

#define WG_TYPE_CELL (wg_cell_get_type ())
#define WG_CELL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WG_TYPE_CELL, WGCell))
#define WG_CELL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WG_TYPE_CELL, WGCellClass))
#define WG_IS_CELL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WG_TYPE_CELL))
#define WG_IS_CELL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WG_TYPE_CELL))
#define WG_CELL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WG_TYPE_CELL, WGCellClass))

typedef struct _WGCell WGCell;
typedef struct _WGCellClass WGCellClass;
typedef struct _WGCellPrivate WGCellPrivate;
enum  {
	WG_CELL_0_PROPERTY,
	WG_CELL_CONTENT_PROPERTY,
	WG_CELL_STATE_PROPERTY,
	WG_CELL_FOCUSED_PROPERTY,
	WG_CELL_NUM_PROPERTIES
};
static GParamSpec* wg_cell_properties[WG_CELL_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)))

struct _WGCell {
	AdwBin parent_instance;
	WGCellPrivate * priv;
};

struct _WGCellClass {
	AdwBinClass parent_class;
};

struct _WGCellPrivate {
	gchar* _content;
	WGCellState _state;
	gboolean _focused;
};

static gint WGCell_private_offset;
static gpointer wg_cell_parent_class = NULL;

VALA_EXTERN GType wg_cell_state_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType wg_cell_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WGCell, g_object_unref)
static void wg_cell_update_styles (WGCell* self);
VALA_EXTERN gboolean wg_cell_get_focused (WGCell* self);
VALA_EXTERN WGCellState wg_cell_get_state (WGCell* self);
VALA_EXTERN WGCell* wg_cell_new (void);
VALA_EXTERN WGCell* wg_cell_construct (GType object_type);
VALA_EXTERN const gchar* wg_cell_get_content (WGCell* self);
VALA_EXTERN void wg_cell_set_content (WGCell* self,
                          const gchar* value);
VALA_EXTERN void wg_cell_set_state (WGCell* self,
                        WGCellState value);
VALA_EXTERN void wg_cell_set_focused (WGCell* self,
                          gboolean value);
static GObject * wg_cell_constructor (GType type,
                               guint n_construct_properties,
                               GObjectConstructParam * construct_properties);
static void _wg_cell_update_styles_g_object_notify (GObject* _sender,
                                             GParamSpec* pspec,
                                             gpointer self);
static void wg_cell_finalize (GObject * obj);
static GType wg_cell_get_type_once (void);
static void _vala_wg_cell_get_property (GObject * object,
                                 guint property_id,
                                 GValue * value,
                                 GParamSpec * pspec);
static void _vala_wg_cell_set_property (GObject * object,
                                 guint property_id,
                                 const GValue * value,
                                 GParamSpec * pspec);

static GType
wg_cell_state_get_type_once (void)
{
	static const GEnumValue values[] = {{WG_CELL_STATE_CORRECT, "WG_CELL_STATE_CORRECT", "correct"}, {WG_CELL_STATE_WRONG, "WG_CELL_STATE_WRONG", "wrong"}, {WG_CELL_STATE_WRONG_POSITION, "WG_CELL_STATE_WRONG_POSITION", "wrong-position"}, {WG_CELL_STATE_UNKNOWN, "WG_CELL_STATE_UNKNOWN", "unknown"}, {WG_CELL_STATE_NONE, "WG_CELL_STATE_NONE", "none"}, {0, NULL, NULL}};
	GType wg_cell_state_type_id;
	wg_cell_state_type_id = g_enum_register_static ("WGCellState", values);
	return wg_cell_state_type_id;
}

GType
wg_cell_state_get_type (void)
{
	static volatile gsize wg_cell_state_type_id__once = 0;
	if (g_once_init_enter (&wg_cell_state_type_id__once)) {
		GType wg_cell_state_type_id;
		wg_cell_state_type_id = wg_cell_state_get_type_once ();
		g_once_init_leave (&wg_cell_state_type_id__once, wg_cell_state_type_id);
	}
	return wg_cell_state_type_id__once;
}

static inline gpointer
wg_cell_get_instance_private (WGCell* self)
{
	return G_STRUCT_MEMBER_P (self, WGCell_private_offset);
}

static void
wg_cell_update_styles (WGCell* self)
{
	gboolean _tmp0_;
	WGCellState _tmp1_;
	g_return_if_fail (self != NULL);
	gtk_widget_remove_css_class ((GtkWidget*) self, "focused");
	gtk_widget_remove_css_class ((GtkWidget*) self, "correct");
	gtk_widget_remove_css_class ((GtkWidget*) self, "wrong");
	gtk_widget_remove_css_class ((GtkWidget*) self, "position");
	gtk_widget_remove_css_class ((GtkWidget*) self, "unknown");
	_tmp0_ = self->priv->_focused;
	if (_tmp0_) {
		gtk_widget_add_css_class ((GtkWidget*) self, "focused");
	}
	_tmp1_ = self->priv->_state;
	switch (_tmp1_) {
		case WG_CELL_STATE_CORRECT:
		{
			gtk_widget_add_css_class ((GtkWidget*) self, "correct");
			break;
		}
		case WG_CELL_STATE_WRONG:
		{
			gtk_widget_add_css_class ((GtkWidget*) self, "wrong");
			break;
		}
		case WG_CELL_STATE_WRONG_POSITION:
		{
			gtk_widget_add_css_class ((GtkWidget*) self, "position");
			break;
		}
		case WG_CELL_STATE_UNKNOWN:
		{
			gtk_widget_add_css_class ((GtkWidget*) self, "unknown");
			break;
		}
		case WG_CELL_STATE_NONE:
		{
			break;
		}
		default:
		break;
	}
}

WGCell*
wg_cell_construct (GType object_type)
{
	WGCell * self = NULL;
	self = (WGCell*) g_object_new (object_type, NULL);
	return self;
}

WGCell*
wg_cell_new (void)
{
	return wg_cell_construct (WG_TYPE_CELL);
}

const gchar*
wg_cell_get_content (WGCell* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_content;
	result = _tmp0_;
	return result;
}

void
wg_cell_set_content (WGCell* self,
                     const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = wg_cell_get_content (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_content);
		self->priv->_content = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, wg_cell_properties[WG_CELL_CONTENT_PROPERTY]);
	}
}

WGCellState
wg_cell_get_state (WGCell* self)
{
	WGCellState result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_state;
	return result;
}

void
wg_cell_set_state (WGCell* self,
                   WGCellState value)
{
	WGCellState old_value;
	g_return_if_fail (self != NULL);
	old_value = wg_cell_get_state (self);
	if (old_value != value) {
		self->priv->_state = value;
		g_object_notify_by_pspec ((GObject *) self, wg_cell_properties[WG_CELL_STATE_PROPERTY]);
	}
}

gboolean
wg_cell_get_focused (WGCell* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_focused;
	return result;
}

void
wg_cell_set_focused (WGCell* self,
                     gboolean value)
{
	gboolean old_value;
	g_return_if_fail (self != NULL);
	old_value = wg_cell_get_focused (self);
	if (old_value != value) {
		self->priv->_focused = value;
		g_object_notify_by_pspec ((GObject *) self, wg_cell_properties[WG_CELL_FOCUSED_PROPERTY]);
	}
}

static void
_wg_cell_update_styles_g_object_notify (GObject* _sender,
                                        GParamSpec* pspec,
                                        gpointer self)
{
	wg_cell_update_styles ((WGCell*) self);
}

static GObject *
wg_cell_constructor (GType type,
                     guint n_construct_properties,
                     GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	WGCell * self;
	GtkLabel* label = NULL;
	const gchar* _tmp0_;
	GtkLabel* _tmp1_;
	GtkLabel* _tmp2_;
	GtkLabel* _tmp3_;
	parent_class = G_OBJECT_CLASS (wg_cell_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WG_TYPE_CELL, WGCell);
	gtk_widget_add_css_class ((GtkWidget*) self, "cell");
	_tmp0_ = self->priv->_content;
	_tmp1_ = (GtkLabel*) gtk_label_new (_tmp0_);
	g_object_ref_sink (_tmp1_);
	label = _tmp1_;
	_tmp2_ = label;
	adw_bin_set_child ((AdwBin*) self, (GtkWidget*) _tmp2_);
	_tmp3_ = label;
	g_object_bind_property_with_closures ((GObject*) self, "content", (GObject*) _tmp3_, "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_object ((GObject*) self, "notify::state", (GCallback) _wg_cell_update_styles_g_object_notify, self, 0);
	g_signal_connect_object ((GObject*) self, "notify::focused", (GCallback) _wg_cell_update_styles_g_object_notify, self, 0);
	wg_cell_update_styles (self);
	_g_object_unref0 (label);
	return obj;
}

static void
wg_cell_class_init (WGCellClass * klass,
                    gpointer klass_data)
{
	wg_cell_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WGCell_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_wg_cell_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_wg_cell_set_property;
	G_OBJECT_CLASS (klass)->constructor = wg_cell_constructor;
	G_OBJECT_CLASS (klass)->finalize = wg_cell_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), WG_CELL_CONTENT_PROPERTY, wg_cell_properties[WG_CELL_CONTENT_PROPERTY] = g_param_spec_string ("content", "content", "content", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WG_CELL_STATE_PROPERTY, wg_cell_properties[WG_CELL_STATE_PROPERTY] = g_param_spec_enum ("state", "state", "state", WG_TYPE_CELL_STATE, WG_CELL_STATE_NONE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WG_CELL_FOCUSED_PROPERTY, wg_cell_properties[WG_CELL_FOCUSED_PROPERTY] = g_param_spec_boolean ("focused", "focused", "focused", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
wg_cell_instance_init (WGCell * self,
                       gpointer klass)
{
	gchar* _tmp0_;
	self->priv = wg_cell_get_instance_private (self);
	_tmp0_ = g_strdup ("");
	self->priv->_content = _tmp0_;
	self->priv->_state = WG_CELL_STATE_NONE;
	self->priv->_focused = FALSE;
}

static void
wg_cell_finalize (GObject * obj)
{
	WGCell * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WG_TYPE_CELL, WGCell);
	_g_free0 (self->priv->_content);
	G_OBJECT_CLASS (wg_cell_parent_class)->finalize (obj);
}

static GType
wg_cell_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WGCellClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) wg_cell_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WGCell), 0, (GInstanceInitFunc) wg_cell_instance_init, NULL };
	GType wg_cell_type_id;
	wg_cell_type_id = g_type_register_static (adw_bin_get_type (), "WGCell", &g_define_type_info, 0);
	WGCell_private_offset = g_type_add_instance_private (wg_cell_type_id, sizeof (WGCellPrivate));
	return wg_cell_type_id;
}

GType
wg_cell_get_type (void)
{
	static volatile gsize wg_cell_type_id__once = 0;
	if (g_once_init_enter (&wg_cell_type_id__once)) {
		GType wg_cell_type_id;
		wg_cell_type_id = wg_cell_get_type_once ();
		g_once_init_leave (&wg_cell_type_id__once, wg_cell_type_id);
	}
	return wg_cell_type_id__once;
}

static void
_vala_wg_cell_get_property (GObject * object,
                            guint property_id,
                            GValue * value,
                            GParamSpec * pspec)
{
	WGCell * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WG_TYPE_CELL, WGCell);
	switch (property_id) {
		case WG_CELL_CONTENT_PROPERTY:
		g_value_set_string (value, wg_cell_get_content (self));
		break;
		case WG_CELL_STATE_PROPERTY:
		g_value_set_enum (value, wg_cell_get_state (self));
		break;
		case WG_CELL_FOCUSED_PROPERTY:
		g_value_set_boolean (value, wg_cell_get_focused (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_wg_cell_set_property (GObject * object,
                            guint property_id,
                            const GValue * value,
                            GParamSpec * pspec)
{
	WGCell * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WG_TYPE_CELL, WGCell);
	switch (property_id) {
		case WG_CELL_CONTENT_PROPERTY:
		wg_cell_set_content (self, g_value_get_string (value));
		break;
		case WG_CELL_STATE_PROPERTY:
		wg_cell_set_state (self, g_value_get_enum (value));
		break;
		case WG_CELL_FOCUSED_PROPERTY:
		wg_cell_set_focused (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

