/* math-variable-popup.c generated by valac 0.34.4, the Vala compiler
 * generated from math-variable-popup.vala, do not modify */

/*
 * Copyright (C) 2008-2012 Robert Ancell
 *
 * 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 3 of the License, or (at your option) any later
 * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
 * license.
 */

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


#define TYPE_MATH_VARIABLE_POPUP (math_variable_popup_get_type ())
#define MATH_VARIABLE_POPUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MATH_VARIABLE_POPUP, MathVariablePopup))
#define MATH_VARIABLE_POPUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MATH_VARIABLE_POPUP, MathVariablePopupClass))
#define IS_MATH_VARIABLE_POPUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MATH_VARIABLE_POPUP))
#define IS_MATH_VARIABLE_POPUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MATH_VARIABLE_POPUP))
#define MATH_VARIABLE_POPUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MATH_VARIABLE_POPUP, MathVariablePopupClass))

typedef struct _MathVariablePopup MathVariablePopup;
typedef struct _MathVariablePopupClass MathVariablePopupClass;
typedef struct _MathVariablePopupPrivate MathVariablePopupPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _MathVariablePopup {
	GtkWindow parent_instance;
	MathVariablePopupPrivate * priv;
};

struct _MathVariablePopupClass {
	GtkWindowClass parent_class;
};

struct _MathVariablePopupPrivate {
	MathEquation* equation;
	GtkBox* vbox;
	GtkEntry* variable_name_entry;
	GtkButton* add_variable_button;
};


static gpointer math_variable_popup_parent_class = NULL;

GType math_variable_popup_get_type (void) G_GNUC_CONST;
#define MATH_VARIABLE_POPUP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_MATH_VARIABLE_POPUP, MathVariablePopupPrivate))
enum  {
	MATH_VARIABLE_POPUP_DUMMY_PROPERTY
};
MathVariablePopup* math_variable_popup_new (MathEquation* equation);
MathVariablePopup* math_variable_popup_construct (GType object_type, MathEquation* equation);
static gboolean __lambda19_ (MathVariablePopup* self, GdkEventFocus* event);
static gboolean ___lambda19__gtk_widget_focus_out_event (GtkWidget* _sender, GdkEventFocus* event, gpointer self);
static GtkBox* math_variable_popup_make_variable_entry (MathVariablePopup* self, const gchar* name, Number* value, gboolean writable);
static gboolean math_variable_popup_variable_name_key_press_cb (MathVariablePopup* self, GtkWidget* widget, GdkEventKey* event);
static gboolean _math_variable_popup_variable_name_key_press_cb_gtk_widget_key_press_event (GtkWidget* _sender, GdkEventKey* event, gpointer self);
static void math_variable_popup_variable_name_changed_cb (MathVariablePopup* self);
static void _math_variable_popup_variable_name_changed_cb_gtk_editable_changed (GtkEditable* _sender, gpointer self);
static void math_variable_popup_add_variable_cb (MathVariablePopup* self, GtkWidget* widget);
static void _math_variable_popup_add_variable_cb_gtk_entry_activate (GtkEntry* _sender, gpointer self);
static void _math_variable_popup_add_variable_cb_gtk_button_clicked (GtkButton* _sender, gpointer self);
static void math_variable_popup_insert_variable_cb (MathVariablePopup* self, GtkWidget* widget);
static void math_variable_popup_save_variable_cb (MathVariablePopup* self, GtkWidget* widget);
static void math_variable_popup_delete_variable_cb (MathVariablePopup* self, GtkWidget* widget);
static void _math_variable_popup_insert_variable_cb_gtk_button_clicked (GtkButton* _sender, gpointer self);
static void _math_variable_popup_save_variable_cb_gtk_button_clicked (GtkButton* _sender, gpointer self);
static void _math_variable_popup_delete_variable_cb_gtk_button_clicked (GtkButton* _sender, gpointer self);
static void math_variable_popup_finalize (GObject* obj);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


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


static gboolean __lambda19_ (MathVariablePopup* self, GdkEventFocus* event) {
	gboolean result = FALSE;
	g_return_val_if_fail (event != NULL, FALSE);
	gtk_widget_destroy ((GtkWidget*) self);
	result = FALSE;
	return result;
}


static gboolean ___lambda19__gtk_widget_focus_out_event (GtkWidget* _sender, GdkEventFocus* event, gpointer self) {
	gboolean result;
	result = __lambda19_ ((MathVariablePopup*) self, event);
	return result;
}


