/* tab-label.c generated by valac 0.34.4, the Vala compiler
 * generated from tab-label.vala, do not modify */

/*
 * tab-label.vala - This file is part of the Geany MultiTerm plugin
 *
 * Copyright (c) 2012 Matthew Brush <matt@geany.org>.
 *
 * 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 "multiterm.h"
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <pango/pango.h>
#include <glib/gi18n-lib.h>

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _MultiTermTabLabelPrivate {
	GtkButton* btn;
};


static gpointer multi_term_tab_label_parent_class = NULL;

#define MULTI_TERM_TAB_LABEL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MULTI_TERM_TYPE_TAB_LABEL, MultiTermTabLabelPrivate))
enum  {
	MULTI_TERM_TAB_LABEL_DUMMY_PROPERTY,
	MULTI_TERM_TAB_LABEL_TEXT,
	MULTI_TERM_TAB_LABEL_BUTTON
};
static void multi_term_tab_label_on_button_clicked (MultiTermTabLabel* self);
static void multi_term_tab_label_on_button_style_set (MultiTermTabLabel* self, GtkStyle* previous_style);
static void _multi_term_tab_label_on_button_clicked_gtk_button_clicked (GtkButton* _sender, gpointer self);
static void _multi_term_tab_label_on_button_style_set_gtk_widget_style_set (GtkWidget* _sender, GtkStyle* previous_style, gpointer self);
static void multi_term_tab_label_finalize (GObject* obj);
static void _vala_multi_term_tab_label_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_multi_term_tab_label_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 void multi_term_tab_label_on_button_clicked (MultiTermTabLabel* self) {
	MultiTermTerminal* term = NULL;
	gconstpointer _tmp0_ = NULL;
	MultiTermTerminal* _tmp1_ = NULL;
	MultiTermNotebook* nb = NULL;
	GtkContainer* _tmp2_ = NULL;
	MultiTermNotebook* _tmp3_ = NULL;
	gint page_num = 0;
	gint _tmp4_ = 0;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_object_get_data ((GObject*) self, "terminal");
	_tmp1_ = _g_object_ref0 ((MultiTermTerminal*) _tmp0_);
	term = _tmp1_;
	_tmp2_ = (GtkContainer*) gtk_widget_get_parent ((GtkWidget*) term);
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, MULTI_TERM_TYPE_NOTEBOOK, MultiTermNotebook));
	nb = _tmp3_;
	_tmp4_ = gtk_notebook_page_num ((GtkNotebook*) nb, (GtkWidget*) term);
	page_num = _tmp4_;
	g_signal_emit_by_name (self, "close-clicked", page_num);
	_g_object_unref0 (nb);
	_g_object_unref0 (term);
}


static void multi_term_tab_label_on_button_style_set (MultiTermTabLabel* self, GtkStyle* previous_style) {
	gint w = 0;
	gint h = 0;
	GtkButton* _tmp0_ = NULL;
	GtkSettings* _tmp1_ = NULL;
	gint _tmp2_ = 0;
	gint _tmp3_ = 0;
	GtkButton* _tmp4_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->btn;
	_tmp1_ = gtk_widget_get_settings ((GtkWidget*) _tmp0_);
	gtk_icon_size_lookup_for_settings (_tmp1_, GTK_ICON_SIZE_MENU, &_tmp2_, &_tmp3_);
	w = _tmp2_;
	h = _tmp3_;
	_tmp4_ = self->priv->btn;
	gtk_widget_set_size_request ((GtkWidget*) _tmp4_, w + 2, h + 2);
}


static void _multi_term_tab_label_on_button_clicked_gtk_button_clicked (GtkButton* _sender, gpointer self) {
	multi_term_tab_label_on_button_clicked ((MultiTermTabLabel*) self);
}


static void _multi_term_tab_label_on_button_style_set_gtk_widget_style_set (GtkWidget* _sender, GtkStyle* previous_style, gpointer self) {
	multi_term_tab_label_on_button_style_set ((MultiTermTabLabel*) self, previous_style);
}


MultiTermTabLabel* multi_term_tab_label_construct (GType object_type, const gchar* text) {
	MultiTermTabLabel * self = NULL;
	GtkImage* img = NULL;
	const gchar* _tmp0_ = NULL;
	GtkLabel* _tmp1_ = NULL;
	GtkLabel* _tmp2_ = NULL;
	GtkLabel* _tmp3_ = NULL;
	GtkLabel* _tmp4_ = NULL;
	GtkImage* _tmp5_ = NULL;
	GtkRcStyle* style = NULL;
	GtkRcStyle* _tmp6_ = NULL;
	GtkButton* _tmp7_ = NULL;
	GtkButton* _tmp8_ = NULL;
	GtkButton* _tmp9_ = NULL;
	GtkButton* _tmp10_ = NULL;
	const gchar* _tmp11_ = NULL;
	GtkButton* _tmp12_ = NULL;
	GtkButton* _tmp13_ = NULL;
	GtkButton* _tmp14_ = NULL;
	GtkButton* _tmp15_ = NULL;
	GtkButton* _tmp16_ = NULL;
	g_return_val_if_fail (text != NULL, NULL);
	self = (MultiTermTabLabel*) g_object_new (object_type, "homogeneous", FALSE, "spacing", 2, NULL);
	gtk_container_set_border_width ((GtkContainer*) self, (guint) 0);
	_tmp0_ = text;
	_tmp1_ = (GtkLabel*) gtk_label_new (_tmp0_);
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (self->label);
	self->label = _tmp1_;
	_tmp2_ = self->label;
	gtk_misc_set_alignment ((GtkMisc*) _tmp2_, 0.0f, 0.5f);
	_tmp3_ = self->label;
	gtk_label_set_ellipsize (_tmp3_, PANGO_ELLIPSIZE_END);
	_tmp4_ = self->label;
	gtk_box_pack_start ((GtkBox*) self, (GtkWidget*) _tmp4_, TRUE, TRUE, (guint) 0);
	_tmp5_ = (GtkImage*) gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
	g_object_ref_sink (_tmp5_);
	_g_object_unref0 (img);
	img = _tmp5_;
	_tmp6_ = gtk_rc_style_new ();
	style = _tmp6_;
	style->xthickness = 0;
	style->ythickness = 0;
	_tmp7_ = (GtkButton*) gtk_button_new ();
	g_object_ref_sink (_tmp7_);
	_g_object_unref0 (self->priv->btn);
	self->priv->btn = _tmp7_;
	_tmp8_ = self->priv->btn;
	gtk_widget_modify_style ((GtkWidget*) _tmp8_, style);
	_tmp9_ = self->priv->btn;
	gtk_container_add ((GtkContainer*) _tmp9_, (GtkWidget*) img);
	_tmp10_ = self->priv->btn;
	_tmp11_ = _ ("Close terminal");
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp10_, _tmp11_);
	_tmp12_ = self->priv->btn;
	g_signal_connect_object (_tmp12_, "clicked", (GCallback) _multi_term_tab_label_on_button_clicked_gtk_button_clicked, self, 0);
	_tmp13_ = self->priv->btn;
	gtk_button_set_relief (_tmp13_, GTK_RELIEF_NONE);
	_tmp14_ = self->priv->btn;
	gtk_button_set_focus_on_click (_tmp14_, FALSE);
	_tmp15_ = self->priv->btn;
	g_signal_connect_object ((GtkWidget*) _tmp15_, "style-set", (GCallback) _multi_term_tab_label_on_button_style_set_gtk_widget_style_set, self, 0);
	_tmp16_ = self->priv->btn;
	gtk_box_pack_start ((GtkBox*) self, (GtkWidget*) _tmp16_, FALSE, FALSE, (guint) 0);
	_g_object_unref0 (style);
	_g_object_unref0 (img);
	return self;
}


MultiTermTabLabel* multi_term_tab_label_new (const gchar* text) {
	return multi_term_tab_label_construct (MULTI_TERM_TYPE_TAB_LABEL, text);
}


const gchar* multi_term_tab_label_get_text (MultiTermTabLabel* self) {
	const gchar* result;
	GtkLabel* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->label;
	_tmp1_ = gtk_label_get_label (_tmp0_);
	result = _tmp1_;
	return result;
}


void multi_term_tab_label_set_text (MultiTermTabLabel* self, const gchar* value) {
	GtkLabel* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->label;
	_tmp1_ = value;
	gtk_label_set_label (_tmp0_, _tmp1_);
	g_object_notify ((GObject *) self, "text");
}


GtkButton* multi_term_tab_label_get_button (MultiTermTabLabel* self) {
	GtkButton* result;
	GtkButton* _tmp0_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->btn;
	result = _tmp0_;
	return result;
}


static void multi_term_tab_label_class_init (MultiTermTabLabelClass * klass) {
	multi_term_tab_label_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (MultiTermTabLabelPrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_multi_term_tab_label_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_multi_term_tab_label_set_property;
	G_OBJECT_CLASS (klass)->finalize = multi_term_tab_label_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), MULTI_TERM_TAB_LABEL_TEXT, g_param_spec_string ("text", "text", "text", 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), MULTI_TERM_TAB_LABEL_BUTTON, g_param_spec_object ("button", "button", "button", GTK_TYPE_BUTTON, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
	g_signal_new ("close_clicked", MULTI_TERM_TYPE_TAB_LABEL, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
}


static void multi_term_tab_label_instance_init (MultiTermTabLabel * self) {
	self->priv = MULTI_TERM_TAB_LABEL_GET_PRIVATE (self);
}


static void multi_term_tab_label_finalize (GObject* obj) {
	MultiTermTabLabel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, MULTI_TERM_TYPE_TAB_LABEL, MultiTermTabLabel);
	_g_object_unref0 (self->priv->btn);
	_g_object_unref0 (self->label);
	G_OBJECT_CLASS (multi_term_tab_label_parent_class)->finalize (obj);
}


GType multi_term_tab_label_get_type (void) {
	static volatile gsize multi_term_tab_label_type_id__volatile = 0;
	if (g_once_init_enter (&multi_term_tab_label_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (MultiTermTabLabelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) multi_term_tab_label_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MultiTermTabLabel), 0, (GInstanceInitFunc) multi_term_tab_label_instance_init, NULL };
		GType multi_term_tab_label_type_id;
		multi_term_tab_label_type_id = g_type_register_static (GTK_TYPE_HBOX, "MultiTermTabLabel", &g_define_type_info, 0);
		g_once_init_leave (&multi_term_tab_label_type_id__volatile, multi_term_tab_label_type_id);
	}
	return multi_term_tab_label_type_id__volatile;
}


static void _vala_multi_term_tab_label_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	MultiTermTabLabel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, MULTI_TERM_TYPE_TAB_LABEL, MultiTermTabLabel);
	switch (property_id) {
		case MULTI_TERM_TAB_LABEL_TEXT:
		g_value_set_string (value, multi_term_tab_label_get_text (self));
		break;
		case MULTI_TERM_TAB_LABEL_BUTTON:
		g_value_set_object (value, multi_term_tab_label_get_button (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_multi_term_tab_label_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	MultiTermTabLabel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, MULTI_TERM_TYPE_TAB_LABEL, MultiTermTabLabel);
	switch (property_id) {
		case MULTI_TERM_TAB_LABEL_TEXT:
		multi_term_tab_label_set_text (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



