/* ui-color-button.c generated by valac 0.10.4, the Vala compiler
 * generated from ui-color-button.vala, do not modify */

/*
 * Convenience class for GtkColorButton.
 *
 * Copyright (C) 2009 Mark Lee <libdesktop-agnostic@lazymalevolence.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * Author : Mark Lee <libdesktop-agnostic@lazymalevolence.com>
 */

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <libdesktop-agnostic/desktop-agnostic.h>
#include <gdk/gdk.h>


#define DESKTOP_AGNOSTIC_UI_TYPE_COLOR_BUTTON (desktop_agnostic_ui_color_button_get_type ())
#define DESKTOP_AGNOSTIC_UI_COLOR_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DESKTOP_AGNOSTIC_UI_TYPE_COLOR_BUTTON, DesktopAgnosticUIColorButton))
#define DESKTOP_AGNOSTIC_UI_COLOR_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DESKTOP_AGNOSTIC_UI_TYPE_COLOR_BUTTON, DesktopAgnosticUIColorButtonClass))
#define DESKTOP_AGNOSTIC_UI_IS_COLOR_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DESKTOP_AGNOSTIC_UI_TYPE_COLOR_BUTTON))
#define DESKTOP_AGNOSTIC_UI_IS_COLOR_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DESKTOP_AGNOSTIC_UI_TYPE_COLOR_BUTTON))
#define DESKTOP_AGNOSTIC_UI_COLOR_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DESKTOP_AGNOSTIC_UI_TYPE_COLOR_BUTTON, DesktopAgnosticUIColorButtonClass))

typedef struct _DesktopAgnosticUIColorButton DesktopAgnosticUIColorButton;
typedef struct _DesktopAgnosticUIColorButtonClass DesktopAgnosticUIColorButtonClass;
typedef struct _DesktopAgnosticUIColorButtonPrivate DesktopAgnosticUIColorButtonPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _DesktopAgnosticUIColorButton {
	GtkColorButton parent_instance;
	DesktopAgnosticUIColorButtonPrivate * priv;
};

struct _DesktopAgnosticUIColorButtonClass {
	GtkColorButtonClass parent_class;
};

struct _DesktopAgnosticUIColorButtonPrivate {
	gulong da_color_signal;
	DesktopAgnosticColor* _da_color;
};


static DesktopAgnosticColor* desktop_agnostic_ui_color_button_ZERO;
static DesktopAgnosticColor* desktop_agnostic_ui_color_button_ZERO = NULL;
static gpointer desktop_agnostic_ui_color_button_parent_class = NULL;

GType desktop_agnostic_ui_color_button_get_type (void) G_GNUC_CONST;
#define DESKTOP_AGNOSTIC_UI_COLOR_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DESKTOP_AGNOSTIC_UI_TYPE_COLOR_BUTTON, DesktopAgnosticUIColorButtonPrivate))
enum  {
	DESKTOP_AGNOSTIC_UI_COLOR_BUTTON_DUMMY_PROPERTY,
	DESKTOP_AGNOSTIC_UI_COLOR_BUTTON_DA_COLOR
};
DesktopAgnosticUIColorButton* desktop_agnostic_ui_color_button_new_with_color (DesktopAgnosticColor* color);
DesktopAgnosticUIColorButton* desktop_agnostic_ui_color_button_construct_with_color (GType object_type, DesktopAgnosticColor* color);
static void desktop_agnostic_ui_color_button_on_color_set (DesktopAgnosticUIColorButton* self);
static void desktop_agnostic_ui_color_button_real_constructed (GObject* base);
static void desktop_agnostic_ui_color_button_on_da_color_changed (DesktopAgnosticUIColorButton* self, GParamSpec* pspec);
static void _desktop_agnostic_ui_color_button_on_color_set_gtk_color_button_color_set (GtkColorButton* _sender, gpointer self);
DesktopAgnosticColor* desktop_agnostic_ui_color_button_get_da_color (DesktopAgnosticUIColorButton* self);
static void desktop_agnostic_ui_color_button_da_color_notify (DesktopAgnosticUIColorButton* self);
void desktop_agnostic_ui_color_button_set_color (DesktopAgnosticUIColorButton* self, GdkColor* color);
void desktop_agnostic_ui_color_button_set_alpha (DesktopAgnosticUIColorButton* self, guint16 alpha);
DesktopAgnosticUIColorButton* desktop_agnostic_ui_color_button_new (void);
DesktopAgnosticUIColorButton* desktop_agnostic_ui_color_button_construct (GType object_type);
void desktop_agnostic_ui_color_button_set_da_color (DesktopAgnosticUIColorButton* self, DesktopAgnosticColor* value);
static void desktop_agnostic_ui_color_button_finalize (GObject* obj);
static void desktop_agnostic_ui_color_button_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void desktop_agnostic_ui_color_button_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);



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


