/* ImpostorWidget.c generated by valac 0.26.2, the Vala compiler
 * generated from ImpostorWidget.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 <float.h>
#include <math.h>
#include <gdk/gdk.h>


#define TYPE_IMPOSTOR_WIDGET (impostor_widget_get_type ())
#define IMPOSTOR_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_IMPOSTOR_WIDGET, ImpostorWidget))
#define IMPOSTOR_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_IMPOSTOR_WIDGET, ImpostorWidgetClass))
#define IS_IMPOSTOR_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_IMPOSTOR_WIDGET))
#define IS_IMPOSTOR_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_IMPOSTOR_WIDGET))
#define IMPOSTOR_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_IMPOSTOR_WIDGET, ImpostorWidgetClass))

typedef struct _ImpostorWidget ImpostorWidget;
typedef struct _ImpostorWidgetClass ImpostorWidgetClass;
typedef struct _ImpostorWidgetPrivate ImpostorWidgetPrivate;
#define _cairo_surface_destroy0(var) ((var == NULL) ? NULL : (var = (cairo_surface_destroy (var), NULL)))
#define _cairo_destroy0(var) ((var == NULL) ? NULL : (var = (cairo_destroy (var), NULL)))

struct _ImpostorWidget {
	GtkImage parent_instance;
	ImpostorWidgetPrivate * priv;
};

struct _ImpostorWidgetClass {
	GtkImageClass parent_class;
};

struct _ImpostorWidgetPrivate {
	cairo_surface_t* surface;
};


static gpointer impostor_widget_parent_class = NULL;

GType impostor_widget_get_type (void) G_GNUC_CONST;
#define IMPOSTOR_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_IMPOSTOR_WIDGET, ImpostorWidgetPrivate))
enum  {
	IMPOSTOR_WIDGET_DUMMY_PROPERTY
};
ImpostorWidget* impostor_widget_new (void);
ImpostorWidget* impostor_widget_construct (GType object_type);
static gboolean impostor_widget_real_draw (GtkWidget* base, cairo_t* ct);
void impostor_widget_clone (ImpostorWidget* self, GtkWidget* widget);
static void impostor_widget_finalize (GObject* obj);


ImpostorWidget* impostor_widget_construct (GType object_type) {
	ImpostorWidget * self = NULL;
	self = (ImpostorWidget*) g_object_new (object_type, NULL);
	gtk_widget_set_halign (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget), GTK_ALIGN_FILL);
	gtk_widget_set_valign (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget), GTK_ALIGN_FILL);
	return self;
}


ImpostorWidget* impostor_widget_new (void) {
	return impostor_widget_construct (TYPE_IMPOSTOR_WIDGET);
}


static gboolean impostor_widget_real_draw (GtkWidget* base, cairo_t* ct) {
	ImpostorWidget * self;
	gboolean result = FALSE;
	cairo_surface_t* _tmp0_ = NULL;
	cairo_t* _tmp1_ = NULL;
	cairo_surface_t* _tmp2_ = NULL;
	cairo_t* _tmp3_ = NULL;
	gint _tmp4_ = 0;
	gint _tmp5_ = 0;
	cairo_t* _tmp6_ = NULL;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, TYPE_IMPOSTOR_WIDGET, ImpostorWidget);
	g_return_val_if_fail (ct != NULL, FALSE);
	_tmp0_ = self->priv->surface;
	if (_tmp0_ == NULL) {
		result = FALSE;
		return result;
	}
	_tmp1_ = ct;
	_tmp2_ = self->priv->surface;
	cairo_set_source_surface (_tmp1_, _tmp2_, (gdouble) 0, (gdouble) 0);
	_tmp3_ = ct;
	_tmp4_ = gtk_widget_get_allocated_width (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
	_tmp5_ = gtk_widget_get_allocated_height (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
	cairo_rectangle (_tmp3_, (gdouble) 0, (gdouble) 0, (gdouble) _tmp4_, (gdouble) _tmp5_);
	_tmp6_ = ct;
	cairo_fill (_tmp6_);
	result = FALSE;
	return result;
}


void impostor_widget_clone (ImpostorWidget* self, GtkWidget* widget) {
	gint widget_width = 0;
	GtkWidget* _tmp0_ = NULL;
	gint _tmp1_ = 0;
	gint widget_height = 0;
	GtkWidget* _tmp2_ = NULL;
	gint _tmp3_ = 0;
	GtkWidget* _tmp4_ = NULL;
	GdkWindow* _tmp5_ = NULL;
	cairo_surface_t* _tmp6_ = NULL;
	cairo_t* ct = NULL;
	cairo_surface_t* _tmp7_ = NULL;
	cairo_t* _tmp8_ = NULL;
	GtkWidget* _tmp9_ = NULL;
	g_return_if_fail (IS_IMPOSTOR_WIDGET (self));
	g_return_if_fail (GTK_IS_WIDGET (widget));
	_tmp0_ = widget;
	_tmp1_ = gtk_widget_get_allocated_width (_tmp0_);
	widget_width = _tmp1_;
	_tmp2_ = widget;
	_tmp3_ = gtk_widget_get_allocated_height (_tmp2_);
	widget_height = _tmp3_;
	_tmp4_ = widget;
	_tmp5_ = gtk_widget_get_window (_tmp4_);
	_tmp6_ = gdk_window_create_similar_surface (_tmp5_, CAIRO_CONTENT_COLOR_ALPHA, widget_width, widget_height);
	_cairo_surface_destroy0 (self->priv->surface);
	self->priv->surface = _tmp6_;
	_tmp7_ = self->priv->surface;
	_tmp8_ = cairo_create (_tmp7_);
	ct = _tmp8_;
	_tmp9_ = widget;
	gtk_widget_draw (_tmp9_, ct);
	_cairo_destroy0 (ct);
}


static void impostor_widget_class_init (ImpostorWidgetClass * klass) {
	impostor_widget_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (ImpostorWidgetPrivate));
	((GtkWidgetClass *) klass)->draw = impostor_widget_real_draw;
	G_OBJECT_CLASS (klass)->finalize = impostor_widget_finalize;
}


static void impostor_widget_instance_init (ImpostorWidget * self) {
	self->priv = IMPOSTOR_WIDGET_GET_PRIVATE (self);
}


static void impostor_widget_finalize (GObject* obj) {
	ImpostorWidget * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_IMPOSTOR_WIDGET, ImpostorWidget);
	_cairo_surface_destroy0 (self->priv->surface);
	G_OBJECT_CLASS (impostor_widget_parent_class)->finalize (obj);
}


GType impostor_widget_get_type (void) {
	static volatile gsize impostor_widget_type_id__volatile = 0;
	if (g_once_init_enter (&impostor_widget_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ImpostorWidgetClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) impostor_widget_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ImpostorWidget), 0, (GInstanceInitFunc) impostor_widget_instance_init, NULL };
		GType impostor_widget_type_id;
		impostor_widget_type_id = g_type_register_static (gtk_image_get_type (), "ImpostorWidget", &g_define_type_info, 0);
		g_once_init_leave (&impostor_widget_type_id__volatile, impostor_widget_type_id);
	}
	return impostor_widget_type_id__volatile;
}



