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

/*
 * Copyright © 2023 Alain M. (https://github.com/alainm23/planify)
 *
 * 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, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 *
 * Authored by: Alain M. <alainmh23@gmail.com>
 */

#include <adwaita.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <gdk/gdk.h>
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include "planify.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 WIDGETS_TYPE_MAGIC_BUTTON (widgets_magic_button_get_type ())
#define WIDGETS_MAGIC_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WIDGETS_TYPE_MAGIC_BUTTON, WidgetsMagicButton))
#define WIDGETS_MAGIC_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WIDGETS_TYPE_MAGIC_BUTTON, WidgetsMagicButtonClass))
#define WIDGETS_IS_MAGIC_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WIDGETS_TYPE_MAGIC_BUTTON))
#define WIDGETS_IS_MAGIC_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WIDGETS_TYPE_MAGIC_BUTTON))
#define WIDGETS_MAGIC_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WIDGETS_TYPE_MAGIC_BUTTON, WidgetsMagicButtonClass))

typedef struct _WidgetsMagicButton WidgetsMagicButton;
typedef struct _WidgetsMagicButtonClass WidgetsMagicButtonClass;
typedef struct _WidgetsMagicButtonPrivate WidgetsMagicButtonPrivate;
enum  {
	WIDGETS_MAGIC_BUTTON_0_PROPERTY,
	WIDGETS_MAGIC_BUTTON_NUM_PROPERTIES
};
static GParamSpec* widgets_magic_button_properties[WIDGETS_MAGIC_BUTTON_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	WIDGETS_MAGIC_BUTTON_CLICKED_SIGNAL,
	WIDGETS_MAGIC_BUTTON_DRAG_BEGIN_SIGNAL,
	WIDGETS_MAGIC_BUTTON_DRAG_END_SIGNAL,
	WIDGETS_MAGIC_BUTTON_NUM_SIGNALS
};
static guint widgets_magic_button_signals[WIDGETS_MAGIC_BUTTON_NUM_SIGNALS] = {0};

struct _WidgetsMagicButton {
	AdwBin parent_instance;
	WidgetsMagicButtonPrivate * priv;
	GtkButton* magic_button;
};

struct _WidgetsMagicButtonClass {
	AdwBinClass parent_class;
};

struct _WidgetsMagicButtonPrivate {
	GtkRevealer* main_revealer;
};

static gint WidgetsMagicButton_private_offset;
static gpointer widgets_magic_button_parent_class = NULL;

VALA_EXTERN GType widgets_magic_button_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WidgetsMagicButton, g_object_unref)
VALA_EXTERN WidgetsMagicButton* widgets_magic_button_new (void);
VALA_EXTERN WidgetsMagicButton* widgets_magic_button_construct (GType object_type);
static void widgets_magic_button_build_drag_and_drop (WidgetsMagicButton* self);
static GdkContentProvider* __lambda13_ (WidgetsMagicButton* self,
                                 GtkDragSource* source,
                                 gdouble x,
                                 gdouble y);
static GdkContentProvider* ___lambda13__gtk_drag_source_prepare (GtkDragSource* _sender,
                                                          gdouble x,
                                                          gdouble y,
                                                          gpointer self);
static void __lambda14_ (WidgetsMagicButton* self,
                  GtkDragSource* source,
                  GdkDrag* drag);
static void ___lambda14__gtk_drag_source_drag_begin (GtkDragSource* _sender,
                                              GdkDrag* drag,
                                              gpointer self);
static void __lambda15_ (WidgetsMagicButton* self,
                  GtkDragSource* source,
                  GdkDrag* drag,
                  gboolean delete_data);
static void ___lambda15__gtk_drag_source_drag_end (GtkDragSource* _sender,
                                            GdkDrag* drag,
                                            gboolean delete_data,
                                            gpointer self);
static gboolean __lambda16_ (WidgetsMagicButton* self,
                      GtkDragSource* source,
                      GdkDrag* drag,
                      GdkDragCancelReason reason);
static gboolean ___lambda16__gtk_drag_source_drag_cancel (GtkDragSource* _sender,
                                                   GdkDrag* drag,
                                                   GdkDragCancelReason reason,
                                                   gpointer self);
static GObject * widgets_magic_button_constructor (GType type,
                                            guint n_construct_properties,
                                            GObjectConstructParam * construct_properties);
static void _widgets_magic_button___lambda17_ (WidgetsMagicButton* self);
static void __widgets_magic_button___lambda17__gtk_button_clicked (GtkButton* _sender,
                                                            gpointer self);