static gboolean _math_variable_popup_variable_name_key_press_cb_gtk_widget_key_press_event (GtkWidget* _sender, GdkEventKey* event, gpointer self) {
	gboolean result;
	result = math_variable_popup_variable_name_key_press_cb ((MathVariablePopup*) self, _sender, event);
	return result;
}


static void _math_variable_popup_variable_name_changed_cb_gtk_editable_changed (GtkEditable* _sender, gpointer self) {
	math_variable_popup_variable_name_changed_cb ((MathVariablePopup*) self);
}


static void _math_variable_popup_add_variable_cb_gtk_entry_activate (GtkEntry* _sender, gpointer self) {
	math_variable_popup_add_variable_cb ((MathVariablePopup*) self, _sender);
}


static void _math_variable_popup_add_variable_cb_gtk_button_clicked (GtkButton* _sender, gpointer self) {
	math_variable_popup_add_variable_cb ((MathVariablePopup*) self, _sender);
}


MathVariablePopup* math_variable_popup_construct (GType object_type, MathEquation* equation) {
	MathVariablePopup * self = NULL;
	MathEquation* _tmp0_ = NULL;
	MathEquation* _tmp1_ = NULL;
	GtkBox* _tmp2_ = NULL;
	GtkBox* _tmp3_ = NULL;
	GtkBox* _tmp4_ = NULL;
	GtkBox* _tmp5_ = NULL;
	gchar** names = NULL;
	MathEquation* _tmp6_ = NULL;
	MathVariables* _tmp7_ = NULL;
	MathVariables* _tmp8_ = NULL;
	gint _tmp9_ = 0;
	gchar** _tmp10_ = NULL;
	gint names_length1 = 0;
	gint _names_size_ = 0;
	GtkBox* entry = NULL;
	GtkBox* _tmp31_ = NULL;
	GtkBox* _tmp32_ = NULL;
	GtkEntry* _tmp33_ = NULL;
	GtkEntry* _tmp34_ = NULL;
	GtkEntry* _tmp35_ = NULL;
	GtkEntry* _tmp36_ = NULL;
	GtkBox* _tmp37_ = NULL;
	GtkEntry* _tmp38_ = NULL;
	GtkEntry* _tmp39_ = NULL;
	GtkButton* _tmp40_ = NULL;
	GtkButton* _tmp41_ = NULL;
	GtkButton* _tmp42_ = NULL;
	GtkImage* image = NULL;
	GtkImage* _tmp43_ = NULL;
	GtkButton* _tmp44_ = NULL;
	GtkBox* _tmp45_ = NULL;
	GtkButton* _tmp46_ = NULL;
	GtkButton* _tmp47_ = NULL;
	GtkBox* _tmp48_ = NULL;
	GtkBox* _tmp49_ = NULL;
	GtkBox* _tmp50_ = NULL;
	GtkBox* _tmp51_ = NULL;
	GtkBox* _tmp52_ = NULL;
	GtkBox* _tmp53_ = NULL;
	MathEquation* _tmp54_ = NULL;
	Number* _tmp55_ = NULL;
	Number* _tmp56_ = NULL;
	GtkBox* _tmp57_ = NULL;
	GtkBox* _tmp58_ = NULL;
	GtkBox* _tmp59_ = NULL;
	GtkBox* _tmp60_ = NULL;
	g_return_val_if_fail (equation != NULL, NULL);
	self = (MathVariablePopup*) g_object_new (object_type, NULL);
	_tmp0_ = equation;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->equation);
	self->priv->equation = _tmp1_;
	gtk_window_set_decorated ((GtkWindow*) self, FALSE);
	gtk_window_set_skip_taskbar_hint ((GtkWindow*) self, TRUE);
	gtk_container_set_border_width ((GtkContainer*) self, (guint) 6);
	g_signal_connect_object ((GtkWidget*) self, "focus-out-event", (GCallback) ___lambda19__gtk_widget_focus_out_event, self, 0);
	_tmp2_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
	g_object_ref_sink (_tmp2_);
	_g_object_unref0 (self->priv->vbox);
	self->priv->vbox = _tmp2_;
	_tmp3_ = self->priv->vbox;
	gtk_box_set_homogeneous (_tmp3_, TRUE);
	_tmp4_ = self->priv->vbox;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp4_);
	_tmp5_ = self->priv->vbox;
	gtk_widget_show ((GtkWidget*) _tmp5_);
	_tmp6_ = equation;
	_tmp7_ = math_equation_get_variables (_tmp6_);
	_tmp8_ = _tmp7_;
	_tmp10_ = math_variables_get_names (_tmp8_, &_tmp9_);
	names = _tmp10_;
	names_length1 = _tmp9_;
	_names_size_ = names_length1;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp11_ = FALSE;
			_tmp11_ = TRUE;
			while (TRUE) {
				gchar** _tmp13_ = NULL;
				gint _tmp13__length1 = 0;
				gint _tmp14_ = 0;
				const gchar* _tmp15_ = NULL;
				Number* value = NULL;
				MathEquation* _tmp16_ = NULL;
				MathVariables* _tmp17_ = NULL;
				MathVariables* _tmp18_ = NULL;
				gchar** _tmp19_ = NULL;
				gint _tmp19__length1 = 0;
				gint _tmp20_ = 0;
				const gchar* _tmp21_ = NULL;
				Number* _tmp22_ = NULL;
				GtkBox* entry = NULL;
				gchar** _tmp23_ = NULL;
				gint _tmp23__length1 = 0;
				gint _tmp24_ = 0;
				const gchar* _tmp25_ = NULL;
				Number* _tmp26_ = NULL;
				GtkBox* _tmp27_ = NULL;
				GtkBox* _tmp28_ = NULL;
				GtkBox* _tmp29_ = NULL;
				GtkBox* _tmp30_ = NULL;
				if (!_tmp11_) {
					gint _tmp12_ = 0;
					_tmp12_ = i;
					i = _tmp12_ + 1;
				}
				_tmp11_ = FALSE;
				_tmp13_ = names;
				_tmp13__length1 = names_length1;
				_tmp14_ = i;
				_tmp15_ = _tmp13_[_tmp14_];
				if (!(_tmp15_ != NULL)) {
					break;
				}
				_tmp16_ = equation;
				_tmp17_ = math_equation_get_variables (_tmp16_);
				_tmp18_ = _tmp17_;
				_tmp19_ = names;
				_tmp19__length1 = names_length1;
				_tmp20_ = i;
				_tmp21_ = _tmp19_[_tmp20_];
				_tmp22_ = math_variables_get (_tmp18_, _tmp21_);
				value = _tmp22_;
				_tmp23_ = names;
				_tmp23__length1 = names_length1;
				_tmp24_ = i;
				_tmp25_ = _tmp23_[_tmp24_];
				_tmp26_ = value;
				_tmp27_ = math_variable_popup_make_variable_entry (self, _tmp25_, _tmp26_, TRUE);
				entry = _tmp27_;
				_tmp28_ = entry;
				gtk_widget_show ((GtkWidget*) _tmp28_);
				_tmp29_ = self->priv->vbox;
				_tmp30_ = entry;
				gtk_box_pack_start (_tmp29_, (GtkWidget*) _tmp30_, FALSE, TRUE, (guint) 0);
				_g_object_unref0 (entry);
				_g_object_unref0 (value);
			}
		}
	}
	_tmp31_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
	g_object_ref_sink (_tmp31_);
	entry = _tmp31_;
	_tmp32_ = entry;
	gtk_widget_show ((GtkWidget*) _tmp32_);
	_tmp33_ = (GtkEntry*) gtk_entry_new ();
	g_object_ref_sink (_tmp33_);
	_g_object_unref0 (self->priv->variable_name_entry);
	self->priv->variable_name_entry = _tmp33_;
	_tmp34_ = self->priv->variable_name_entry;
	g_signal_connect_object ((GtkWidget*) _tmp34_, "key-press-event", (GCallback) _math_variable_popup_variable_name_key_press_cb_gtk_widget_key_press_event, self, 0);
	_tmp35_ = self->priv->variable_name_entry;
	g_signal_connect_object ((GtkEditable*) _tmp35_, "changed", (GCallback) _math_variable_popup_variable_name_changed_cb_gtk_editable_changed, self, 0);
	_tmp36_ = self->priv->variable_name_entry;
	g_signal_connect_object (_tmp36_, "activate", (GCallback) _math_variable_popup_add_variable_cb_gtk_entry_activate, self, 0);
	_tmp37_ = entry;
	_tmp38_ = self->priv->variable_name_entry;
	gtk_box_pack_start (_tmp37_, (GtkWidget*) _tmp38_, TRUE, TRUE, (guint) 0);
	_tmp39_ = self->priv->variable_name_entry;
	gtk_widget_show ((GtkWidget*) _tmp39_);
	_tmp40_ = (GtkButton*) gtk_button_new ();
	g_object_ref_sink (_tmp40_);
	_g_object_unref0 (self->priv->add_variable_button);
	self->priv->add_variable_button = _tmp40_;
	_tmp41_ = self->priv->add_variable_button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp41_, FALSE);
	_tmp42_ = self->priv->add_variable_button;
	g_signal_connect_object (_tmp42_, "clicked", (GCallback) _math_variable_popup_add_variable_cb_gtk_button_clicked, self, 0);
	_tmp43_ = (GtkImage*) gtk_image_new_from_icon_name ("list-add", GTK_ICON_SIZE_BUTTON);
	g_object_ref_sink (_tmp43_);
	image = _tmp43_;
	_tmp44_ = self->priv->add_variable_button;
	gtk_container_add ((GtkContainer*) _tmp44_, (GtkWidget*) image);
	_tmp45_ = entry;
	_tmp46_ = self->priv->add_variable_button;
	gtk_box_pack_start (_tmp45_, (GtkWidget*) _tmp46_, FALSE, TRUE, (guint) 0);
	gtk_widget_show ((GtkWidget*) image);
	_tmp47_ = self->priv->add_variable_button;
	gtk_widget_show ((GtkWidget*) _tmp47_);
	_tmp48_ = self->priv->vbox;
	_tmp49_ = entry;
	gtk_box_pack_end (_tmp48_, (GtkWidget*) _tmp49_, FALSE, TRUE, (guint) 0);
	_tmp50_ = math_variable_popup_make_variable_entry (self, "rand", NULL, FALSE);
	_g_object_unref0 (entry);
	entry = _tmp50_;
	_tmp51_ = entry;
	gtk_widget_show ((GtkWidget*) _tmp51_);
	_tmp52_ = self->priv->vbox;
	_tmp53_ = entry;
	gtk_box_pack_end (_tmp52_, (GtkWidget*) _tmp53_, FALSE, TRUE, (guint) 0);
	_tmp54_ = equation;
	_tmp55_ = math_equation_get_answer (_tmp54_);
	_tmp56_ = _tmp55_;
	_tmp57_ = math_variable_popup_make_variable_entry (self, "ans", _tmp56_, FALSE);
	_g_object_unref0 (entry);
	entry = _tmp57_;
	_tmp58_ = entry;
	gtk_widget_show ((GtkWidget*) _tmp58_);
	_tmp59_ = self->priv->vbox;
	_tmp60_ = entry;
	gtk_box_pack_end (_tmp59_, (GtkWidget*) _tmp60_, FALSE, TRUE, (guint) 0);
	_g_object_unref0 (image);
	_g_object_unref0 (entry);
	names = (_vala_array_free (names, names_length1, (GDestroyNotify) g_free), NULL);
	return self;
}