DesktopAgnosticUIColorButton* desktop_agnostic_ui_color_button_construct_with_color (GType object_type, DesktopAgnosticColor* color) {
	DesktopAgnosticUIColorButton * self;
	GdkColor _tmp0_ = {0};
	GdkColor _tmp1_;
	g_return_val_if_fail (color != NULL, NULL);
	self = g_object_newv (object_type, 0, NULL);
	gtk_color_button_set_color ((GtkColorButton*) self, (_tmp1_ = (desktop_agnostic_color_get_color (color, &_tmp0_), _tmp0_), &_tmp1_));
	gtk_color_button_set_alpha ((GtkColorButton*) self, desktop_agnostic_color_get_alpha (color));
	desktop_agnostic_ui_color_button_on_color_set (self);
	return self;
}


DesktopAgnosticUIColorButton* desktop_agnostic_ui_color_button_new_with_color (DesktopAgnosticColor* color) {
	return desktop_agnostic_ui_color_button_construct_with_color (DESKTOP_AGNOSTIC_UI_TYPE_COLOR_BUTTON, color);
}


static void _desktop_agnostic_ui_color_button_on_color_set_gtk_color_button_color_set (GtkColorButton* _sender, gpointer self) {
	desktop_agnostic_ui_color_button_on_color_set (self);
}


static void desktop_agnostic_ui_color_button_real_constructed (GObject* base) {
	DesktopAgnosticUIColorButton * self;
	self = (DesktopAgnosticUIColorButton*) base;
	gtk_color_button_set_use_alpha ((GtkColorButton*) self, TRUE);
	self->priv->da_color_signal = g_signal_connect (self, "notify::da-color", (GCallback) desktop_agnostic_ui_color_button_on_da_color_changed, NULL);
	g_signal_connect_object ((GtkColorButton*) self, "color-set", (GCallback) _desktop_agnostic_ui_color_button_on_color_set_gtk_color_button_color_set, self, 0);
}


static void desktop_agnostic_ui_color_button_on_da_color_changed (DesktopAgnosticUIColorButton* self, GParamSpec* pspec) {
	g_return_if_fail (self != NULL);
	g_return_if_fail (pspec != NULL);
	if (self->priv->_da_color == NULL) {
		GdkColor _tmp0_ = {0};
		GdkColor _tmp1_;
		gtk_color_button_set_color ((GtkColorButton*) self, (_tmp1_ = (desktop_agnostic_color_get_color (desktop_agnostic_ui_color_button_ZERO, &_tmp0_), _tmp0_), &_tmp1_));
		gtk_color_button_set_alpha ((GtkColorButton*) self, desktop_agnostic_color_get_alpha (desktop_agnostic_ui_color_button_ZERO));
	} else {
		GdkColor _tmp2_ = {0};
		GdkColor _tmp3_;
		gtk_color_button_set_color ((GtkColorButton*) self, (_tmp3_ = (desktop_agnostic_color_get_color (self->priv->_da_color, &_tmp2_), _tmp2_), &_tmp3_));
		gtk_color_button_set_alpha ((GtkColorButton*) self, desktop_agnostic_color_get_alpha (self->priv->_da_color));
	}
}


/**
     * Emits the non-internal signal callbacks for the da-color property.
     */