static void _widgets_magic_button___lambda18_ (WidgetsMagicButton* self,
                                        gboolean visible);
static void __widgets_magic_button___lambda18__services_event_bus_magic_button_visible (ServicesEventBus* _sender,
                                                                                 gboolean active,
                                                                                 gpointer self);
static void widgets_magic_button_finalize (GObject * obj);
static GType widgets_magic_button_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

static inline gpointer
widgets_magic_button_get_instance_private (WidgetsMagicButton* self)
{
	return G_STRUCT_MEMBER_P (self, WidgetsMagicButton_private_offset);
}

WidgetsMagicButton*
widgets_magic_button_construct (GType object_type)
{
	WidgetsMagicButton * self = NULL;
	self = (WidgetsMagicButton*) g_object_new (object_type, "margin-top", 24, "margin-start", 24, "margin-end", 24, "margin-bottom", 24, "valign", GTK_ALIGN_END, "halign", GTK_ALIGN_END, NULL);
	return self;
}

WidgetsMagicButton*
widgets_magic_button_new (void)
{
	return widgets_magic_button_construct (WIDGETS_TYPE_MAGIC_BUTTON);
}

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

static GdkContentProvider*
__lambda13_ (WidgetsMagicButton* self,
             GtkDragSource* source,
             gdouble x,
             gdouble y)
{
	GValue _tmp0_ = {0};
	GdkContentProvider* _tmp1_;
	GdkContentProvider* _tmp2_;
	GdkContentProvider* result;
	g_return_val_if_fail (source != NULL, NULL);
	g_value_init (&_tmp0_, WIDGETS_TYPE_MAGIC_BUTTON);
	g_value_set_object (&_tmp0_, self);
	_tmp1_ = gdk_content_provider_new_for_value (&_tmp0_);
	_tmp2_ = _tmp1_;
	G_IS_VALUE (&_tmp0_) ? (g_value_unset (&_tmp0_), NULL) : NULL;
	result = _tmp2_;
	return result;
}

static GdkContentProvider*
___lambda13__gtk_drag_source_prepare (GtkDragSource* _sender,
                                      gdouble x,
                                      gdouble y,
                                      gpointer self)
{
	GdkContentProvider* result;
	result = __lambda13_ ((WidgetsMagicButton*) self, _sender, x, y);
	return result;
}

static void
__lambda14_ (WidgetsMagicButton* self,
             GtkDragSource* source,
             GdkDrag* drag)
{
	GtkWidgetPaintable* paintable = NULL;
	GtkButton* _tmp0_;
	GtkWidgetPaintable* _tmp1_;
	GtkRevealer* _tmp2_;
	g_return_if_fail (source != NULL);
	g_return_if_fail (drag != NULL);
	_tmp0_ = self->magic_button;
	_tmp1_ = (GtkWidgetPaintable*) gtk_widget_paintable_new ((GtkWidget*) _tmp0_);
	paintable = _tmp1_;
	gtk_drag_source_set_icon (source, (GdkPaintable*) paintable, 0, 0);
	_tmp2_ = self->priv->main_revealer;
	gtk_revealer_set_reveal_child (_tmp2_, FALSE);
	g_signal_emit (self, widgets_magic_button_signals[WIDGETS_MAGIC_BUTTON_DRAG_BEGIN_SIGNAL], 0);
	_g_object_unref0 (paintable);
}

static void
___lambda14__gtk_drag_source_drag_begin (GtkDragSource* _sender,
                                         GdkDrag* drag,
                                         gpointer self)
{
	__lambda14_ ((WidgetsMagicButton*) self, _sender, drag);
}

static void
__lambda15_ (WidgetsMagicButton* self,
             GtkDragSource* source,
             GdkDrag* drag,
             gboolean delete_data)
{
	GtkRevealer* _tmp0_;
	g_return_if_fail (source != NULL);
	g_return_if_fail (drag != NULL);
	_tmp0_ = self->priv->main_revealer;
	gtk_revealer_set_reveal_child (_tmp0_, TRUE);
	g_signal_emit (self, widgets_magic_button_signals[WIDGETS_MAGIC_BUTTON_DRAG_END_SIGNAL], 0);
}

static void
___lambda15__gtk_drag_source_drag_end (GtkDragSource* _sender,
                                       GdkDrag* drag,
                                       gboolean delete_data,
                                       gpointer self)
{
	__lambda15_ ((WidgetsMagicButton*) self, _sender, drag, delete_data);
}

