/* PinButton.c generated by valac 0.56.19, the Vala compiler
 * generated from PinButton.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 "planify.h"
#include <gtk/gtk.h>
#include <glib.h>
#include <glib-object.h>
#include <glib/gi18n-lib.h>
#include <stdlib.h>
#include <string.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

enum  {
	WIDGETS_PIN_BUTTON_0_PROPERTY,
	WIDGETS_PIN_BUTTON_NO_PADDING_PROPERTY,
	WIDGETS_PIN_BUTTON_NUM_PROPERTIES
};
static GParamSpec* widgets_pin_button_properties[WIDGETS_PIN_BUTTON_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	WIDGETS_PIN_BUTTON_CHANGED_SIGNAL,
	WIDGETS_PIN_BUTTON_NUM_SIGNALS
};
static guint widgets_pin_button_signals[WIDGETS_PIN_BUTTON_NUM_SIGNALS] = {0};

struct _WidgetsPinButtonPrivate {
	GtkImage* pinned_image;
};

static gint WidgetsPinButton_private_offset;
static gpointer widgets_pin_button_parent_class = NULL;

static GObject * widgets_pin_button_constructor (GType type,
                                          guint n_construct_properties,
                                          GObjectConstructParam * construct_properties);
static void _widgets_pin_button___lambda273_ (WidgetsPinButton* self);
static void __widgets_pin_button___lambda273__gtk_button_clicked (GtkButton* _sender,
                                                           gpointer self);
static void widgets_pin_button_finalize (GObject * obj);
static GType widgets_pin_button_get_type_once (void);
static void _vala_widgets_pin_button_set_property (GObject * object,
                                            guint property_id,
                                            const GValue * value,
                                            GParamSpec * pspec);
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 _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
widgets_pin_button_get_instance_private (WidgetsPinButton* self)
{
	return G_STRUCT_MEMBER_P (self, WidgetsPinButton_private_offset);
}

WidgetsPinButton*
widgets_pin_button_construct (GType object_type)
{
	WidgetsPinButton * self = NULL;
	self = (WidgetsPinButton*) g_object_new (object_type, "valign", GTK_ALIGN_CENTER, "halign", GTK_ALIGN_CENTER, "tooltip-text", _ ("Pin"), NULL);
	return self;
}

WidgetsPinButton*
widgets_pin_button_new (void)
{
	return widgets_pin_button_construct (WIDGETS_TYPE_PIN_BUTTON);
}

void
widgets_pin_button_update_from_item (WidgetsPinButton* self,
                                     ObjectsItem* item)
{
	gboolean _tmp0_;
	gboolean _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (item != NULL);
	_tmp0_ = objects_item_get_pinned (item);
	_tmp1_ = _tmp0_;
	widgets_pin_button_update_request (self, _tmp1_);
}

void
widgets_pin_button_update_request (WidgetsPinButton* self,
                                   gboolean pinned)
{
	g_return_if_fail (self != NULL);
	if (pinned) {
		GtkImage* _tmp0_;
		_tmp0_ = self->priv->pinned_image;
		gtk_widget_add_css_class ((GtkWidget*) _tmp0_, "pinboard-color");
	} else {
		GtkImage* _tmp1_;
		_tmp1_ = self->priv->pinned_image;
		gtk_widget_remove_css_class ((GtkWidget*) _tmp1_, "pinboard-color");
	}
}

void
widgets_pin_button_reset (WidgetsPinButton* self)
{
	GtkImage* _tmp0_;
	gchar** _tmp1_;
	gchar** _tmp2_;
	gint _tmp2__length1;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->pinned_image;
	_tmp1_ = g_new0 (gchar*, 0 + 1);
	_tmp2_ = _tmp1_;
	_tmp2__length1 = 0;
	gtk_widget_set_css_classes ((GtkWidget*) _tmp0_, _tmp2_);
	_tmp2_ = (_vala_array_free (_tmp2_, _tmp2__length1, (GDestroyNotify) g_free), NULL);
}

void
widgets_pin_button_set_no_padding (WidgetsPinButton* self,
                                   gboolean value)
{
	g_return_if_fail (self != NULL);
	if (value) {
		gtk_widget_add_css_class ((GtkWidget*) self, "no-padding");
	} else {
		gtk_widget_remove_css_class ((GtkWidget*) self, "no-padding");
	}
	g_object_notify_by_pspec ((GObject *) self, widgets_pin_button_properties[WIDGETS_PIN_BUTTON_NO_PADDING_PROPERTY]);
}

static void
_widgets_pin_button___lambda273_ (WidgetsPinButton* self)
{
	g_signal_emit (self, widgets_pin_button_signals[WIDGETS_PIN_BUTTON_CHANGED_SIGNAL], 0);
}

static void
__widgets_pin_button___lambda273__gtk_button_clicked (GtkButton* _sender,
                                                      gpointer self)
{
	_widgets_pin_button___lambda273_ ((WidgetsPinButton*) self);
}

static GObject *
widgets_pin_button_constructor (GType type,
                                guint n_construct_properties,
                                GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	WidgetsPinButton * self;
	GtkImage* _tmp0_;
	GtkImage* _tmp1_;
	parent_class = G_OBJECT_CLASS (widgets_pin_button_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_PIN_BUTTON, WidgetsPinButton);
	gtk_widget_add_css_class ((GtkWidget*) self, "flat");
	_tmp0_ = (GtkImage*) gtk_image_new_from_icon_name ("pin-symbolic");
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->pinned_image);
	self->priv->pinned_image = _tmp0_;
	_tmp1_ = self->priv->pinned_image;
	gtk_button_set_child ((GtkButton*) self, (GtkWidget*) _tmp1_);
	g_signal_connect_object ((GtkButton*) self, "clicked", (GCallback) __widgets_pin_button___lambda273__gtk_button_clicked, self, 0);
	return obj;
}

static void
widgets_pin_button_class_init (WidgetsPinButtonClass * klass,
                               gpointer klass_data)
{
	widgets_pin_button_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WidgetsPinButton_private_offset);
	G_OBJECT_CLASS (klass)->set_property = _vala_widgets_pin_button_set_property;
	G_OBJECT_CLASS (klass)->constructor = widgets_pin_button_constructor;
	G_OBJECT_CLASS (klass)->finalize = widgets_pin_button_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_PIN_BUTTON_NO_PADDING_PROPERTY, widgets_pin_button_properties[WIDGETS_PIN_BUTTON_NO_PADDING_PROPERTY] = g_param_spec_boolean ("no-padding", "no-padding", "no-padding", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE));
	widgets_pin_button_signals[WIDGETS_PIN_BUTTON_CHANGED_SIGNAL] = g_signal_new ("changed", WIDGETS_TYPE_PIN_BUTTON, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
widgets_pin_button_instance_init (WidgetsPinButton * self,
                                  gpointer klass)
{
	self->priv = widgets_pin_button_get_instance_private (self);
}

static void
widgets_pin_button_finalize (GObject * obj)
{
	WidgetsPinButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_PIN_BUTTON, WidgetsPinButton);
	g_debug ("PinButton.vala:46: Destroying - Widgets.PinButton\n");
	_g_object_unref0 (self->priv->pinned_image);
	G_OBJECT_CLASS (widgets_pin_button_parent_class)->finalize (obj);
}

static GType
widgets_pin_button_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WidgetsPinButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) widgets_pin_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WidgetsPinButton), 0, (GInstanceInitFunc) widgets_pin_button_instance_init, NULL };
	GType widgets_pin_button_type_id;
	widgets_pin_button_type_id = g_type_register_static (gtk_button_get_type (), "WidgetsPinButton", &g_define_type_info, 0);
	WidgetsPinButton_private_offset = g_type_add_instance_private (widgets_pin_button_type_id, sizeof (WidgetsPinButtonPrivate));
	return widgets_pin_button_type_id;
}

GType
widgets_pin_button_get_type (void)
{
	static volatile gsize widgets_pin_button_type_id__once = 0;
	if (g_once_init_enter (&widgets_pin_button_type_id__once)) {
		GType widgets_pin_button_type_id;
		widgets_pin_button_type_id = widgets_pin_button_get_type_once ();
		g_once_init_leave (&widgets_pin_button_type_id__once, widgets_pin_button_type_id);
	}
	return widgets_pin_button_type_id__once;
}

static void
_vala_widgets_pin_button_set_property (GObject * object,
                                       guint property_id,
                                       const GValue * value,
                                       GParamSpec * pspec)
{
	WidgetsPinButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WIDGETS_TYPE_PIN_BUTTON, WidgetsPinButton);
	switch (property_id) {
		case WIDGETS_PIN_BUTTON_NO_PADDING_PROPERTY:
		widgets_pin_button_set_no_padding (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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);
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