MathVariablePopup* math_variable_popup_new (MathEquation* equation) {
	return math_variable_popup_construct (TYPE_MATH_VARIABLE_POPUP, equation);
}


static void math_variable_popup_insert_variable_cb (MathVariablePopup* self, GtkWidget* widget) {
	gchar* name = NULL;
	GtkWidget* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	MathEquation* _tmp3_ = NULL;
	GtkWidget* _tmp4_ = NULL;
	GtkWidget* _tmp5_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (widget != NULL);
	_tmp0_ = widget;
	_tmp1_ = g_object_get_data ((GObject*) _tmp0_, "variable_name");
	_tmp2_ = g_strdup ((const gchar*) _tmp1_);
	name = _tmp2_;
	_tmp3_ = self->priv->equation;
	math_equation_insert (_tmp3_, name);
	_tmp4_ = widget;
	_tmp5_ = gtk_widget_get_toplevel (_tmp4_);
	gtk_widget_destroy (_tmp5_);
	_g_free0 (name);
}


static gboolean math_variable_popup_variable_name_key_press_cb (MathVariablePopup* self, GtkWidget* widget, GdkEventKey* event) {
	gboolean result = FALSE;
	gboolean _tmp0_ = FALSE;
	GdkEventKey* _tmp1_ = NULL;
	guint _tmp2_ = 0U;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (widget != NULL, FALSE);
	g_return_val_if_fail (event != NULL, FALSE);
	_tmp1_ = event;
	_tmp2_ = _tmp1_->keyval;
	if (_tmp2_ == ((guint) GDK_KEY_space)) {
		_tmp0_ = TRUE;
	} else {
		GdkEventKey* _tmp3_ = NULL;
		guint _tmp4_ = 0U;
		_tmp3_ = event;
		_tmp4_ = _tmp3_->keyval;
		_tmp0_ = _tmp4_ == ((guint) GDK_KEY_KP_Space);
	}
	if (_tmp0_) {
		GdkEventKey* _tmp5_ = NULL;
		_tmp5_ = event;
		_tmp5_->keyval = (guint) GDK_KEY_underscore;
	}
	result = FALSE;
	return result;
}