static gboolean
__lambda16_ (WidgetsMagicButton* self,
             GtkDragSource* source,
             GdkDrag* drag,
             GdkDragCancelReason reason)
{
	GtkRevealer* _tmp0_;
	gboolean result;
	g_return_val_if_fail (source != NULL, FALSE);
	g_return_val_if_fail (drag != NULL, FALSE);
	_tmp0_ = self->priv->main_revealer;
	gtk_revealer_set_reveal_child (_tmp0_, TRUE);
	g_signal_emit (self, widgets_magic_button_signals[WIDGETS_MAGIC_BUTTON_DRAG_END_SIGNAL], 0);
	result = FALSE;
	return result;
}

static gboolean
___lambda16__gtk_drag_source_drag_cancel (GtkDragSource* _sender,
                                          GdkDrag* drag,
                                          GdkDragCancelReason reason,
                                          gpointer self)
{
	gboolean result;
	result = __lambda16_ ((WidgetsMagicButton*) self, _sender, drag, reason);
	return result;
}

static void
widgets_magic_button_build_drag_and_drop (WidgetsMagicButton* self)
{
	GtkDragSource* drag_source = NULL;
	GtkDragSource* _tmp0_;
	GtkEventController* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gtk_drag_source_new ();
	drag_source = _tmp0_;
	gtk_drag_source_set_actions (drag_source, GDK_ACTION_MOVE);
	_tmp1_ = _g_object_ref0 ((GtkEventController*) drag_source);
	gtk_widget_add_controller ((GtkWidget*) self, _tmp1_);
	g_signal_connect_object (drag_source, "prepare", (GCallback) ___lambda13__gtk_drag_source_prepare, self, 0);
	g_signal_connect_object (drag_source, "drag-begin", (GCallback) ___lambda14__gtk_drag_source_drag_begin, self, 0);
	g_signal_connect_object (drag_source, "drag-end", (GCallback) ___lambda15__gtk_drag_source_drag_end, self, 0);
	g_signal_connect_object (drag_source, "drag-cancel", (GCallback) ___lambda16__gtk_drag_source_drag_cancel, self, 0);
	_g_object_unref0 (drag_source);
}

static void
_widgets_magic_button___lambda17_ (WidgetsMagicButton* self)
{
	g_signal_emit (self, widgets_magic_button_signals[WIDGETS_MAGIC_BUTTON_CLICKED_SIGNAL], 0);
}

static void
__widgets_magic_button___lambda17__gtk_button_clicked (GtkButton* _sender,
                                                       gpointer self)
{
	_widgets_magic_button___lambda17_ ((WidgetsMagicButton*) self);
}

static void
_widgets_magic_button___lambda18_ (WidgetsMagicButton* self,
                                   gboolean visible)
{
	GtkRevealer* _tmp0_;
	_tmp0_ = self->priv->main_revealer;
	gtk_revealer_set_reveal_child (_tmp0_, visible);
}

static void
__widgets_magic_button___lambda18__services_event_bus_magic_button_visible (ServicesEventBus* _sender,
                                                                            gboolean active,
                                                                            gpointer self)
{
	_widgets_magic_button___lambda18_ ((WidgetsMagicButton*) self, active);
}

