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

/*  This file is part of corebird, a Gtk+ linux Twitter client.
 *  Copyright (C) 2013 Timm Bäder
 *
 *  corebird 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.
 *
 *  corebird 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 corebird.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <cairo.h>
#include <stdlib.h>
#include <string.h>
#include <atk/atk.h>
#include <gdk/gdk.h>
#include <float.h>
#include <math.h>


#define TYPE_BADGE_RADIO_BUTTON (badge_radio_button_get_type ())
#define BADGE_RADIO_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_BADGE_RADIO_BUTTON, BadgeRadioButton))
#define BADGE_RADIO_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_BADGE_RADIO_BUTTON, BadgeRadioButtonClass))
#define IS_BADGE_RADIO_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_BADGE_RADIO_BUTTON))
#define IS_BADGE_RADIO_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_BADGE_RADIO_BUTTON))
#define BADGE_RADIO_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_BADGE_RADIO_BUTTON, BadgeRadioButtonClass))

typedef struct _BadgeRadioButton BadgeRadioButton;
typedef struct _BadgeRadioButtonClass BadgeRadioButtonClass;
typedef struct _BadgeRadioButtonPrivate BadgeRadioButtonPrivate;
enum  {
	BADGE_RADIO_BUTTON_0_PROPERTY,
	BADGE_RADIO_BUTTON_SHOW_BADGE_PROPERTY,
	BADGE_RADIO_BUTTON_NUM_PROPERTIES
};
static GParamSpec* badge_radio_button_properties[BADGE_RADIO_BUTTON_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _BadgeRadioButton {
	GtkRadioButton parent_instance;
	BadgeRadioButtonPrivate * priv;
};

struct _BadgeRadioButtonClass {
	GtkRadioButtonClass parent_class;
};

struct _BadgeRadioButtonPrivate {
	gboolean _show_badge;
};


static gpointer badge_radio_button_parent_class = NULL;

GType badge_radio_button_get_type (void) G_GNUC_CONST;
#define BADGE_RADIO_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_BADGE_RADIO_BUTTON, BadgeRadioButtonPrivate))
#define BADGE_RADIO_BUTTON_BADGE_SIZE 10
BadgeRadioButton* badge_radio_button_new (GtkRadioButton* group, const gchar* icon_name, const gchar* text);
BadgeRadioButton* badge_radio_button_construct (GType object_type, GtkRadioButton* group, const gchar* icon_name, const gchar* text);
static gboolean badge_radio_button_real_draw (GtkWidget* base, cairo_t* ct);
gboolean badge_radio_button_get_show_badge (BadgeRadioButton* self);
void badge_radio_button_set_show_badge (BadgeRadioButton* self, gboolean value);
static void badge_radio_button_finalize (GObject * obj);
static void _vala_badge_radio_button_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_badge_radio_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;
}


BadgeRadioButton* badge_radio_button_construct (GType object_type, GtkRadioButton* group, const gchar* icon_name, const gchar* text) {
	BadgeRadioButton * self = NULL;
	GtkRadioButton* _tmp0_;
	GtkStyleContext* _tmp1_;
	GtkImage* i = NULL;
	const gchar* _tmp2_;
	GtkImage* _tmp3_;
	GtkImage* _tmp4_;
	const gchar* _tmp5_;
	g_return_val_if_fail (GTK_IS_RADIO_BUTTON (group), NULL);
	g_return_val_if_fail (icon_name != NULL, NULL);
	g_return_val_if_fail (text != NULL, NULL);
	_tmp0_ = group;
	self = (BadgeRadioButton*) g_object_new (object_type, "group", _tmp0_, NULL);
	_tmp1_ = gtk_widget_get_style_context (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
	gtk_style_context_add_class (_tmp1_, "image-button");
	_tmp2_ = icon_name;
	_tmp3_ = (GtkImage*) gtk_image_new_from_icon_name (_tmp2_, GTK_ICON_SIZE_BUTTON);
	g_object_ref_sink (_tmp3_);
	i = _tmp3_;
	_tmp4_ = i;
	gtk_container_add (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_container_get_type (), GtkContainer), G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, gtk_widget_get_type (), GtkWidget));
	gtk_toggle_button_set_mode (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_toggle_button_get_type (), GtkToggleButton), FALSE);
	gtk_widget_set_focus_on_click (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget), FALSE);
	gtk_widget_set_hexpand (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget), TRUE);
	_tmp5_ = text;
	if (g_strcmp0 (_tmp5_, "") != 0) {
		const gchar* _tmp6_;
		AtkObject* accessible = NULL;
		AtkObject* _tmp7_;
		AtkObject* _tmp8_;
		AtkObject* _tmp9_;
		const gchar* _tmp10_;
		_tmp6_ = text;
		gtk_widget_set_tooltip_text (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget), _tmp6_);
		_tmp7_ = gtk_widget_get_accessible (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
		_tmp8_ = _g_object_ref0 (_tmp7_);
		accessible = _tmp8_;
		_tmp9_ = accessible;
		_tmp10_ = text;
		atk_object_set_name (_tmp9_, _tmp10_);
		_g_object_unref0 (accessible);
	}
	_g_object_unref0 (i);
	return self;
}


BadgeRadioButton* badge_radio_button_new (GtkRadioButton* group, const gchar* icon_name, const gchar* text) {
	return badge_radio_button_construct (TYPE_BADGE_RADIO_BUTTON, group, icon_name, text);
}


static gboolean badge_radio_button_real_draw (GtkWidget* base, cairo_t* ct) {
	BadgeRadioButton * self;
	gboolean result = FALSE;
	cairo_t* _tmp0_;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_;
	gboolean _tmp3_;
	GtkAllocation child_allocation = {0};
	GtkAllocation allocation = {0};
	GtkWidget* _tmp5_;
	GtkAllocation _tmp6_ = {0};
	GtkAllocation _tmp7_ = {0};
	GtkStyleContext* context = NULL;
	GtkStyleContext* _tmp8_;
	GtkStyleContext* _tmp9_;
	gint x = 0;
	GtkAllocation _tmp10_;
	gint _tmp11_;
	GtkAllocation _tmp12_;
	gint _tmp13_;
	GtkAllocation _tmp14_;
	gint _tmp15_;
	gint y = 0;
	GtkStyleContext* _tmp16_;
	GtkStyleContext* _tmp17_;
	GtkStyleContext* _tmp18_;
	cairo_t* _tmp19_;
	gint _tmp20_;
	gint _tmp21_;
	GtkStyleContext* _tmp22_;
	cairo_t* _tmp23_;
	gint _tmp24_;
	gint _tmp25_;
	GtkStyleContext* _tmp26_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, TYPE_BADGE_RADIO_BUTTON, BadgeRadioButton);
	g_return_val_if_fail (ct != NULL, FALSE);
	_tmp0_ = ct;
	GTK_WIDGET_CLASS (badge_radio_button_parent_class)->draw (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_radio_button_get_type (), GtkRadioButton), gtk_widget_get_type (), GtkWidget), _tmp0_);
	_tmp2_ = badge_radio_button_get_show_badge (self);
	_tmp3_ = _tmp2_;
	if (!_tmp3_) {
		_tmp1_ = TRUE;
	} else {
		GtkWidget* _tmp4_;
		_tmp4_ = gtk_bin_get_child (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_bin_get_type (), GtkBin));
		_tmp1_ = _tmp4_ == NULL;
	}
	if (_tmp1_) {
		result = GDK_EVENT_PROPAGATE;
		return result;
	}
	_tmp5_ = gtk_bin_get_child (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_bin_get_type (), GtkBin));
	gtk_widget_get_allocation (_tmp5_, &_tmp6_);
	child_allocation = _tmp6_;
	gtk_widget_get_allocation (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget), &_tmp7_);
	allocation = _tmp7_;
	_tmp8_ = gtk_widget_get_style_context (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
	_tmp9_ = _g_object_ref0 (_tmp8_);
	context = _tmp9_;
	_tmp10_ = allocation;
	_tmp11_ = _tmp10_.x;
	_tmp12_ = child_allocation;
	_tmp13_ = _tmp12_.x;
	_tmp14_ = child_allocation;
	_tmp15_ = _tmp14_.width;
	x = ((_tmp11_ - _tmp13_) + _tmp15_) - BADGE_RADIO_BUTTON_BADGE_SIZE;
	y = 5;
	_tmp16_ = context;
	gtk_style_context_save (_tmp16_);
	_tmp17_ = context;
	gtk_style_context_add_class (_tmp17_, "badge");
	_tmp18_ = context;
	_tmp19_ = ct;
	_tmp20_ = x;
	_tmp21_ = y;
	gtk_render_background (_tmp18_, _tmp19_, (gdouble) _tmp20_, (gdouble) _tmp21_, (gdouble) BADGE_RADIO_BUTTON_BADGE_SIZE, (gdouble) BADGE_RADIO_BUTTON_BADGE_SIZE);
	_tmp22_ = context;
	_tmp23_ = ct;
	_tmp24_ = x;
	_tmp25_ = y;
	gtk_render_frame (_tmp22_, _tmp23_, (gdouble) _tmp24_, (gdouble) _tmp25_, (gdouble) BADGE_RADIO_BUTTON_BADGE_SIZE, (gdouble) BADGE_RADIO_BUTTON_BADGE_SIZE);
	_tmp26_ = context;
	gtk_style_context_restore (_tmp26_);
	result = GDK_EVENT_PROPAGATE;
	_g_object_unref0 (context);
	return result;
}


gboolean badge_radio_button_get_show_badge (BadgeRadioButton* self) {
	gboolean result;
	gboolean _tmp0_;
	g_return_val_if_fail (IS_BADGE_RADIO_BUTTON (self), FALSE);
	_tmp0_ = self->priv->_show_badge;
	result = _tmp0_;
	return result;
}


void badge_radio_button_set_show_badge (BadgeRadioButton* self, gboolean value) {
	const gchar* _tmp0_ = NULL;
	gboolean _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	g_return_if_fail (IS_BADGE_RADIO_BUTTON (self));
	_tmp1_ = value;
	if (_tmp1_) {
		_tmp0_ = "true";
	} else {
		_tmp0_ = "false";
	}
	g_debug ("BadgeRadioButton.vala:23: New show_badge value: %s", _tmp0_);
	_tmp2_ = value;
	_tmp3_ = self->priv->_show_badge;
	if (_tmp2_ != _tmp3_) {
		gboolean _tmp4_;
		_tmp4_ = value;
		self->priv->_show_badge = _tmp4_;
		gtk_widget_queue_draw (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
	}
	g_object_notify_by_pspec ((GObject *) self, badge_radio_button_properties[BADGE_RADIO_BUTTON_SHOW_BADGE_PROPERTY]);
}


static void badge_radio_button_class_init (BadgeRadioButtonClass * klass) {
	badge_radio_button_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (BadgeRadioButtonPrivate));
	((GtkWidgetClass *) klass)->draw = (gboolean (*) (GtkWidget *, cairo_t*)) badge_radio_button_real_draw;
	G_OBJECT_CLASS (klass)->get_property = _vala_badge_radio_button_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_badge_radio_button_set_property;
	G_OBJECT_CLASS (klass)->finalize = badge_radio_button_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), BADGE_RADIO_BUTTON_SHOW_BADGE_PROPERTY, badge_radio_button_properties[BADGE_RADIO_BUTTON_SHOW_BADGE_PROPERTY] = g_param_spec_boolean ("show-badge", "show-badge", "show-badge", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
}


static void badge_radio_button_instance_init (BadgeRadioButton * self) {
	self->priv = BADGE_RADIO_BUTTON_GET_PRIVATE (self);
	self->priv->_show_badge = FALSE;
}


static void badge_radio_button_finalize (GObject * obj) {
	BadgeRadioButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_BADGE_RADIO_BUTTON, BadgeRadioButton);
	G_OBJECT_CLASS (badge_radio_button_parent_class)->finalize (obj);
}


GType badge_radio_button_get_type (void) {
	static volatile gsize badge_radio_button_type_id__volatile = 0;
	if (g_once_init_enter (&badge_radio_button_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (BadgeRadioButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) badge_radio_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BadgeRadioButton), 0, (GInstanceInitFunc) badge_radio_button_instance_init, NULL };
		GType badge_radio_button_type_id;
		badge_radio_button_type_id = g_type_register_static (gtk_radio_button_get_type (), "BadgeRadioButton", &g_define_type_info, 0);
		g_once_init_leave (&badge_radio_button_type_id__volatile, badge_radio_button_type_id);
	}
	return badge_radio_button_type_id__volatile;
}


static void _vala_badge_radio_button_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	BadgeRadioButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_BADGE_RADIO_BUTTON, BadgeRadioButton);
	switch (property_id) {
		case BADGE_RADIO_BUTTON_SHOW_BADGE_PROPERTY:
		g_value_set_boolean (value, badge_radio_button_get_show_badge (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_badge_radio_button_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	BadgeRadioButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_BADGE_RADIO_BUTTON, BadgeRadioButton);
	switch (property_id) {
		case BADGE_RADIO_BUTTON_SHOW_BADGE_PROPERTY:
		badge_radio_button_set_show_badge (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