static void desktop_agnostic_ui_color_button_da_color_notify (DesktopAgnosticUIColorButton* self) {
	g_return_if_fail (self != NULL);
	g_signal_handler_block (self, self->priv->da_color_signal);
	g_object_notify ((GObject*) self, "da-color");
	g_signal_handler_unblock (self, self->priv->da_color_signal);
}


/**
     * Updates the da-color property when the color is updated via the UI.
     */
static void desktop_agnostic_ui_color_button_on_color_set (DesktopAgnosticUIColorButton* self) {
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	if (self->priv->_da_color == NULL) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = self->priv->_da_color == desktop_agnostic_ui_color_button_ZERO;
	}
	if (_tmp0_) {
		GdkColor _tmp1_ = {0};
		GdkColor _tmp2_;
		DesktopAgnosticColor* _tmp3_;
		self->priv->_da_color = (_tmp3_ = desktop_agnostic_color_new ((_tmp2_ = (gtk_color_button_get_color ((GtkColorButton*) self, &_tmp1_), _tmp1_), &_tmp2_), (gushort) gtk_color_button_get_alpha ((GtkColorButton*) self)), _g_object_unref0 (self->priv->_da_color), _tmp3_);
	} else {
		GdkColor _tmp4_ = {0};
		GdkColor _tmp5_;
		desktop_agnostic_color_set_color (self->priv->_da_color, (_tmp5_ = (gtk_color_button_get_color ((GtkColorButton*) self, &_tmp4_), _tmp4_), &_tmp5_));
		desktop_agnostic_color_set_alpha (self->priv->_da_color, gtk_color_button_get_alpha ((GtkColorButton*) self));
	}
	desktop_agnostic_ui_color_button_da_color_notify (self);
}


void desktop_agnostic_ui_color_button_set_color (DesktopAgnosticUIColorButton* self, GdkColor* color) {
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	if (self->priv->_da_color == NULL) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = self->priv->_da_color == desktop_agnostic_ui_color_button_ZERO;
	}
	if (_tmp0_) {
		DesktopAgnosticColor* _tmp1_;
		self->priv->_da_color = (_tmp1_ = desktop_agnostic_color_new (color, G_MAXUSHORT), _g_object_unref0 (self->priv->_da_color), _tmp1_);
	} else {
		desktop_agnostic_color_set_alpha (self->priv->_da_color, gtk_color_button_get_alpha ((GtkColorButton*) self));
	}
	desktop_agnostic_ui_color_button_da_color_notify (self);
}


void desktop_agnostic_ui_color_button_set_alpha (DesktopAgnosticUIColorButton* self, guint16 alpha) {
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	if (self->priv->_da_color == NULL) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = self->priv->_da_color == desktop_agnostic_ui_color_button_ZERO;
	}
	if (_tmp0_) {
		GdkColor _tmp1_ = {0};
		GdkColor _tmp2_;
		DesktopAgnosticColor* _tmp3_;
		self->priv->_da_color = (_tmp3_ = desktop_agnostic_color_new ((_tmp2_ = (desktop_agnostic_color_get_color (desktop_agnostic_ui_color_button_ZERO, &_tmp1_), _tmp1_), &_tmp2_), (gushort) alpha), _g_object_unref0 (self->priv->_da_color), _tmp3_);
	} else {
		desktop_agnostic_color_set_alpha (self->priv->_da_color, (guint) alpha);
	}
	desktop_agnostic_ui_color_button_da_color_notify (self);
	gtk_color_button_set_alpha (GTK_COLOR_BUTTON (self), alpha);
}


DesktopAgnosticUIColorButton* desktop_agnostic_ui_color_button_construct (GType object_type) {
	DesktopAgnosticUIColorButton * self;
	self = g_object_newv (object_type, 0, NULL);
	return self;
}


DesktopAgnosticUIColorButton* desktop_agnostic_ui_color_button_new (void) {
	return desktop_agnostic_ui_color_button_construct (DESKTOP_AGNOSTIC_UI_TYPE_COLOR_BUTTON);
}


DesktopAgnosticColor* desktop_agnostic_ui_color_button_get_da_color (DesktopAgnosticUIColorButton* self) {
	DesktopAgnosticColor* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self->priv->_da_color;
	return result;
}


