/* tracker-cell-renderer-text.c generated by valac 0.11.5, the Vala compiler
 * generated from tracker-cell-renderer-text.vala, do not modify */

/**/
/* Copyright 2010, Martyn Russell <martyn@lanedo.com>*/
/**/
/* 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 2*/
/* 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, write to the Free Software*/
/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA*/
/* 02110-1301, USA.*/
/**/

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


#define TRACKER_TYPE_CELL_RENDERER_TEXT (tracker_cell_renderer_text_get_type ())
#define TRACKER_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TRACKER_TYPE_CELL_RENDERER_TEXT, TrackerCellRendererText))
#define TRACKER_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TRACKER_TYPE_CELL_RENDERER_TEXT, TrackerCellRendererTextClass))
#define TRACKER_IS_CELL_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TRACKER_TYPE_CELL_RENDERER_TEXT))
#define TRACKER_IS_CELL_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TRACKER_TYPE_CELL_RENDERER_TEXT))
#define TRACKER_CELL_RENDERER_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TRACKER_TYPE_CELL_RENDERER_TEXT, TrackerCellRendererTextClass))

typedef struct _TrackerCellRendererText TrackerCellRendererText;
typedef struct _TrackerCellRendererTextClass TrackerCellRendererTextClass;
typedef struct _TrackerCellRendererTextPrivate TrackerCellRendererTextPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _pango_font_description_free0(var) ((var == NULL) ? NULL : (var = (pango_font_description_free (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _pango_attribute_destroy0(var) ((var == NULL) ? NULL : (var = (pango_attribute_destroy (var), NULL)))
#define _pango_attr_list_unref0(var) ((var == NULL) ? NULL : (var = (pango_attr_list_unref (var), NULL)))

struct _TrackerCellRendererText {
	GtkCellRendererText parent_instance;
	TrackerCellRendererTextPrivate * priv;
};

struct _TrackerCellRendererTextClass {
	GtkCellRendererTextClass parent_class;
};

struct _TrackerCellRendererTextPrivate {
	gchar* _subtext;
	gboolean _show_row_hint;
	gboolean _show_subtext;
	gboolean _show_fixed_height;
	gboolean is_selected;
	gboolean is_valid;
	gint fixed_height;
};


static gpointer tracker_cell_renderer_text_parent_class = NULL;

GType tracker_cell_renderer_text_get_type (void) G_GNUC_CONST;
#define TRACKER_CELL_RENDERER_TEXT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_CELL_RENDERER_TEXT, TrackerCellRendererTextPrivate))
enum  {
	TRACKER_CELL_RENDERER_TEXT_DUMMY_PROPERTY,
	TRACKER_CELL_RENDERER_TEXT_SUBTEXT,
	TRACKER_CELL_RENDERER_TEXT_SHOW_ROW_HINT,
	TRACKER_CELL_RENDERER_TEXT_SHOW_SUBTEXT,
	TRACKER_CELL_RENDERER_TEXT_SHOW_FIXED_HEIGHT
};
static void tracker_cell_renderer_text_real_get_size (GtkCellRenderer* base, GtkWidget* widget, GdkRectangle* cell_area, gint* x_offset, gint* y_offset, gint* width, gint* height);
static void tracker_cell_renderer_text_update_text (TrackerCellRendererText* self, GtkWidget* widget, gboolean selected);
static void tracker_cell_renderer_text_real_render (GtkCellRenderer* base, GdkWindow* window, GtkWidget* widget, GdkRectangle* background_area, GdkRectangle* cell_area, GdkRectangle* expose_area, GtkCellRendererState flags);
const gchar* tracker_cell_renderer_text_get_subtext (TrackerCellRendererText* self);
gboolean tracker_cell_renderer_text_get_show_subtext (TrackerCellRendererText* self);
gboolean tracker_cell_renderer_text_get_show_fixed_height (TrackerCellRendererText* self);
TrackerCellRendererText* tracker_cell_renderer_text_new (void);
TrackerCellRendererText* tracker_cell_renderer_text_construct (GType object_type);
void tracker_cell_renderer_text_set_subtext (TrackerCellRendererText* self, const gchar* value);
gboolean tracker_cell_renderer_text_get_show_row_hint (TrackerCellRendererText* self);
void tracker_cell_renderer_text_set_show_row_hint (TrackerCellRendererText* self, gboolean value);
void tracker_cell_renderer_text_set_show_subtext (TrackerCellRendererText* self, gboolean value);
void tracker_cell_renderer_text_set_show_fixed_height (TrackerCellRendererText* self, gboolean value);
static void tracker_cell_renderer_text_finalize (GObject* obj);
static void _vala_tracker_cell_renderer_text_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_tracker_cell_renderer_text_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;
}


static gpointer _pango_font_description_copy0 (gpointer self) {
	return self ? pango_font_description_copy (self) : NULL;
}


static void tracker_cell_renderer_text_real_get_size (GtkCellRenderer* base, GtkWidget* widget, GdkRectangle* cell_area, gint* x_offset, gint* y_offset, gint* width, gint* height) {
	TrackerCellRendererText * self;
	gint _x_offset = 0;
	gint _y_offset = 0;
	gint _width = 0;
	gint _height = 0;
	gint _tmp7_;
	gint _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	self = (TrackerCellRendererText*) base;
	g_return_if_fail (widget != NULL);
	if (self->priv->fixed_height == (-1)) {
		PangoContext* _tmp0_ = NULL;
		PangoContext* _tmp1_;
		PangoContext* c;
		PangoLayout* _tmp2_ = NULL;
		PangoLayout* layout;
		GtkStyle* _tmp3_ = NULL;
		GtkStyle* _tmp4_;
		GtkStyle* style;
		PangoFontDescription* _tmp5_;
		PangoFontDescription* fd;
		gint _tmp6_;
		_tmp0_ = gtk_widget_get_pango_context (widget);
		_tmp1_ = _g_object_ref0 (_tmp0_);
		c = _tmp1_;
		_tmp2_ = pango_layout_new (c);
		layout = _tmp2_;
		_tmp3_ = gtk_widget_get_style (widget);
		_tmp4_ = _g_object_ref0 (_tmp3_);
		style = _tmp4_;
		_tmp5_ = _pango_font_description_copy0 (style->font_desc);
		fd = _tmp5_;
		pango_layout_set_text (layout, "Foo\nBar", -1);
		pango_layout_set_font_description (layout, fd);
		pango_layout_get_pixel_size (layout, NULL, &_tmp6_);
		self->priv->fixed_height = _tmp6_;
		_pango_font_description_free0 (fd);
		_g_object_unref0 (style);
		_g_object_unref0 (layout);
		_g_object_unref0 (c);
	}
	tracker_cell_renderer_text_update_text (self, widget, self->priv->is_selected);
	GTK_CELL_RENDERER_CLASS (tracker_cell_renderer_text_parent_class)->get_size ((GtkCellRenderer*) GTK_CELL_RENDERER_TEXT (self), widget, cell_area, &_tmp7_, &_tmp8_, &_tmp9_, &_tmp10_);
	_x_offset = _tmp7_;
	_y_offset = _tmp8_;
	_width = _tmp9_;
	_height = _tmp10_;
	if (x_offset) {
		*x_offset = _x_offset;
	}
	if (y_offset) {
		*y_offset = _y_offset;
	}
	if (width) {
		*width = _width;
	}
	if (height) {
		*height = _height;
	}
}


static void tracker_cell_renderer_text_real_render (GtkCellRenderer* base, GdkWindow* window, GtkWidget* widget, GdkRectangle* background_area, GdkRectangle* cell_area, GdkRectangle* expose_area, GtkCellRendererState flags) {
	TrackerCellRendererText * self;
	gboolean selected;
	self = (TrackerCellRendererText*) base;
	g_return_if_fail (window != NULL);
	g_return_if_fail (widget != NULL);
	selected = (flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED;
	tracker_cell_renderer_text_update_text (self, widget, selected);
	GTK_CELL_RENDERER_CLASS (tracker_cell_renderer_text_parent_class)->render ((GtkCellRenderer*) GTK_CELL_RENDERER_TEXT (self), window, widget, background_area, cell_area, expose_area, flags);
}


static void tracker_cell_renderer_text_update_text (TrackerCellRendererText* self, GtkWidget* widget, gboolean selected) {
	gboolean _tmp0_ = FALSE;
	GtkStyle* _tmp1_ = NULL;
	GtkStyle* _tmp2_;
	GtkStyle* style;
	PangoAttrList* _tmp3_ = NULL;
	PangoAttrList* attr_list;
	guint start;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_;
	gboolean _tmp6_;
	PangoFontDescription* _tmp12_;
	PangoFontDescription* fd;
	gint _tmp13_;
	PangoAttrSize* _tmp14_ = NULL;
	PangoAttrSize* attr_size;
	PangoAttrSize* _tmp15_;
	gchar* str = NULL;
	gboolean _tmp16_ = FALSE;
	gboolean _tmp17_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (widget != NULL);
	if (self->priv->is_valid) {
		_tmp0_ = self->priv->is_selected == selected;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		return;
	}
	_tmp1_ = gtk_widget_get_style (widget);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	style = _tmp2_;
	_tmp3_ = pango_attr_list_new ();
	attr_list = _tmp3_;
	start = (guint) 0;
	_tmp5_ = (g_object_get ((GtkCellRendererText*) self, "text", &_tmp4_, NULL), _tmp4_);
	if ((_tmp6_ = _tmp5_ != NULL, _g_free0 (_tmp5_), _tmp6_)) {
		gchar* _tmp7_ = NULL;
		gchar* _tmp8_;
		gint _tmp9_;
		_tmp8_ = (g_object_get ((GtkCellRendererText*) self, "text", &_tmp7_, NULL), _tmp7_);
		_tmp9_ = strlen (_tmp8_);
		start = (guint) _tmp9_;
		_g_free0 (_tmp8_);
	}
	if (!selected) {
		GdkColor c;
		PangoAttribute* _tmp10_ = NULL;
		PangoAttribute* attr_color;
		PangoAttribute* _tmp11_;
		c = style->text_aa[GTK_STATE_NORMAL];
		_tmp10_ = pango_attr_foreground_new (c.red, c.green, c.blue);
		attr_color = _tmp10_;
		attr_color->start_index = start;
		attr_color->end_index = (guint) (-1);
		_tmp11_ = attr_color;
		attr_color = NULL;
		pango_attr_list_insert (attr_list, _tmp11_);
		_pango_attribute_destroy0 (attr_color);
	}
	_tmp12_ = _pango_font_description_copy0 (style->font_desc);
	fd = _tmp12_;
	_tmp13_ = pango_font_description_get_size (fd);
	_tmp14_ = (PangoAttrSize*) pango_attr_size_new ((gint) (_tmp13_ / 1.2));
	attr_size = _tmp14_;
	((PangoAttribute*) attr_size)->start_index = start;
	((PangoAttribute*) attr_size)->end_index = (guint) (-1);
	_tmp15_ = attr_size;
	attr_size = NULL;
	pango_attr_list_insert (attr_list, (PangoAttribute*) _tmp15_);
	if (self->priv->_subtext == NULL) {
		_tmp17_ = TRUE;
	} else {
		gint _tmp18_;
		_tmp18_ = strlen (self->priv->_subtext);
		_tmp17_ = _tmp18_ < 1;
	}
	if (_tmp17_) {
		_tmp16_ = TRUE;
	} else {
		_tmp16_ = self->priv->_show_subtext;
	}
	if (_tmp16_) {
		gchar* _tmp19_ = NULL;
		gchar* _tmp20_;
		_tmp20_ = (g_object_get ((GtkCellRendererText*) self, "text", &_tmp19_, NULL), _tmp19_);
		_g_free0 (str);
		str = _tmp20_;
	} else {
		gchar* _tmp21_ = NULL;
		gchar* _tmp22_;
		gchar* _tmp23_ = NULL;
		gchar* _tmp24_;
		_tmp22_ = (g_object_get ((GtkCellRendererText*) self, "text", &_tmp21_, NULL), _tmp21_);
		_tmp23_ = g_strdup_printf ("%s\n%s", _tmp22_, self->priv->_subtext);
		_tmp24_ = _tmp23_;
		_g_free0 (str);
		str = _tmp24_;
		_g_free0 (_tmp22_);
	}
	if (self->priv->_show_fixed_height) {
		g_object_set ((GtkCellRenderer*) self, "height", self->priv->fixed_height, NULL);
	} else {
		g_object_set ((GtkCellRenderer*) self, "height", -1, NULL);
	}
	gtk_cell_renderer_set_visible ((GtkCellRenderer*) self, TRUE);
	g_object_set ((GtkCellRendererText*) self, "weight", (gint) PANGO_WEIGHT_NORMAL, NULL);
	g_object_set ((GtkCellRendererText*) self, "text", str, NULL);
	g_object_set ((GtkCellRendererText*) self, "attributes", attr_list, NULL);
	g_object_set ((GtkCellRenderer*) self, "xpad", (guint) 0, NULL);
	g_object_set ((GtkCellRenderer*) self, "ypad", (guint) 1, NULL);
	self->priv->is_selected = selected;
	_g_free0 (str);
	_pango_attribute_destroy0 (attr_size);
	_pango_font_description_free0 (fd);
	_pango_attr_list_unref0 (attr_list);
	_g_object_unref0 (style);
}


TrackerCellRendererText* tracker_cell_renderer_text_construct (GType object_type) {
	TrackerCellRendererText * self = NULL;
	self = (TrackerCellRendererText*) g_object_new (object_type, NULL);
	return self;
}


TrackerCellRendererText* tracker_cell_renderer_text_new (void) {
	return tracker_cell_renderer_text_construct (TRACKER_TYPE_CELL_RENDERER_TEXT);
}


const gchar* tracker_cell_renderer_text_get_subtext (TrackerCellRendererText* self) {
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self->priv->_subtext;
	return result;
}


void tracker_cell_renderer_text_set_subtext (TrackerCellRendererText* self, const gchar* value) {
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_strdup (value);
	_tmp1_ = _tmp0_;
	_g_free0 (self->priv->_subtext);
	self->priv->_subtext = _tmp1_;
	g_object_notify ((GObject *) self, "subtext");
}


gboolean tracker_cell_renderer_text_get_show_row_hint (TrackerCellRendererText* self) {
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_show_row_hint;
	return result;
}


void tracker_cell_renderer_text_set_show_row_hint (TrackerCellRendererText* self, gboolean value) {
	g_return_if_fail (self != NULL);
	self->priv->_show_row_hint = value;
	g_object_notify ((GObject *) self, "show-row-hint");
}


gboolean tracker_cell_renderer_text_get_show_subtext (TrackerCellRendererText* self) {
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_show_subtext;
	return result;
}


void tracker_cell_renderer_text_set_show_subtext (TrackerCellRendererText* self, gboolean value) {
	g_return_if_fail (self != NULL);
	self->priv->_show_subtext = value;
	g_object_notify ((GObject *) self, "show-subtext");
}


gboolean tracker_cell_renderer_text_get_show_fixed_height (TrackerCellRendererText* self) {
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_show_fixed_height;
	return result;
}


void tracker_cell_renderer_text_set_show_fixed_height (TrackerCellRendererText* self, gboolean value) {
	g_return_if_fail (self != NULL);
	self->priv->_show_fixed_height = value;
	g_object_notify ((GObject *) self, "show-fixed-height");
}


static void tracker_cell_renderer_text_class_init (TrackerCellRendererTextClass * klass) {
	tracker_cell_renderer_text_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (TrackerCellRendererTextPrivate));
	GTK_CELL_RENDERER_CLASS (klass)->get_size = tracker_cell_renderer_text_real_get_size;
	GTK_CELL_RENDERER_CLASS (klass)->render = tracker_cell_renderer_text_real_render;
	G_OBJECT_CLASS (klass)->get_property = _vala_tracker_cell_renderer_text_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_tracker_cell_renderer_text_set_property;
	G_OBJECT_CLASS (klass)->finalize = tracker_cell_renderer_text_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), TRACKER_CELL_RENDERER_TEXT_SUBTEXT, g_param_spec_string ("subtext", "subtext", "subtext", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), TRACKER_CELL_RENDERER_TEXT_SHOW_ROW_HINT, g_param_spec_boolean ("show-row-hint", "show-row-hint", "show-row-hint", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), TRACKER_CELL_RENDERER_TEXT_SHOW_SUBTEXT, g_param_spec_boolean ("show-subtext", "show-subtext", "show-subtext", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), TRACKER_CELL_RENDERER_TEXT_SHOW_FIXED_HEIGHT, g_param_spec_boolean ("show-fixed-height", "show-fixed-height", "show-fixed-height", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
}


static void tracker_cell_renderer_text_instance_init (TrackerCellRendererText * self) {
	self->priv = TRACKER_CELL_RENDERER_TEXT_GET_PRIVATE (self);
	self->priv->fixed_height = -1;
}


static void tracker_cell_renderer_text_finalize (GObject* obj) {
	TrackerCellRendererText * self;
	self = TRACKER_CELL_RENDERER_TEXT (obj);
	_g_free0 (self->priv->_subtext);
	G_OBJECT_CLASS (tracker_cell_renderer_text_parent_class)->finalize (obj);
}


GType tracker_cell_renderer_text_get_type (void) {
	static volatile gsize tracker_cell_renderer_text_type_id__volatile = 0;
	if (g_once_init_enter (&tracker_cell_renderer_text_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (TrackerCellRendererTextClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) tracker_cell_renderer_text_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TrackerCellRendererText), 0, (GInstanceInitFunc) tracker_cell_renderer_text_instance_init, NULL };
		GType tracker_cell_renderer_text_type_id;
		tracker_cell_renderer_text_type_id = g_type_register_static (GTK_TYPE_CELL_RENDERER_TEXT, "TrackerCellRendererText", &g_define_type_info, 0);
		g_once_init_leave (&tracker_cell_renderer_text_type_id__volatile, tracker_cell_renderer_text_type_id);
	}
	return tracker_cell_renderer_text_type_id__volatile;
}


static void _vala_tracker_cell_renderer_text_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	TrackerCellRendererText * self;
	self = TRACKER_CELL_RENDERER_TEXT (object);
	switch (property_id) {
		case TRACKER_CELL_RENDERER_TEXT_SUBTEXT:
		g_value_set_string (value, tracker_cell_renderer_text_get_subtext (self));
		break;
		case TRACKER_CELL_RENDERER_TEXT_SHOW_ROW_HINT:
		g_value_set_boolean (value, tracker_cell_renderer_text_get_show_row_hint (self));
		break;
		case TRACKER_CELL_RENDERER_TEXT_SHOW_SUBTEXT:
		g_value_set_boolean (value, tracker_cell_renderer_text_get_show_subtext (self));
		break;
		case TRACKER_CELL_RENDERER_TEXT_SHOW_FIXED_HEIGHT:
		g_value_set_boolean (value, tracker_cell_renderer_text_get_show_fixed_height (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_tracker_cell_renderer_text_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	TrackerCellRendererText * self;
	self = TRACKER_CELL_RENDERER_TEXT (object);
	switch (property_id) {
		case TRACKER_CELL_RENDERER_TEXT_SUBTEXT:
		tracker_cell_renderer_text_set_subtext (self, g_value_get_string (value));
		break;
		case TRACKER_CELL_RENDERER_TEXT_SHOW_ROW_HINT:
		tracker_cell_renderer_text_set_show_row_hint (self, g_value_get_boolean (value));
		break;
		case TRACKER_CELL_RENDERER_TEXT_SHOW_SUBTEXT:
		tracker_cell_renderer_text_set_show_subtext (self, g_value_get_boolean (value));
		break;
		case TRACKER_CELL_RENDERER_TEXT_SHOW_FIXED_HEIGHT:
		tracker_cell_renderer_text_set_show_fixed_height (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



