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

/*-
 * Copyright (c) 2015-2016 elementary LLC.
 *
 * 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/>.
 *
 * Authored by: supaiku <supaiku@protonmail.ch>
 *
 */

#include "desktop.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <gdk/gdk.h>
#include <float.h>
#include <math.h>
#include <gdk-pixbuf/gdk-pixbuf.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

enum  {
	PANTHEON_SHELL_SOLID_COLOR_CONTAINER_0_PROPERTY,
	PANTHEON_SHELL_SOLID_COLOR_CONTAINER_COLOR_PROPERTY,
	PANTHEON_SHELL_SOLID_COLOR_CONTAINER_RGBA_PROPERTY,
	PANTHEON_SHELL_SOLID_COLOR_CONTAINER_NUM_PROPERTIES
};
static GParamSpec* pantheon_shell_solid_color_container_properties[PANTHEON_SHELL_SOLID_COLOR_CONTAINER_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 _PantheonShellSolidColorContainerPrivate {
	gchar* _color;
};

static gint PantheonShellSolidColorContainer_private_offset;
static gpointer pantheon_shell_solid_color_container_parent_class = NULL;

static guint8 pantheon_shell_solid_color_container_fp_to_uint8 (gdouble value);
static GObject * pantheon_shell_solid_color_container_constructor (GType type,
                                                            guint n_construct_properties,
                                                            GObjectConstructParam * construct_properties);
static void pantheon_shell_solid_color_container_finalize (GObject * obj);
static GType pantheon_shell_solid_color_container_get_type_once (void);
static void _vala_pantheon_shell_solid_color_container_get_property (GObject * object,
                                                              guint property_id,
                                                              GValue * value,
                                                              GParamSpec * pspec);
static void _vala_pantheon_shell_solid_color_container_set_property (GObject * object,
                                                              guint property_id,
                                                              const GValue * value,
                                                              GParamSpec * pspec);

static inline gpointer
pantheon_shell_solid_color_container_get_instance_private (PantheonShellSolidColorContainer* self)
{
	return G_STRUCT_MEMBER_P (self, PantheonShellSolidColorContainer_private_offset);
}

PantheonShellSolidColorContainer*
pantheon_shell_solid_color_container_construct (GType object_type,
                                                const gchar* color_value)
{
	PantheonShellSolidColorContainer * self = NULL;
	g_return_val_if_fail (color_value != NULL, NULL);
	self = (PantheonShellSolidColorContainer*) g_object_new (object_type, "color", color_value, NULL);
	return self;
}

PantheonShellSolidColorContainer*
pantheon_shell_solid_color_container_new (const gchar* color_value)
{
	return pantheon_shell_solid_color_container_construct (PANTHEON_SHELL_TYPE_SOLID_COLOR_CONTAINER, color_value);
}

guint32
pantheon_shell_solid_color_container_rgba_to_pixel (GdkRGBA* rgba)
{
	GdkRGBA _tmp0_;
	GdkRGBA _tmp1_;
	GdkRGBA _tmp2_;
	GdkRGBA _tmp3_;
	guint32 result;
	g_return_val_if_fail (rgba != NULL, 0U);
	_tmp0_ = *rgba;
	_tmp1_ = *rgba;
	_tmp2_ = *rgba;
	_tmp3_ = *rgba;
	result = (((((guint32) pantheon_shell_solid_color_container_fp_to_uint8 ((gdouble) _tmp0_.red)) << 24) | (((guint32) pantheon_shell_solid_color_container_fp_to_uint8 ((gdouble) _tmp1_.green)) << 16)) | (((guint32) pantheon_shell_solid_color_container_fp_to_uint8 ((gdouble) _tmp2_.blue)) << 8)) | ((guint32) pantheon_shell_solid_color_container_fp_to_uint8 ((gdouble) _tmp3_.alpha));
	return result;
}

static guint8
pantheon_shell_solid_color_container_fp_to_uint8 (gdouble value)
{
	guint8 result;
	result = (guint8) (value * G_MAXUINT8);
	return result;
}

const gchar*
pantheon_shell_solid_color_container_get_color (PantheonShellSolidColorContainer* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_color;
	result = _tmp0_;
	return result;
}

static void
pantheon_shell_solid_color_container_set_color (PantheonShellSolidColorContainer* self,
                                                const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = pantheon_shell_solid_color_container_get_color (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_color);
		self->priv->_color = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, pantheon_shell_solid_color_container_properties[PANTHEON_SHELL_SOLID_COLOR_CONTAINER_COLOR_PROPERTY]);
	}
}

void
pantheon_shell_solid_color_container_get_rgba (PantheonShellSolidColorContainer* self,
                                               GdkRGBA * result)
{
	GdkRGBA rgba = {0};
	GdkRGBA _tmp0_ = {0};
	const gchar* _tmp1_;
	GdkRGBA _tmp2_;
	g_return_if_fail (self != NULL);
	rgba = _tmp0_;
	_tmp1_ = self->priv->_color;
	gdk_rgba_parse (&rgba, _tmp1_);
	_tmp2_ = rgba;
	*result = _tmp2_;
	return;
}