void desktop_agnostic_ui_color_button_set_da_color (DesktopAgnosticUIColorButton* self, DesktopAgnosticColor* value) {
	DesktopAgnosticColor* _tmp0_;
	g_return_if_fail (self != NULL);
	self->priv->_da_color = (_tmp0_ = _g_object_ref0 (value), _g_object_unref0 (self->priv->_da_color), _tmp0_);
	g_object_notify ((GObject *) self, "da-color");
}


static void desktop_agnostic_ui_color_button_class_init (DesktopAgnosticUIColorButtonClass * klass) {
	desktop_agnostic_ui_color_button_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (DesktopAgnosticUIColorButtonPrivate));
	G_OBJECT_CLASS (klass)->constructed = desktop_agnostic_ui_color_button_real_constructed;
	G_OBJECT_CLASS (klass)->get_property = desktop_agnostic_ui_color_button_get_property;
	G_OBJECT_CLASS (klass)->set_property = desktop_agnostic_ui_color_button_set_property;
	G_OBJECT_CLASS (klass)->finalize = desktop_agnostic_ui_color_button_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DESKTOP_AGNOSTIC_UI_COLOR_BUTTON_DA_COLOR, g_param_spec_object ("da-color", "da-color", "da-color", DESKTOP_AGNOSTIC_TYPE_COLOR, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	desktop_agnostic_ui_color_button_ZERO = desktop_agnostic_color_new_from_values ((gushort) 0, (gushort) 0, (gushort) 0, G_MAXUSHORT);
}


static void desktop_agnostic_ui_color_button_instance_init (DesktopAgnosticUIColorButton * self) {
	self->priv = DESKTOP_AGNOSTIC_UI_COLOR_BUTTON_GET_PRIVATE (self);
	self->priv->_da_color = _g_object_ref0 (desktop_agnostic_ui_color_button_ZERO);
}


static void desktop_agnostic_ui_color_button_finalize (GObject* obj) {
	DesktopAgnosticUIColorButton * self;
	self = DESKTOP_AGNOSTIC_UI_COLOR_BUTTON (obj);
	_g_object_unref0 (self->priv->_da_color);
	G_OBJECT_CLASS (desktop_agnostic_ui_color_button_parent_class)->finalize (obj);
}


GType desktop_agnostic_ui_color_button_get_type (void) {
	static volatile gsize desktop_agnostic_ui_color_button_type_id__volatile = 0;
	if (g_once_init_enter (&desktop_agnostic_ui_color_button_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (DesktopAgnosticUIColorButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) desktop_agnostic_ui_color_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DesktopAgnosticUIColorButton), 0, (GInstanceInitFunc) desktop_agnostic_ui_color_button_instance_init, NULL };
		GType desktop_agnostic_ui_color_button_type_id;
		desktop_agnostic_ui_color_button_type_id = g_type_register_static (GTK_TYPE_COLOR_BUTTON, "DesktopAgnosticUIColorButton", &g_define_type_info, 0);
		g_once_init_leave (&desktop_agnostic_ui_color_button_type_id__volatile, desktop_agnostic_ui_color_button_type_id);
	}
	return desktop_agnostic_ui_color_button_type_id__volatile;
}


static void desktop_agnostic_ui_color_button_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	DesktopAgnosticUIColorButton * self;
	self = DESKTOP_AGNOSTIC_UI_COLOR_BUTTON (object);
	switch (property_id) {
		case DESKTOP_AGNOSTIC_UI_COLOR_BUTTON_DA_COLOR:
		g_value_set_object (value, desktop_agnostic_ui_color_button_get_da_color (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void desktop_agnostic_ui_color_button_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	DesktopAgnosticUIColorButton * self;
	self = DESKTOP_AGNOSTIC_UI_COLOR_BUTTON (object);
	switch (property_id) {
		case DESKTOP_AGNOSTIC_UI_COLOR_BUTTON_DA_COLOR:
		desktop_agnostic_ui_color_button_set_da_color (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}




