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

/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * Copyright © 2025 Johan Gay
 *
 * This file is part of GNOME Sudoku.
 *
 * GNOME Sudoku 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.
 *
 * GNOME Sudoku 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 GNOME Sudoku. If not, see <http://www.gnu.org/licenses/>.
 */

#include <adwaita.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib.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

#define TYPE_SUDOKU_MENU_BUTTON (sudoku_menu_button_get_type ())
#define SUDOKU_MENU_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SUDOKU_MENU_BUTTON, SudokuMenuButton))
#define SUDOKU_MENU_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SUDOKU_MENU_BUTTON, SudokuMenuButtonClass))
#define IS_SUDOKU_MENU_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SUDOKU_MENU_BUTTON))
#define IS_SUDOKU_MENU_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SUDOKU_MENU_BUTTON))
#define SUDOKU_MENU_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SUDOKU_MENU_BUTTON, SudokuMenuButtonClass))

typedef struct _SudokuMenuButton SudokuMenuButton;
typedef struct _SudokuMenuButtonClass SudokuMenuButtonClass;
typedef struct _SudokuMenuButtonPrivate SudokuMenuButtonPrivate;
enum  {
	SUDOKU_MENU_BUTTON_0_PROPERTY,
	SUDOKU_MENU_BUTTON_NUM_PROPERTIES
};
static GParamSpec* sudoku_menu_button_properties[SUDOKU_MENU_BUTTON_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _SudokuMenuButton {
	AdwBin parent_instance;
	SudokuMenuButtonPrivate * priv;
	GtkStack* menu_fullscreen_stack;
	GtkButton* menu_unfullscreen_button;
	GtkButton* menu_fullscreen_button;
	GtkPopover* main_menu;
};

struct _SudokuMenuButtonClass {
	AdwBinClass parent_class;
};

static gpointer sudoku_menu_button_parent_class = NULL;

VALA_EXTERN GType sudoku_menu_button_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SudokuMenuButton, g_object_unref)
static void sudoku_menu_button_set_fullscreen_button (SudokuMenuButton* self,
                                               gboolean fullscreen);
static void sudoku_menu_button_fullscreen_cb (SudokuMenuButton* self);
static void sudoku_menu_button_real_realize (GtkWidget* base);
static void _sudoku_menu_button_fullscreen_cb_g_object_notify (GObject* _sender,
                                                        GParamSpec* pspec,
                                                        gpointer self);
VALA_EXTERN SudokuMenuButton* sudoku_menu_button_new (void);
VALA_EXTERN SudokuMenuButton* sudoku_menu_button_construct (GType object_type);
static void sudoku_menu_button_finalize (GObject * obj);
static GType sudoku_menu_button_get_type_once (void);

static void
sudoku_menu_button_set_fullscreen_button (SudokuMenuButton* self,
                                          gboolean fullscreen)
{
	g_return_if_fail (self != NULL);
	if (fullscreen) {
		GtkStack* _tmp0_;
		GtkButton* _tmp1_;
		_tmp0_ = self->menu_fullscreen_stack;
		_tmp1_ = self->menu_unfullscreen_button;
		gtk_stack_set_visible_child (_tmp0_, (GtkWidget*) _tmp1_);
	} else {
		GtkStack* _tmp2_;
		GtkButton* _tmp3_;
		_tmp2_ = self->menu_fullscreen_stack;
		_tmp3_ = self->menu_fullscreen_button;
		gtk_stack_set_visible_child (_tmp2_, (GtkWidget*) _tmp3_);
	}
}

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

static void
sudoku_menu_button_fullscreen_cb (SudokuMenuButton* self)
{
	GtkWindow* window = NULL;
	GtkRoot* _tmp0_;
	GtkRoot* _tmp1_;
	GtkWindow* _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gtk_widget_get_root ((GtkWidget*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp1_, gtk_window_get_type ()) ? ((GtkWindow*) _tmp1_) : NULL);
	window = _tmp2_;
	g_object_get (window, "fullscreened", &_tmp3_, NULL);
	_tmp4_ = _tmp3_;
	sudoku_menu_button_set_fullscreen_button (self, _tmp4_);
	_g_object_unref0 (window);
}