static GObject *
pantheon_shell_solid_color_container_constructor (GType type,
                                                  guint n_construct_properties,
                                                  GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	PantheonShellSolidColorContainer * self;
	GdkPixbuf* pixbuf = NULL;
	GdkPixbuf* _tmp0_;
	GdkPixbuf* _tmp1_;
	GdkRGBA _tmp2_ = {0};
	GdkRGBA _tmp3_;
	GtkPicture* _tmp4_;
	GdkPixbuf* _tmp5_;
	GdkTexture* _tmp6_;
	GdkTexture* _tmp7_;
	parent_class = G_OBJECT_CLASS (pantheon_shell_solid_color_container_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PANTHEON_SHELL_TYPE_SOLID_COLOR_CONTAINER, PantheonShellSolidColorContainer);
	_tmp0_ = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, PANTHEON_SHELL_WALLPAPER_CONTAINER_THUMB_WIDTH, PANTHEON_SHELL_WALLPAPER_CONTAINER_THUMB_HEIGHT);
	pixbuf = _tmp0_;
	_tmp1_ = pixbuf;
	pantheon_shell_solid_color_container_get_rgba (self, &_tmp2_);
	_tmp3_ = _tmp2_;
	gdk_pixbuf_fill (_tmp1_, pantheon_shell_solid_color_container_rgba_to_pixel (&_tmp3_));
	_tmp4_ = ((PantheonShellWallpaperContainer*) self)->image;
	_tmp5_ = pixbuf;
	_tmp6_ = gdk_texture_new_for_pixbuf (_tmp5_);
	_tmp7_ = _tmp6_;
	gtk_picture_set_paintable (_tmp4_, (GdkPaintable*) _tmp7_);
	_g_object_unref0 (_tmp7_);
	_g_object_unref0 (pixbuf);
	return obj;
}

static void
pantheon_shell_solid_color_container_class_init (PantheonShellSolidColorContainerClass * klass,
                                                 gpointer klass_data)
{
	pantheon_shell_solid_color_container_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &PantheonShellSolidColorContainer_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_pantheon_shell_solid_color_container_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_pantheon_shell_solid_color_container_set_property;
	G_OBJECT_CLASS (klass)->constructor = pantheon_shell_solid_color_container_constructor;
	G_OBJECT_CLASS (klass)->finalize = pantheon_shell_solid_color_container_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), PANTHEON_SHELL_SOLID_COLOR_CONTAINER_COLOR_PROPERTY, pantheon_shell_solid_color_container_properties[PANTHEON_SHELL_SOLID_COLOR_CONTAINER_COLOR_PROPERTY] = g_param_spec_string ("color", "color", "color", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PANTHEON_SHELL_SOLID_COLOR_CONTAINER_RGBA_PROPERTY, pantheon_shell_solid_color_container_properties[PANTHEON_SHELL_SOLID_COLOR_CONTAINER_RGBA_PROPERTY] = g_param_spec_boxed ("rgba", "rgba", "rgba", gdk_rgba_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
pantheon_shell_solid_color_container_instance_init (PantheonShellSolidColorContainer * self,
                                                    gpointer klass)
{
	self->priv = pantheon_shell_solid_color_container_get_instance_private (self);
}

static void
pantheon_shell_solid_color_container_finalize (GObject * obj)
{
	PantheonShellSolidColorContainer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PANTHEON_SHELL_TYPE_SOLID_COLOR_CONTAINER, PantheonShellSolidColorContainer);
	_g_free0 (self->priv->_color);
	G_OBJECT_CLASS (pantheon_shell_solid_color_container_parent_class)->finalize (obj);
}

static GType
pantheon_shell_solid_color_container_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (PantheonShellSolidColorContainerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) pantheon_shell_solid_color_container_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PantheonShellSolidColorContainer), 0, (GInstanceInitFunc) pantheon_shell_solid_color_container_instance_init, NULL };
	GType pantheon_shell_solid_color_container_type_id;
	pantheon_shell_solid_color_container_type_id = g_type_register_static (PANTHEON_SHELL_TYPE_WALLPAPER_CONTAINER, "PantheonShellSolidColorContainer", &g_define_type_info, 0);
	PantheonShellSolidColorContainer_private_offset = g_type_add_instance_private (pantheon_shell_solid_color_container_type_id, sizeof (PantheonShellSolidColorContainerPrivate));
	return pantheon_shell_solid_color_container_type_id;
}

GType
pantheon_shell_solid_color_container_get_type (void)
{
	static volatile gsize pantheon_shell_solid_color_container_type_id__once = 0;
	if (g_once_init_enter (&pantheon_shell_solid_color_container_type_id__once)) {
		GType pantheon_shell_solid_color_container_type_id;
		pantheon_shell_solid_color_container_type_id = pantheon_shell_solid_color_container_get_type_once ();
		g_once_init_leave (&pantheon_shell_solid_color_container_type_id__once, pantheon_shell_solid_color_container_type_id);
	}
	return pantheon_shell_solid_color_container_type_id__once;
}

static void
_vala_pantheon_shell_solid_color_container_get_property (GObject * object,
                                                         guint property_id,
                                                         GValue * value,
                                                         GParamSpec * pspec)
{
	PantheonShellSolidColorContainer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PANTHEON_SHELL_TYPE_SOLID_COLOR_CONTAINER, PantheonShellSolidColorContainer);
	switch (property_id) {
		case PANTHEON_SHELL_SOLID_COLOR_CONTAINER_COLOR_PROPERTY:
		g_value_set_string (value, pantheon_shell_solid_color_container_get_color (self));
		break;
		case PANTHEON_SHELL_SOLID_COLOR_CONTAINER_RGBA_PROPERTY:
		{
			GdkRGBA boxed;
			pantheon_shell_solid_color_container_get_rgba (self, &boxed);
			g_value_set_boxed (value, &boxed);
		}
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_pantheon_shell_solid_color_container_set_property (GObject * object,
                                                         guint property_id,
                                                         const GValue * value,
                                                         GParamSpec * pspec)
{
	PantheonShellSolidColorContainer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PANTHEON_SHELL_TYPE_SOLID_COLOR_CONTAINER, PantheonShellSolidColorContainer);
	switch (property_id) {
		case PANTHEON_SHELL_SOLID_COLOR_CONTAINER_COLOR_PROPERTY:
		pantheon_shell_solid_color_container_set_color (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

