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

/* window.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 <adwaita.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>

#define WG_CONSTANTS_APP_ID "app.drey.Blurble"
#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

#define WG_TYPE_GAME_PAGE (wg_game_page_get_type ())
#define WG_GAME_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WG_TYPE_GAME_PAGE, WGGamePage))
#define WG_GAME_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WG_TYPE_GAME_PAGE, WGGamePageClass))
#define WG_IS_GAME_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WG_TYPE_GAME_PAGE))
#define WG_IS_GAME_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WG_TYPE_GAME_PAGE))
#define WG_GAME_PAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WG_TYPE_GAME_PAGE, WGGamePageClass))

typedef struct _WGGamePage WGGamePage;
typedef struct _WGGamePageClass WGGamePageClass;
typedef struct _WGGamePagePrivate WGGamePagePrivate;

#define WG_TYPE_GAME_CONTROLLER (wg_game_controller_get_type ())
#define WG_GAME_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WG_TYPE_GAME_CONTROLLER, WGGameController))
#define WG_GAME_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WG_TYPE_GAME_CONTROLLER, WGGameControllerClass))
#define WG_IS_GAME_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WG_TYPE_GAME_CONTROLLER))
#define WG_IS_GAME_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WG_TYPE_GAME_CONTROLLER))
#define WG_GAME_CONTROLLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WG_TYPE_GAME_CONTROLLER, WGGameControllerClass))

typedef struct _WGGameController WGGameController;
typedef struct _WGGameControllerClass WGGameControllerClass;

#define WG_TYPE_KEYBOARD (wg_keyboard_get_type ())
#define WG_KEYBOARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WG_TYPE_KEYBOARD, WGKeyboard))
#define WG_KEYBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WG_TYPE_KEYBOARD, WGKeyboardClass))
#define WG_IS_KEYBOARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WG_TYPE_KEYBOARD))
#define WG_IS_KEYBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WG_TYPE_KEYBOARD))
#define WG_KEYBOARD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WG_TYPE_KEYBOARD, WGKeyboardClass))

typedef struct _WGKeyboard WGKeyboard;
typedef struct _WGKeyboardClass WGKeyboardClass;
enum  {
	WG_GAME_PAGE_0_PROPERTY,
	WG_GAME_PAGE_NUM_PROPERTIES
};
static GParamSpec* wg_game_page_properties[WG_GAME_PAGE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
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_DATA_PARSER_TYPE_WORD (wg_data_parser_word_get_type ())
#define WG_DATA_PARSER_WORD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WG_DATA_PARSER_TYPE_WORD, WGDataParserWord))
#define WG_DATA_PARSER_WORD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WG_DATA_PARSER_TYPE_WORD, WGDataParserWordClass))
#define WG_DATA_PARSER_IS_WORD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WG_DATA_PARSER_TYPE_WORD))
#define WG_DATA_PARSER_IS_WORD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WG_DATA_PARSER_TYPE_WORD))
#define WG_DATA_PARSER_WORD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WG_DATA_PARSER_TYPE_WORD, WGDataParserWordClass))

typedef struct _WGDataParserWord WGDataParserWord;
typedef struct _WGDataParserWordClass WGDataParserWordClass;
enum  {
	WG_GAME_PAGE_GAME_OVER_SIGNAL,
	WG_GAME_PAGE_NUM_SIGNALS
};
static guint wg_game_page_signals[WG_GAME_PAGE_NUM_SIGNALS] = {0};

struct _WGGamePage {
	AdwBin parent_instance;
	WGGamePagePrivate * priv;
};

struct _WGGamePageClass {
	AdwBinClass parent_class;
};

struct _WGGamePagePrivate {
	WGGameController* gc;
	WGKeyboard* k;
	GSettings* settings;
};

static gint WGGamePage_private_offset;
static gpointer wg_game_page_parent_class = NULL;

VALA_EXTERN GType wg_game_page_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WGGamePage, g_object_unref)
VALA_EXTERN GType wg_game_controller_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WGGameController, g_object_unref)
VALA_EXTERN GType wg_keyboard_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WGKeyboard, g_object_unref)
VALA_EXTERN WGGameController* wg_game_controller_new (void);
VALA_EXTERN WGGameController* wg_game_controller_construct (GType object_type);
VALA_EXTERN WGKeyboard* wg_keyboard_new (void);
VALA_EXTERN WGKeyboard* wg_keyboard_construct (GType object_type);
VALA_EXTERN WGGamePage* wg_game_page_new (void);
VALA_EXTERN WGGamePage* wg_game_page_construct (GType object_type);
static void wg_game_page_do_game_over (WGGamePage* self,
                                gboolean win);
static void _wg_game_page_do_game_over_wg_game_controller_game_over (WGGameController* _sender,
                                                              gboolean win,
                                                              gpointer self);
VALA_EXTERN void wg_keyboard_set_game_over (WGKeyboard* self,
                                gboolean value);
VALA_EXTERN void wg_game_controller_insert (WGGameController* self,
                                const gchar* text);
static void _wg_game_controller_insert_wg_keyboard_insert (WGKeyboard* _sender,
                                                    const gchar* cell,
                                                    gpointer self);
VALA_EXTERN void wg_game_controller_confirm (WGGameController* self);
static void _wg_game_controller_confirm_wg_keyboard_enter (WGKeyboard* _sender,
                                                    gpointer self);
VALA_EXTERN void wg_game_controller_backspace (WGGameController* self);
static void _wg_game_controller_backspace_wg_keyboard_backspace (WGKeyboard* _sender,
                                                          gpointer self);
VALA_EXTERN GType wg_cell_state_get_type (void) G_GNUC_CONST ;
static void __lambda13_ (WGGamePage* self,
                  const gchar* val,
                  WGCellState state);
VALA_EXTERN void wg_keyboard_set_key_state (WGKeyboard* self,
                                const gchar* val,
                                WGCellState state);
static void ___lambda13__wg_game_controller_change_letter_state (WGGameController* _sender,
                                                          const gchar* val,
                                                          WGCellState state,
                                                          gpointer self);
VALA_EXTERN void wg_game_page_set_keyboard_visibility (WGGamePage* self,
                                           gboolean visible);
static void __lambda14_ (WGGamePage* self,
                  const gchar* key);
static void ___lambda14__g_settings_changed (GSettings* _sender,
                                      const gchar* key,
                                      gpointer self);
VALA_EXTERN void wg_game_page_new_word (WGGamePage* self);
VALA_EXTERN void wg_game_controller_new_word (WGGameController* self);
VALA_EXTERN void wg_keyboard_reset (WGKeyboard* self);
VALA_EXTERN GType wg_data_parser_word_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WGDataParserWord, g_object_unref)
VALA_EXTERN WGDataParserWord* wg_game_controller_get_correct_word (WGGameController* self);
static void g_cclosure_user_marshal_VOID__OBJECT_BOOLEAN (GClosure * closure,
                                                   GValue * return_value,
                                                   guint n_param_values,
                                                   const GValue * param_values,
                                                   gpointer invocation_hint,
                                                   gpointer marshal_data);
static GObject * wg_game_page_constructor (GType type,
                                    guint n_construct_properties,
                                    GObjectConstructParam * construct_properties);
VALA_EXTERN gboolean wg_game_controller_grab_focus (WGGameController* self);
static void wg_game_page_finalize (GObject * obj);
static GType wg_game_page_get_type_once (void);

static inline gpointer
wg_game_page_get_instance_private (WGGamePage* self)
{
	return G_STRUCT_MEMBER_P (self, WGGamePage_private_offset);
}

static void
_wg_game_page_do_game_over_wg_game_controller_game_over (WGGameController* _sender,
                                                         gboolean win,
                                                         gpointer self)
{
	wg_game_page_do_game_over ((WGGamePage*) self, win);
}

static void
_wg_game_controller_insert_wg_keyboard_insert (WGKeyboard* _sender,
                                               const gchar* cell,
                                               gpointer self)
{
	wg_game_controller_insert ((WGGameController*) self, cell);
}

static void
_wg_game_controller_confirm_wg_keyboard_enter (WGKeyboard* _sender,
                                               gpointer self)
{
	wg_game_controller_confirm ((WGGameController*) self);
}

static void
_wg_game_controller_backspace_wg_keyboard_backspace (WGKeyboard* _sender,
                                                     gpointer self)
{
	wg_game_controller_backspace ((WGGameController*) self);
}

static void
__lambda13_ (WGGamePage* self,
             const gchar* val,
             WGCellState state)
{
	WGKeyboard* _tmp0_;
	g_return_if_fail (val != NULL);
	_tmp0_ = self->priv->k;
	wg_keyboard_set_key_state (_tmp0_, val, state);
}

static void
___lambda13__wg_game_controller_change_letter_state (WGGameController* _sender,
                                                     const gchar* val,
                                                     WGCellState state,
                                                     gpointer self)
{
	__lambda13_ ((WGGamePage*) self, val, state);
}

static void
__lambda14_ (WGGamePage* self,
             const gchar* key)
{
	GSettings* _tmp0_;
	g_return_if_fail (key != NULL);
	if (g_strcmp0 (key, "show-keyboard") != 0) {
		return;
	}
	_tmp0_ = self->priv->settings;
	wg_game_page_set_keyboard_visibility (self, g_settings_get_boolean (_tmp0_, "show-keyboard"));
}

static void
___lambda14__g_settings_changed (GSettings* _sender,
                                 const gchar* key,
                                 gpointer self)
{
	__lambda14_ ((WGGamePage*) self, key);
}

WGGamePage*
wg_game_page_construct (GType object_type)
{
	WGGamePage * self = NULL;
	WGGameController* _tmp0_;
	WGKeyboard* _tmp1_;
	WGKeyboard* _tmp2_;
	WGGameController* _tmp3_;
	WGKeyboard* _tmp4_;
	WGGameController* _tmp5_;
	WGKeyboard* _tmp6_;
	WGGameController* _tmp7_;
	WGGameController* _tmp8_;
	GSettings* _tmp9_;
	GSettings* _tmp10_;
	self = (WGGamePage*) g_object_new (object_type, NULL);
	_tmp0_ = self->priv->gc;
	g_signal_connect_object (_tmp0_, "game-over", (GCallback) _wg_game_page_do_game_over_wg_game_controller_game_over, self, 0);
	_tmp1_ = self->priv->k;
	wg_keyboard_set_game_over (_tmp1_, FALSE);
	_tmp2_ = self->priv->k;
	_tmp3_ = self->priv->gc;
	g_signal_connect_object (_tmp2_, "insert", (GCallback) _wg_game_controller_insert_wg_keyboard_insert, _tmp3_, 0);
	_tmp4_ = self->priv->k;
	_tmp5_ = self->priv->gc;
	g_signal_connect_object (_tmp4_, "enter", (GCallback) _wg_game_controller_confirm_wg_keyboard_enter, _tmp5_, 0);
	_tmp6_ = self->priv->k;
	_tmp7_ = self->priv->gc;
	g_signal_connect_object (_tmp6_, "backspace", (GCallback) _wg_game_controller_backspace_wg_keyboard_backspace, _tmp7_, 0);
	_tmp8_ = self->priv->gc;
	g_signal_connect_object (_tmp8_, "change-letter-state", (GCallback) ___lambda13__wg_game_controller_change_letter_state, self, 0);
	_tmp9_ = self->priv->settings;
	wg_game_page_set_keyboard_visibility (self, g_settings_get_boolean (_tmp9_, "show-keyboard"));
	_tmp10_ = self->priv->settings;
	g_signal_connect_object (_tmp10_, "changed", (GCallback) ___lambda14__g_settings_changed, self, 0);
	return self;
}

WGGamePage*
wg_game_page_new (void)
{
	return wg_game_page_construct (WG_TYPE_GAME_PAGE);
}

void
wg_game_page_new_word (WGGamePage* self)
{
	WGKeyboard* _tmp0_;
	WGGameController* _tmp1_;
	WGKeyboard* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->k;
	wg_keyboard_set_game_over (_tmp0_, FALSE);
	_tmp1_ = self->priv->gc;
	wg_game_controller_new_word (_tmp1_);
	_tmp2_ = self->priv->k;
	wg_keyboard_reset (_tmp2_);
}

static void
wg_game_page_do_game_over (WGGamePage* self,
                           gboolean win)
{
	WGKeyboard* _tmp0_;
	WGGameController* _tmp1_;
	WGDataParserWord* _tmp2_;
	WGDataParserWord* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->k;
	wg_keyboard_set_game_over (_tmp0_, TRUE);
	_tmp1_ = self->priv->gc;
	_tmp2_ = wg_game_controller_get_correct_word (_tmp1_);
	_tmp3_ = _tmp2_;
	g_signal_emit (self, wg_game_page_signals[WG_GAME_PAGE_GAME_OVER_SIGNAL], 0, _tmp3_, win);
}

void
wg_game_page_set_keyboard_visibility (WGGamePage* self,
                                      gboolean visible)
{
	WGKeyboard* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->k;
	gtk_widget_set_visible ((GtkWidget*) _tmp0_, visible);
}

static void
g_cclosure_user_marshal_VOID__OBJECT_BOOLEAN (GClosure * closure,
                                              GValue * return_value,
                                              guint n_param_values,
                                              const GValue * param_values,
                                              gpointer invocation_hint,
                                              gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__OBJECT_BOOLEAN) (gpointer data1, gpointer arg_1, gboolean arg_2, gpointer data2);
	register GMarshalFunc_VOID__OBJECT_BOOLEAN callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__OBJECT_BOOLEAN) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_object (param_values + 1), g_value_get_boolean (param_values + 2), data2);
}

static GObject *
wg_game_page_constructor (GType type,
                          guint n_construct_properties,
                          GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	WGGamePage * self;
	GtkBox* main_box = NULL;
	GtkBox* _tmp0_;
	GtkBox* _tmp1_;
	GtkBox* _tmp2_;
	GtkBox* _tmp3_;
	GtkBox* _tmp4_;
	WGGameController* _tmp5_;
	GtkBox* _tmp6_;
	WGKeyboard* _tmp7_;
	WGGameController* _tmp8_;
	parent_class = G_OBJECT_CLASS (wg_game_page_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WG_TYPE_GAME_PAGE, WGGamePage);
	_tmp0_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 32);
	g_object_ref_sink (_tmp0_);
	main_box = _tmp0_;
	_tmp1_ = main_box;
	adw_bin_set_child ((AdwBin*) self, (GtkWidget*) _tmp1_);
	_tmp2_ = main_box;
	gtk_widget_set_halign ((GtkWidget*) _tmp2_, GTK_ALIGN_CENTER);
	_tmp3_ = main_box;
	gtk_widget_set_valign ((GtkWidget*) _tmp3_, GTK_ALIGN_CENTER);
	_tmp4_ = main_box;
	_tmp5_ = self->priv->gc;
	gtk_box_append (_tmp4_, (GtkWidget*) _tmp5_);
	_tmp6_ = main_box;
	_tmp7_ = self->priv->k;
	gtk_box_append (_tmp6_, (GtkWidget*) _tmp7_);
	_tmp8_ = self->priv->gc;
	wg_game_controller_grab_focus (_tmp8_);
	_g_object_unref0 (main_box);
	return obj;
}

static void
wg_game_page_class_init (WGGamePageClass * klass,
                         gpointer klass_data)
{
	wg_game_page_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WGGamePage_private_offset);
	G_OBJECT_CLASS (klass)->constructor = wg_game_page_constructor;
	G_OBJECT_CLASS (klass)->finalize = wg_game_page_finalize;
	wg_game_page_signals[WG_GAME_PAGE_GAME_OVER_SIGNAL] = g_signal_new ("game-over", WG_TYPE_GAME_PAGE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2, WG_DATA_PARSER_TYPE_WORD, G_TYPE_BOOLEAN);
}

static void
wg_game_page_instance_init (WGGamePage * self,
                            gpointer klass)
{
	WGGameController* _tmp0_;
	WGKeyboard* _tmp1_;
	GSettings* _tmp2_;
	self->priv = wg_game_page_get_instance_private (self);
	_tmp0_ = wg_game_controller_new ();
	g_object_ref_sink (_tmp0_);
	self->priv->gc = _tmp0_;
	_tmp1_ = wg_keyboard_new ();
	g_object_ref_sink (_tmp1_);
	self->priv->k = _tmp1_;
	_tmp2_ = g_settings_new (WG_CONSTANTS_APP_ID);
	self->priv->settings = _tmp2_;
}

static void
wg_game_page_finalize (GObject * obj)
{
	WGGamePage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WG_TYPE_GAME_PAGE, WGGamePage);
	_g_object_unref0 (self->priv->gc);
	_g_object_unref0 (self->priv->k);
	_g_object_unref0 (self->priv->settings);
	G_OBJECT_CLASS (wg_game_page_parent_class)->finalize (obj);
}

static GType
wg_game_page_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WGGamePageClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) wg_game_page_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WGGamePage), 0, (GInstanceInitFunc) wg_game_page_instance_init, NULL };
	GType wg_game_page_type_id;
	wg_game_page_type_id = g_type_register_static (adw_bin_get_type (), "WGGamePage", &g_define_type_info, 0);
	WGGamePage_private_offset = g_type_add_instance_private (wg_game_page_type_id, sizeof (WGGamePagePrivate));
	return wg_game_page_type_id;
}

GType
wg_game_page_get_type (void)
{
	static volatile gsize wg_game_page_type_id__once = 0;
	if (g_once_init_enter (&wg_game_page_type_id__once)) {
		GType wg_game_page_type_id;
		wg_game_page_type_id = wg_game_page_get_type_once ();
		g_once_init_leave (&wg_game_page_type_id__once, wg_game_page_type_id);
	}
	return wg_game_page_type_id__once;
}