static void
_sudoku_menu_button_fullscreen_cb_g_object_notify (GObject* _sender,
                                                   GParamSpec* pspec,
                                                   gpointer self)
{
	sudoku_menu_button_fullscreen_cb ((SudokuMenuButton*) self);
}

static void
sudoku_menu_button_real_realize (GtkWidget* base)
{
	SudokuMenuButton * self;
	GtkWindow* window = NULL;
	GtkRoot* _tmp0_;
	GtkRoot* _tmp1_;
	GtkWindow* _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	self = (SudokuMenuButton*) base;
	GTK_WIDGET_CLASS (sudoku_menu_button_parent_class)->realize ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, adw_bin_get_type (), AdwBin));
	_tmp0_ = gtk_widget_get_root ((GtkWidget*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp1_, gtk_window_get_type ()) ? ((GtkWindow*) _tmp1_) : NULL);
	window = _tmp2_;
	g_object_get (window, "fullscreened", &_tmp3_, NULL);
	_tmp4_ = _tmp3_;
	sudoku_menu_button_set_fullscreen_button (self, _tmp4_);
	g_signal_connect_object ((GObject*) window, "notify::fullscreened", (GCallback) _sudoku_menu_button_fullscreen_cb_g_object_notify, self, 0);
	_g_object_unref0 (window);
}

SudokuMenuButton*
sudoku_menu_button_construct (GType object_type)
{
	SudokuMenuButton * self = NULL;
	self = (SudokuMenuButton*) g_object_new (object_type, NULL);
	return self;
}

SudokuMenuButton*
sudoku_menu_button_new (void)
{
	return sudoku_menu_button_construct (TYPE_SUDOKU_MENU_BUTTON);
}

static void
sudoku_menu_button_class_init (SudokuMenuButtonClass * klass,
                               gpointer klass_data)
{
	sudoku_menu_button_parent_class = g_type_class_peek_parent (klass);
	((GtkWidgetClass *) klass)->realize = (void (*) (GtkWidget*)) sudoku_menu_button_real_realize;
	G_OBJECT_CLASS (klass)->finalize = sudoku_menu_button_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Sudoku/ui/menu-button.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "menu_fullscreen_stack", FALSE, G_STRUCT_OFFSET (SudokuMenuButton, menu_fullscreen_stack));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "menu_unfullscreen_button", FALSE, G_STRUCT_OFFSET (SudokuMenuButton, menu_unfullscreen_button));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "menu_fullscreen_button", FALSE, G_STRUCT_OFFSET (SudokuMenuButton, menu_fullscreen_button));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "main_menu", FALSE, G_STRUCT_OFFSET (SudokuMenuButton, main_menu));
}

static void
sudoku_menu_button_instance_init (SudokuMenuButton * self,
                                  gpointer klass)
{
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
sudoku_menu_button_finalize (GObject * obj)
{
	SudokuMenuButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_SUDOKU_MENU_BUTTON, SudokuMenuButton);
	G_OBJECT_CLASS (sudoku_menu_button_parent_class)->finalize (obj);
}

static GType
sudoku_menu_button_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SudokuMenuButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) sudoku_menu_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SudokuMenuButton), 0, (GInstanceInitFunc) sudoku_menu_button_instance_init, NULL };
	GType sudoku_menu_button_type_id;
	sudoku_menu_button_type_id = g_type_register_static (adw_bin_get_type (), "SudokuMenuButton", &g_define_type_info, 0);
	return sudoku_menu_button_type_id;
}

GType
sudoku_menu_button_get_type (void)
{
	static volatile gsize sudoku_menu_button_type_id__once = 0;
	if (g_once_init_enter (&sudoku_menu_button_type_id__once)) {
		GType sudoku_menu_button_type_id;
		sudoku_menu_button_type_id = sudoku_menu_button_get_type_once ();
		g_once_init_leave (&sudoku_menu_button_type_id__once, sudoku_menu_button_type_id);
	}
	return sudoku_menu_button_type_id__once;
}

