/* error_entry.c generated by valac 0.17.3.8-fd35, the Vala compiler
 * generated from error_entry.vala, do not modify */

/*
 * This file is part of LaTeXila.
 *
 * Copyright © 2012 Sébastien Wilmet
 *
 * LaTeXila 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.
 *
 * LaTeXila 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 LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>


#define TYPE_ERROR_ENTRY (error_entry_get_type ())
#define ERROR_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ERROR_ENTRY, ErrorEntry))
#define ERROR_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ERROR_ENTRY, ErrorEntryClass))
#define IS_ERROR_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ERROR_ENTRY))
#define IS_ERROR_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_ERROR_ENTRY))
#define ERROR_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_ERROR_ENTRY, ErrorEntryClass))

typedef struct _ErrorEntry ErrorEntry;
typedef struct _ErrorEntryClass ErrorEntryClass;
typedef struct _ErrorEntryPrivate ErrorEntryPrivate;
typedef struct _Block20Data Block20Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _ErrorEntry {
	GtkEntry parent_instance;
	ErrorEntryPrivate * priv;
};

struct _ErrorEntryClass {
	GtkEntryClass parent_class;
};

struct _ErrorEntryPrivate {
	gboolean _error;
};

struct _Block20Data {
	int _ref_count_;
	ErrorEntry * self;
	GtkCssProvider* provider;
};


static gpointer error_entry_parent_class = NULL;

GType error_entry_get_type (void) G_GNUC_CONST;
#define ERROR_ENTRY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_ERROR_ENTRY, ErrorEntryPrivate))
enum  {
	ERROR_ENTRY_DUMMY_PROPERTY,
	ERROR_ENTRY_ERROR
};
ErrorEntry* error_entry_new (void);
ErrorEntry* error_entry_construct (GType object_type);
static Block20Data* block20_data_ref (Block20Data* _data20_);
static void block20_data_unref (void * _userdata_);
static void __lambda79_ (Block20Data* _data20_);
gboolean error_entry_get_error (ErrorEntry* self);
static void ___lambda79__g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self);
void error_entry_set_error (ErrorEntry* self, gboolean value);
static void error_entry_finalize (GObject* obj);
static void _vala_error_entry_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_error_entry_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);


static Block20Data* block20_data_ref (Block20Data* _data20_) {
	g_atomic_int_inc (&_data20_->_ref_count_);
	return _data20_;
}


static void block20_data_unref (void * _userdata_) {
	Block20Data* _data20_;
	_data20_ = (Block20Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data20_->_ref_count_)) {
		ErrorEntry * self;
		self = _data20_->self;
		_g_object_unref0 (_data20_->provider);
		_g_object_unref0 (self);
		g_slice_free (Block20Data, _data20_);
	}
}


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


static void __lambda79_ (Block20Data* _data20_) {
	ErrorEntry * self;
	GtkStyleContext* _tmp0_ = NULL;
	GtkStyleContext* _tmp1_;
	GtkStyleContext* context;
	gboolean _tmp2_;
	self = _data20_->self;
	_tmp0_ = gtk_widget_get_style_context ((GtkWidget*) self);
	_tmp1_ = _g_object_ref0 (_tmp0_);
	context = _tmp1_;
	_tmp2_ = self->priv->_error;
	if (_tmp2_) {
		GtkStyleContext* _tmp3_;
		GtkCssProvider* _tmp4_;
		_tmp3_ = context;
		_tmp4_ = _data20_->provider;
		gtk_style_context_add_provider (_tmp3_, (GtkStyleProvider*) _tmp4_, (guint) GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
	} else {
		GtkStyleContext* _tmp5_;
		GtkCssProvider* _tmp6_;
		_tmp5_ = context;
		_tmp6_ = _data20_->provider;
		gtk_style_context_remove_provider (_tmp5_, (GtkStyleProvider*) _tmp6_);
	}
	_g_object_unref0 (context);
}


static void ___lambda79__g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self) {
	__lambda79_ (self);
}


ErrorEntry* error_entry_construct (GType object_type) {
	ErrorEntry * self = NULL;
	Block20Data* _data20_;
	gchar* _tmp0_;
	gchar* style;
	GtkCssProvider* _tmp1_;
	GError * _inner_error_ = NULL;
	_data20_ = g_slice_new0 (Block20Data);
	_data20_->_ref_count_ = 1;
	self = (ErrorEntry*) g_object_new (object_type, NULL);
	_data20_->self = g_object_ref (self);
	_tmp0_ = g_strdup ("\n" \
"        GtkEntry {\n" \
"            color: @error_fg_color;\n" \
"            background-image: none;\n" \
"            background-color: @error_bg_color;\n" \
"        }\n" \
"        ");
	style = _tmp0_;
	_tmp1_ = gtk_css_provider_new ();
	_data20_->provider = _tmp1_;
	{
		GtkCssProvider* _tmp2_;
		const gchar* _tmp3_;
		_tmp2_ = _data20_->provider;
		_tmp3_ = style;
		gtk_css_provider_load_from_data (_tmp2_, _tmp3_, (gssize) (-1), &_inner_error_);
		if (_inner_error_ != NULL) {
			goto __catch51_g_error;
		}
	}
	goto __finally51;
	__catch51_g_error:
	{
		GError* e = NULL;
		GError* _tmp4_;
		const gchar* _tmp5_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp4_ = e;
		_tmp5_ = _tmp4_->message;
		g_warning ("error_entry.vala:45: Impossible to load CSS style for the error entry:" \
" %s", _tmp5_);
		_g_error_free0 (e);
		_g_free0 (style);
		block20_data_unref (_data20_);
		_data20_ = NULL;
		return self;
	}
	__finally51:
	if (_inner_error_ != NULL) {
		_g_free0 (style);
		block20_data_unref (_data20_);
		_data20_ = NULL;
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
	g_signal_connect_data ((GObject*) self, "notify::error", (GCallback) ___lambda79__g_object_notify, block20_data_ref (_data20_), (GClosureNotify) block20_data_unref, 0);
	_g_free0 (style);
	block20_data_unref (_data20_);
	_data20_ = NULL;
	return self;
}


ErrorEntry* error_entry_new (void) {
	return error_entry_construct (TYPE_ERROR_ENTRY);
}


gboolean error_entry_get_error (ErrorEntry* self) {
	gboolean result;
	gboolean _tmp0_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_error;
	result = _tmp0_;
	return result;
}


void error_entry_set_error (ErrorEntry* self, gboolean value) {
	gboolean _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	self->priv->_error = _tmp0_;
	g_object_notify ((GObject *) self, "error");
}


static void error_entry_class_init (ErrorEntryClass * klass) {
	error_entry_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (ErrorEntryPrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_error_entry_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_error_entry_set_property;
	G_OBJECT_CLASS (klass)->finalize = error_entry_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), ERROR_ENTRY_ERROR, g_param_spec_boolean ("error", "error", "error", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
}


static void error_entry_instance_init (ErrorEntry * self) {
	self->priv = ERROR_ENTRY_GET_PRIVATE (self);
	self->priv->_error = FALSE;
}


static void error_entry_finalize (GObject* obj) {
	ErrorEntry * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_ERROR_ENTRY, ErrorEntry);
	G_OBJECT_CLASS (error_entry_parent_class)->finalize (obj);
}


GType error_entry_get_type (void) {
	static volatile gsize error_entry_type_id__volatile = 0;
	if (g_once_init_enter (&error_entry_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ErrorEntryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) error_entry_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ErrorEntry), 0, (GInstanceInitFunc) error_entry_instance_init, NULL };
		GType error_entry_type_id;
		error_entry_type_id = g_type_register_static (GTK_TYPE_ENTRY, "ErrorEntry", &g_define_type_info, 0);
		g_once_init_leave (&error_entry_type_id__volatile, error_entry_type_id);
	}
	return error_entry_type_id__volatile;
}


static void _vala_error_entry_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	ErrorEntry * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_ERROR_ENTRY, ErrorEntry);
	switch (property_id) {
		case ERROR_ENTRY_ERROR:
		g_value_set_boolean (value, error_entry_get_error (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_error_entry_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	ErrorEntry * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_ERROR_ENTRY, ErrorEntry);
	switch (property_id) {
		case ERROR_ENTRY_ERROR:
		error_entry_set_error (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