static void math_variable_popup_variable_name_changed_cb (MathVariablePopup* self) {
	GtkButton* _tmp0_ = NULL;
	GtkEntry* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->add_variable_button;
	_tmp1_ = self->priv->variable_name_entry;
	_tmp2_ = gtk_entry_get_text (_tmp1_);
	gtk_widget_set_sensitive ((GtkWidget*) _tmp0_, g_strcmp0 (_tmp2_, "") != 0);
}


static void math_variable_popup_add_variable_cb (MathVariablePopup* self, GtkWidget* widget) {
	gchar* name = NULL;
	GtkEntry* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	const gchar* _tmp3_ = NULL;
	Number* z = NULL;
	MathEquation* _tmp4_ = NULL;
	Number* _tmp5_ = NULL;
	Number* _tmp6_ = NULL;
	Number* _tmp7_ = NULL;
	GtkWidget* _tmp24_ = NULL;
	GtkWidget* _tmp25_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (widget != NULL);
	_tmp0_ = self->priv->variable_name_entry;
	_tmp1_ = gtk_entry_get_text (_tmp0_);
	_tmp2_ = g_strdup (_tmp1_);
	name = _tmp2_;
	_tmp3_ = name;
	if (g_strcmp0 (_tmp3_, "") == 0) {
		_g_free0 (name);
		return;
	}
	_tmp4_ = self->priv->equation;
	_tmp5_ = math_equation_get_number (_tmp4_);
	_tmp6_ = _tmp5_;
	z = _tmp6_;
	_tmp7_ = z;
	if (_tmp7_ != NULL) {
		MathEquation* _tmp8_ = NULL;
		MathVariables* _tmp9_ = NULL;
		MathVariables* _tmp10_ = NULL;
		const gchar* _tmp11_ = NULL;
		Number* _tmp12_ = NULL;
		_tmp8_ = self->priv->equation;
		_tmp9_ = math_equation_get_variables (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp11_ = name;
		_tmp12_ = z;
		math_variables_set (_tmp10_, _tmp11_, _tmp12_);
	} else {
		MathEquation* _tmp13_ = NULL;
		gboolean _tmp14_ = FALSE;
		gboolean _tmp15_ = FALSE;
		_tmp13_ = self->priv->equation;
		_tmp14_ = math_equation_get_is_result (_tmp13_);
		_tmp15_ = _tmp14_;
		if (_tmp15_) {
			MathEquation* _tmp16_ = NULL;
			MathVariables* _tmp17_ = NULL;
			MathVariables* _tmp18_ = NULL;
			const gchar* _tmp19_ = NULL;
			MathEquation* _tmp20_ = NULL;
			Number* _tmp21_ = NULL;
			Number* _tmp22_ = NULL;
			_tmp16_ = self->priv->equation;
			_tmp17_ = math_equation_get_variables (_tmp16_);
			_tmp18_ = _tmp17_;
			_tmp19_ = name;
			_tmp20_ = self->priv->equation;
			_tmp21_ = math_equation_get_answer (_tmp20_);
			_tmp22_ = _tmp21_;
			math_variables_set (_tmp18_, _tmp19_, _tmp22_);
		} else {
			const gchar* _tmp23_ = NULL;
			_tmp23_ = name;
			g_warning ("math-variable-popup.vala:108: Can't add variable %s, the display is no" \
"t a number", _tmp23_);
		}
	}
	_tmp24_ = widget;
	_tmp25_ = gtk_widget_get_toplevel (_tmp24_);
	gtk_widget_destroy (_tmp25_);
	_g_object_unref0 (z);
	_g_free0 (name);
}


static void math_variable_popup_save_variable_cb (MathVariablePopup* self, GtkWidget* widget) {
	gchar* name = NULL;
	GtkWidget* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	Number* z = NULL;
	MathEquation* _tmp3_ = NULL;
	Number* _tmp4_ = NULL;
	Number* _tmp5_ = NULL;
	Number* _tmp6_ = NULL;
	GtkWidget* _tmp23_ = NULL;
	GtkWidget* _tmp24_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (widget != NULL);
	_tmp0_ = widget;
	_tmp1_ = g_object_get_data ((GObject*) _tmp0_, "variable_name");
	_tmp2_ = g_strdup ((const gchar*) _tmp1_);
	name = _tmp2_;
	_tmp3_ = self->priv->equation;
	_tmp4_ = math_equation_get_number (_tmp3_);
	_tmp5_ = _tmp4_;
	z = _tmp5_;
	_tmp6_ = z;
	if (_tmp6_ != NULL) {
		MathEquation* _tmp7_ = NULL;
		MathVariables* _tmp8_ = NULL;
		MathVariables* _tmp9_ = NULL;
		const gchar* _tmp10_ = NULL;
		Number* _tmp11_ = NULL;
		_tmp7_ = self->priv->equation;
		_tmp8_ = math_equation_get_variables (_tmp7_);
		_tmp9_ = _tmp8_;
		_tmp10_ = name;
		_tmp11_ = z;
		math_variables_set (_tmp9_, _tmp10_, _tmp11_);
	} else {
		MathEquation* _tmp12_ = NULL;
		gboolean _tmp13_ = FALSE;
		gboolean _tmp14_ = FALSE;
		_tmp12_ = self->priv->equation;
		_tmp13_ = math_equation_get_is_result (_tmp12_);
		_tmp14_ = _tmp13_;
		if (_tmp14_) {
			MathEquation* _tmp15_ = NULL;
			MathVariables* _tmp16_ = NULL;
			MathVariables* _tmp17_ = NULL;
			const gchar* _tmp18_ = NULL;
			MathEquation* _tmp19_ = NULL;
			Number* _tmp20_ = NULL;
			Number* _tmp21_ = NULL;
			_tmp15_ = self->priv->equation;
			_tmp16_ = math_equation_get_variables (_tmp15_);
			_tmp17_ = _tmp16_;
			_tmp18_ = name;
			_tmp19_ = self->priv->equation;
			_tmp20_ = math_equation_get_answer (_tmp19_);
			_tmp21_ = _tmp20_;
			math_variables_set (_tmp17_, _tmp18_, _tmp21_);
		} else {
			const gchar* _tmp22_ = NULL;
			_tmp22_ = name;
			g_warning ("math-variable-popup.vala:122: Can't save variable %s, the display is n" \
"ot a number", _tmp22_);
		}
	}
	_tmp23_ = widget;
	_tmp24_ = gtk_widget_get_toplevel (_tmp23_);
	gtk_widget_destroy (_tmp24_);
	_g_object_unref0 (z);
	_g_free0 (name);
}


static void math_variable_popup_delete_variable_cb (MathVariablePopup* self, GtkWidget* widget) {
	gchar* name = NULL;
	GtkWidget* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	MathEquation* _tmp3_ = NULL;
	MathVariables* _tmp4_ = NULL;
	MathVariables* _tmp5_ = NULL;
	GtkWidget* _tmp6_ = NULL;
	GtkWidget* _tmp7_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (widget != NULL);
	_tmp0_ = widget;
	_tmp1_ = g_object_get_data ((GObject*) _tmp0_, "variable_name");
	_tmp2_ = g_strdup ((const gchar*) _tmp1_);
	name = _tmp2_;
	_tmp3_ = self->priv->equation;
	_tmp4_ = math_equation_get_variables (_tmp3_);
	_tmp5_ = _tmp4_;
	math_variables_delete (_tmp5_, name);
	_tmp6_ = widget;
	_tmp7_ = gtk_widget_get_toplevel (_tmp6_);
	gtk_widget_destroy (_tmp7_);
	_g_free0 (name);
}


static void _math_variable_popup_insert_variable_cb_gtk_button_clicked (GtkButton* _sender, gpointer self) {
	math_variable_popup_insert_variable_cb ((MathVariablePopup*) self, _sender);
}


static void _math_variable_popup_save_variable_cb_gtk_button_clicked (GtkButton* _sender, gpointer self) {
	math_variable_popup_save_variable_cb ((MathVariablePopup*) self, _sender);
}


static void _math_variable_popup_delete_variable_cb_gtk_button_clicked (GtkButton* _sender, gpointer self) {
	math_variable_popup_delete_variable_cb ((MathVariablePopup*) self, _sender);
}


static GtkBox* math_variable_popup_make_variable_entry (MathVariablePopup* self, const gchar* name, Number* value, gboolean writable) {
	GtkBox* result = NULL;
	GtkBox* hbox = NULL;
	GtkBox* _tmp0_ = NULL;
	gchar* text = NULL;
	Number* _tmp1_ = NULL;
	GtkButton* button = NULL;
	GtkButton* _tmp12_ = NULL;
	GtkButton* _tmp13_ = NULL;
	const gchar* _tmp14_ = NULL;
	gchar* _tmp15_ = NULL;
	GtkButton* _tmp16_ = NULL;
	GtkButton* _tmp17_ = NULL;
	GtkBox* _tmp18_ = NULL;
	GtkButton* _tmp19_ = NULL;
	GtkButton* _tmp20_ = NULL;
	GtkLabel* label = NULL;
	const gchar* _tmp21_ = NULL;
	GtkLabel* _tmp22_ = NULL;
	GtkLabel* _tmp23_ = NULL;
	GtkLabel* _tmp24_ = NULL;
	GtkButton* _tmp25_ = NULL;
	GtkLabel* _tmp26_ = NULL;
	GtkLabel* _tmp27_ = NULL;
	gboolean _tmp28_ = FALSE;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
	g_object_ref_sink (_tmp0_);
	hbox = _tmp0_;
	_tmp1_ = value;
	if (_tmp1_ != NULL) {
		gchar* value_text = NULL;
		MathEquation* _tmp2_ = NULL;
		Serializer* _tmp3_ = NULL;
		Serializer* _tmp4_ = NULL;
		Number* _tmp5_ = NULL;
		gchar* _tmp6_ = NULL;
		const gchar* _tmp7_ = NULL;
		const gchar* _tmp8_ = NULL;
		gchar* _tmp9_ = NULL;
		_tmp2_ = self->priv->equation;
		_tmp3_ = math_equation_get_serializer (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp5_ = value;
		_tmp6_ = serializer_to_string (_tmp4_, _tmp5_);
		value_text = _tmp6_;
		_tmp7_ = name;
		_tmp8_ = value_text;
		_tmp9_ = g_strdup_printf ("<b>%s</b> = %s", _tmp7_, _tmp8_);
		_g_free0 (text);
		text = _tmp9_;
		_g_free0 (value_text);
	} else {
		const gchar* _tmp10_ = NULL;
		gchar* _tmp11_ = NULL;
		_tmp10_ = name;
		_tmp11_ = g_strdup_printf ("<b>%s</b>", _tmp10_);
		_g_free0 (text);
		text = _tmp11_;
	}
	_tmp12_ = (GtkButton*) gtk_button_new ();
	g_object_ref_sink (_tmp12_);
	button = _tmp12_;
	_tmp13_ = button;
	_tmp14_ = name;
	_tmp15_ = g_strdup (_tmp14_);
	g_object_set_data_full ((GObject*) _tmp13_, "variable_name", _tmp15_, g_free);
	_tmp16_ = button;
	g_signal_connect_object (_tmp16_, "clicked", (GCallback) _math_variable_popup_insert_variable_cb_gtk_button_clicked, self, 0);
	_tmp17_ = button;
	gtk_button_set_relief (_tmp17_, GTK_RELIEF_NONE);
	_tmp18_ = hbox;
	_tmp19_ = button;
	gtk_box_pack_start (_tmp18_, (GtkWidget*) _tmp19_, TRUE, TRUE, (guint) 0);
	_tmp20_ = button;
	gtk_widget_show ((GtkWidget*) _tmp20_);
	_tmp21_ = text;
	_tmp22_ = (GtkLabel*) gtk_label_new (_tmp21_);
	g_object_ref_sink (_tmp22_);
	label = _tmp22_;
	_tmp23_ = label;
	gtk_label_set_use_markup (_tmp23_, TRUE);
	_tmp24_ = label;
	gtk_misc_set_alignment ((GtkMisc*) _tmp24_, 0.0f, 0.5f);
	_tmp25_ = button;
	_tmp26_ = label;
	gtk_container_add ((GtkContainer*) _tmp25_, (GtkWidget*) _tmp26_);
	_tmp27_ = label;
	gtk_widget_show ((GtkWidget*) _tmp27_);
	_tmp28_ = writable;
	if (_tmp28_) {
		GtkButton* _tmp29_ = NULL;
		GtkButton* _tmp30_ = NULL;
		const gchar* _tmp31_ = NULL;
		gchar* _tmp32_ = NULL;
		GtkImage* image = NULL;
		GtkImage* _tmp33_ = NULL;
		GtkButton* _tmp34_ = NULL;
		GtkImage* _tmp35_ = NULL;
		GtkBox* _tmp36_ = NULL;
		GtkButton* _tmp37_ = NULL;
		GtkButton* _tmp38_ = NULL;
		GtkImage* _tmp39_ = NULL;
		GtkButton* _tmp40_ = NULL;
		GtkButton* _tmp41_ = NULL;
		GtkButton* _tmp42_ = NULL;
		const gchar* _tmp43_ = NULL;
		gchar* _tmp44_ = NULL;
		GtkImage* _tmp45_ = NULL;
		GtkButton* _tmp46_ = NULL;
		GtkImage* _tmp47_ = NULL;
		GtkBox* _tmp48_ = NULL;
		GtkButton* _tmp49_ = NULL;
		GtkButton* _tmp50_ = NULL;
		GtkImage* _tmp51_ = NULL;
		GtkButton* _tmp52_ = NULL;
		_tmp29_ = (GtkButton*) gtk_button_new ();
		g_object_ref_sink (_tmp29_);
		_g_object_unref0 (button);
		button = _tmp29_;
		_tmp30_ = button;
		_tmp31_ = name;
		_tmp32_ = g_strdup (_tmp31_);
		g_object_set_data_full ((GObject*) _tmp30_, "variable_name", _tmp32_, g_free);
		_tmp33_ = (GtkImage*) gtk_image_new_from_icon_name ("document-save", GTK_ICON_SIZE_BUTTON);
		g_object_ref_sink (_tmp33_);
		image = _tmp33_;
		_tmp34_ = button;
		_tmp35_ = image;
		gtk_container_add ((GtkContainer*) _tmp34_, (GtkWidget*) _tmp35_);
		_tmp36_ = hbox;
		_tmp37_ = button;
		gtk_box_pack_start (_tmp36_, (GtkWidget*) _tmp37_, FALSE, TRUE, (guint) 0);
		_tmp38_ = button;
		g_signal_connect_object (_tmp38_, "clicked", (GCallback) _math_variable_popup_save_variable_cb_gtk_button_clicked, self, 0);
		_tmp39_ = image;
		gtk_widget_show ((GtkWidget*) _tmp39_);
		_tmp40_ = button;
		gtk_widget_show ((GtkWidget*) _tmp40_);
		_tmp41_ = (GtkButton*) gtk_button_new ();
		g_object_ref_sink (_tmp41_);
		_g_object_unref0 (button);
		button = _tmp41_;
		_tmp42_ = button;
		_tmp43_ = name;
		_tmp44_ = g_strdup (_tmp43_);
		g_object_set_data_full ((GObject*) _tmp42_, "variable_name", _tmp44_, g_free);
		_tmp45_ = (GtkImage*) gtk_image_new_from_icon_name ("edit-delete", GTK_ICON_SIZE_BUTTON);
		g_object_ref_sink (_tmp45_);
		_g_object_unref0 (image);
		image = _tmp45_;
		_tmp46_ = button;
		_tmp47_ = image;
		gtk_container_add ((GtkContainer*) _tmp46_, (GtkWidget*) _tmp47_);
		_tmp48_ = hbox;
		_tmp49_ = button;
		gtk_box_pack_start (_tmp48_, (GtkWidget*) _tmp49_, FALSE, TRUE, (guint) 0);
		_tmp50_ = button;
		g_signal_connect_object (_tmp50_, "clicked", (GCallback) _math_variable_popup_delete_variable_cb_gtk_button_clicked, self, 0);
		_tmp51_ = image;
		gtk_widget_show ((GtkWidget*) _tmp51_);
		_tmp52_ = button;
		gtk_widget_show ((GtkWidget*) _tmp52_);
		_g_object_unref0 (image);
	}
	result = hbox;
	_g_object_unref0 (label);
	_g_object_unref0 (button);
	_g_free0 (text);
	return result;
}


static void math_variable_popup_class_init (MathVariablePopupClass * klass) {
	math_variable_popup_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (MathVariablePopupPrivate));
	G_OBJECT_CLASS (klass)->finalize = math_variable_popup_finalize;
}


static void math_variable_popup_instance_init (MathVariablePopup * self) {
	self->priv = MATH_VARIABLE_POPUP_GET_PRIVATE (self);
}


static void math_variable_popup_finalize (GObject* obj) {
	MathVariablePopup * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_MATH_VARIABLE_POPUP, MathVariablePopup);
	_g_object_unref0 (self->priv->equation);
	_g_object_unref0 (self->priv->vbox);
	_g_object_unref0 (self->priv->variable_name_entry);
	_g_object_unref0 (self->priv->add_variable_button);
	G_OBJECT_CLASS (math_variable_popup_parent_class)->finalize (obj);
}


GType math_variable_popup_get_type (void) {
	static volatile gsize math_variable_popup_type_id__volatile = 0;
	if (g_once_init_enter (&math_variable_popup_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (MathVariablePopupClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) math_variable_popup_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MathVariablePopup), 0, (GInstanceInitFunc) math_variable_popup_instance_init, NULL };
		GType math_variable_popup_type_id;
		math_variable_popup_type_id = g_type_register_static (gtk_window_get_type (), "MathVariablePopup", &g_define_type_info, 0);
		g_once_init_leave (&math_variable_popup_type_id__volatile, math_variable_popup_type_id);
	}
	return math_variable_popup_type_id__volatile;
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