static GObject *
widgets_magic_button_constructor (GType type,
                                  guint n_construct_properties,
                                  GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	WidgetsMagicButton * self;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar** _tmp2_;
	gchar* _tmp3_;
	GtkButton* _tmp4_ = NULL;
	GtkButton* _tmp5_;
	GtkWidget* _tmp6_;
	GtkRevealer* _tmp7_ = NULL;
	GtkRevealer* _tmp8_;
	GtkButton* _tmp9_;
	ServicesEventBus* _tmp10_;
	ServicesEventBus* _tmp11_;
	parent_class = G_OBJECT_CLASS (widgets_magic_button_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_MAGIC_BUTTON, WidgetsMagicButton);
	_tmp0_ = g_strdup ("suggested-action");
	_tmp1_ = g_strdup ("magic-button");
	_tmp2_ = g_new0 (gchar*, 2 + 1);
	_tmp2_[0] = _tmp0_;
	_tmp2_[1] = _tmp1_;
	_tmp3_ = g_strdup (_ ("Add Task"));
	_tmp4_ = (GtkButton*) gtk_button_new_from_icon_name ("plus-large-symbolic");
	g_object_set ((GtkWidget*) _tmp4_, "height-request", 48, NULL);
	g_object_set ((GtkWidget*) _tmp4_, "width-request", 48, NULL);
	gtk_widget_set_css_classes ((GtkWidget*) _tmp4_, _tmp2_);
	_tmp2_ = (_vala_array_free (_tmp2_, 2, (GDestroyNotify) g_free), NULL);
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp4_, _tmp3_);
	_g_free0 (_tmp3_);
	gtk_widget_set_margin_top ((GtkWidget*) _tmp4_, 3);
	gtk_widget_set_margin_start ((GtkWidget*) _tmp4_, 3);
	gtk_widget_set_margin_end ((GtkWidget*) _tmp4_, 3);
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp4_, 3);
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->magic_button);
	self->magic_button = _tmp4_;
	_tmp5_ = self->magic_button;
	_tmp6_ = _g_object_ref0 ((GtkWidget*) _tmp5_);
	_tmp7_ = (GtkRevealer*) gtk_revealer_new ();
	gtk_revealer_set_transition_type (_tmp7_, GTK_REVEALER_TRANSITION_TYPE_CROSSFADE);
	gtk_revealer_set_reveal_child (_tmp7_, TRUE);
	gtk_revealer_set_child (_tmp7_, _tmp6_);
	_g_object_unref0 (_tmp6_);
	g_object_ref_sink (_tmp7_);
	_g_object_unref0 (self->priv->main_revealer);
	self->priv->main_revealer = _tmp7_;
	_tmp8_ = self->priv->main_revealer;
	adw_bin_set_child ((AdwBin*) self, (GtkWidget*) _tmp8_);
	widgets_magic_button_build_drag_and_drop (self);
	_tmp9_ = self->magic_button;
	g_signal_connect_object (_tmp9_, "clicked", (GCallback) __widgets_magic_button___lambda17__gtk_button_clicked, self, 0);
	_tmp10_ = services_event_bus_get_default ();
	_tmp11_ = _tmp10_;
	g_signal_connect_object (_tmp11_, "magic-button-visible", (GCallback) __widgets_magic_button___lambda18__services_event_bus_magic_button_visible, self, 0);
	_g_object_unref0 (_tmp11_);
	return obj;
}

static void
widgets_magic_button_class_init (WidgetsMagicButtonClass * klass,
                                 gpointer klass_data)
{
	widgets_magic_button_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WidgetsMagicButton_private_offset);
	G_OBJECT_CLASS (klass)->constructor = widgets_magic_button_constructor;
	G_OBJECT_CLASS (klass)->finalize = widgets_magic_button_finalize;
	widgets_magic_button_signals[WIDGETS_MAGIC_BUTTON_CLICKED_SIGNAL] = g_signal_new ("clicked", WIDGETS_TYPE_MAGIC_BUTTON, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	widgets_magic_button_signals[WIDGETS_MAGIC_BUTTON_DRAG_BEGIN_SIGNAL] = g_signal_new ("drag-begin", WIDGETS_TYPE_MAGIC_BUTTON, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	widgets_magic_button_signals[WIDGETS_MAGIC_BUTTON_DRAG_END_SIGNAL] = g_signal_new ("drag-end", WIDGETS_TYPE_MAGIC_BUTTON, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
widgets_magic_button_instance_init (WidgetsMagicButton * self,
                                    gpointer klass)
{
	self->priv = widgets_magic_button_get_instance_private (self);
}

static void
widgets_magic_button_finalize (GObject * obj)
{
	WidgetsMagicButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_MAGIC_BUTTON, WidgetsMagicButton);
	g_debug ("MagicButton.vala:42: Destroying - Widgets.MagicButton\n");
	_g_object_unref0 (self->magic_button);
	_g_object_unref0 (self->priv->main_revealer);
	G_OBJECT_CLASS (widgets_magic_button_parent_class)->finalize (obj);
}

static GType
widgets_magic_button_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WidgetsMagicButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) widgets_magic_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WidgetsMagicButton), 0, (GInstanceInitFunc) widgets_magic_button_instance_init, NULL };
	GType widgets_magic_button_type_id;
	widgets_magic_button_type_id = g_type_register_static (adw_bin_get_type (), "WidgetsMagicButton", &g_define_type_info, 0);
	WidgetsMagicButton_private_offset = g_type_add_instance_private (widgets_magic_button_type_id, sizeof (WidgetsMagicButtonPrivate));
	return widgets_magic_button_type_id;
}

GType
widgets_magic_button_get_type (void)
{
	static volatile gsize widgets_magic_button_type_id__once = 0;
	if (g_once_init_enter (&widgets_magic_button_type_id__once)) {
		GType widgets_magic_button_type_id;
		widgets_magic_button_type_id = widgets_magic_button_get_type_once ();
		g_once_init_leave (&widgets_magic_button_type_id__once, widgets_magic_button_type_id);
	}
	return widgets_magic_button_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

