/* test-scrolled.c generated by valac 0.20.1, the Vala compiler
 * generated from test-scrolled.vala, do not modify */

/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 8 -*- */
/*
 * Copyright (C) 2011 Alexander Larsson <alexl@redhat.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, see <http://www.gnu.org/licenses/>.
 */

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


#define TYPE_ROW (row_get_type ())
#define ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ROW, Row))
#define ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ROW, RowClass))
#define IS_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ROW))
#define IS_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_ROW))
#define ROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_ROW, RowClass))

typedef struct _Row Row;
typedef struct _RowClass RowClass;
typedef struct _RowPrivate RowPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block1Data Block1Data;

struct _Row {
	GtkGrid parent_instance;
	RowPrivate * priv;
	gint32 value;
};

struct _RowClass {
	GtkGridClass parent_class;
};

struct _Block1Data {
	int _ref_count_;
	EggListBox* list;
};


static gpointer row_parent_class = NULL;

GType row_get_type (void) G_GNUC_CONST;
enum  {
	ROW_DUMMY_PROPERTY
};
Row* row_new (void);
Row* row_construct (GType object_type);
static void row_finalize (GObject* obj);
gint compare (GtkWidget* a, GtkWidget* b);
gboolean filter (GtkWidget* widget);
gint _vala_main (gchar** args, int args_length1);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void __lambda2_ (Block1Data* _data1_);
static gint _compare_gcompare_data_func (gconstpointer a, gconstpointer b, gpointer self);
static void ___lambda2__gtk_button_clicked (GtkButton* _sender, gpointer self);
static void __lambda3_ (Block1Data* _data1_);
static gboolean _filter_egg_list_box_filter_func (GtkWidget* child, gpointer self);
static void ___lambda3__gtk_button_clicked (GtkButton* _sender, gpointer self);
static void __lambda4_ (Block1Data* _data1_);
static void ___lambda4__gtk_button_clicked (GtkButton* _sender, gpointer self);


Row* row_construct (GType object_type) {
	Row * self = NULL;
	gint32 _tmp0_ = 0;
	gint32 _tmp1_;
	gchar* _tmp2_ = NULL;
	gchar* _tmp3_;
	GtkLabel* _tmp4_;
	GtkLabel* _tmp5_;
	GtkLabel* l;
	self = (Row*) g_object_new (object_type, NULL);
	_tmp0_ = g_random_int_range ((gint32) 0, (gint32) 10000);
	self->value = _tmp0_;
	_tmp1_ = self->value;
	_tmp2_ = g_strdup_printf ("Value %u", (guint) _tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = (GtkLabel*) gtk_label_new (_tmp3_);
	g_object_ref_sink (_tmp4_);
	_tmp5_ = _tmp4_;
	_g_free0 (_tmp3_);
	l = _tmp5_;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) l);
	gtk_widget_show ((GtkWidget*) l);
	_g_object_unref0 (l);
	return self;
}


Row* row_new (void) {
	return row_construct (TYPE_ROW);
}


static void row_class_init (RowClass * klass) {
	row_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = row_finalize;
}


static void row_instance_init (Row * self) {
}


static void row_finalize (GObject* obj) {
	Row * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_ROW, Row);
	G_OBJECT_CLASS (row_parent_class)->finalize (obj);
}


GType row_get_type (void) {
	static volatile gsize row_type_id__volatile = 0;
	if (g_once_init_enter (&row_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Row), 0, (GInstanceInitFunc) row_instance_init, NULL };
		GType row_type_id;
		row_type_id = g_type_register_static (GTK_TYPE_GRID, "Row", &g_define_type_info, 0);
		g_once_init_leave (&row_type_id__volatile, row_type_id);
	}
	return row_type_id__volatile;
}


gint compare (GtkWidget* a, GtkWidget* b) {
	gint result = 0;
	GtkWidget* _tmp0_;
	gint32 _tmp1_;
	GtkWidget* _tmp2_;
	gint32 _tmp3_;
	g_return_val_if_fail (a != NULL, 0);
	g_return_val_if_fail (b != NULL, 0);
	_tmp0_ = b;
	_tmp1_ = (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, TYPE_ROW) ? ((Row*) _tmp0_) : NULL)->value;
	_tmp2_ = a;
	_tmp3_ = (G_TYPE_CHECK_INSTANCE_TYPE (_tmp2_, TYPE_ROW) ? ((Row*) _tmp2_) : NULL)->value;
	result = (gint) (((gint32) _tmp1_) - ((gint32) _tmp3_));
	return result;
}


gboolean filter (GtkWidget* widget) {
	gboolean result = FALSE;
	GtkWidget* _tmp0_;
	gint32 _tmp1_;
	g_return_val_if_fail (widget != NULL, FALSE);
	_tmp0_ = widget;
	_tmp1_ = (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, TYPE_ROW) ? ((Row*) _tmp0_) : NULL)->value;
	result = (_tmp1_ % 2) == ((gint32) 0);
	return result;
}


static Block1Data* block1_data_ref (Block1Data* _data1_) {
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}


static void block1_data_unref (void * _userdata_) {
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		_g_object_unref0 (_data1_->list);
		g_slice_free (Block1Data, _data1_);
	}
}


static gint _compare_gcompare_data_func (gconstpointer a, gconstpointer b, gpointer self) {
	gint result;
	result = compare (a, b);
	return result;
}


static void __lambda2_ (Block1Data* _data1_) {
	EggListBox* _tmp0_;
	_tmp0_ = _data1_->list;
	egg_list_box_set_sort_func (_tmp0_, _compare_gcompare_data_func, NULL, NULL);
}


static void ___lambda2__gtk_button_clicked (GtkButton* _sender, gpointer self) {
	__lambda2_ (self);
}


static gboolean _filter_egg_list_box_filter_func (GtkWidget* child, gpointer self) {
	gboolean result;
	result = filter (child);
	return result;
}


static void __lambda3_ (Block1Data* _data1_) {
	EggListBox* _tmp0_;
	_tmp0_ = _data1_->list;
	egg_list_box_set_filter_func (_tmp0_, _filter_egg_list_box_filter_func, NULL, NULL);
}


static void ___lambda3__gtk_button_clicked (GtkButton* _sender, gpointer self) {
	__lambda3_ (self);
}


static void __lambda4_ (Block1Data* _data1_) {
	EggListBox* _tmp0_;
	_tmp0_ = _data1_->list;
	egg_list_box_set_filter_func (_tmp0_, NULL, NULL, NULL);
}


static void ___lambda4__gtk_button_clicked (GtkButton* _sender, gpointer self) {
	__lambda4_ (self);
}


gint _vala_main (gchar** args, int args_length1) {
	gint result = 0;
	Block1Data* _data1_;
	gint num_rows;
	gchar** _tmp0_;
	gint _tmp0__length1;
	gint _tmp4_;
	GtkWindow* _tmp5_;
	GtkWindow* w;
	GtkBox* _tmp6_;
	GtkBox* hbox;
	GtkWindow* _tmp7_;
	GtkBox* _tmp8_;
	GtkScrolledWindow* _tmp9_;
	GtkScrolledWindow* scrolled;
	GtkScrolledWindow* _tmp10_;
	GtkBox* _tmp11_;
	GtkScrolledWindow* _tmp12_;
	GtkBox* _tmp13_;
	GtkBox* scrolled_box;
	GtkScrolledWindow* _tmp14_;
	GtkBox* _tmp15_;
	GtkLabel* _tmp16_;
	GtkLabel* label;
	GtkBox* _tmp17_;
	GtkLabel* _tmp18_;
	EggListBox* _tmp19_;
	GtkBox* _tmp20_;
	EggListBox* _tmp21_;
	EggListBox* _tmp22_;
	GtkScrolledWindow* _tmp23_;
	GtkAdjustment* _tmp24_ = NULL;
	GtkBox* _tmp33_;
	GtkBox* vbox;
	GtkBox* _tmp34_;
	GtkButton* _tmp35_;
	GtkButton* b;
	GtkButton* _tmp36_;
	GtkButton* _tmp37_;
	GtkButton* _tmp38_;
	GtkButton* _tmp39_;
	GtkButton* _tmp40_;
	GtkButton* _tmp41_;
	GtkButton* _tmp42_;
	GtkButton* _tmp43_;
	GtkWindow* _tmp44_;
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	num_rows = 0;
	gtk_init (&args_length1, &args);
	_tmp0_ = args;
	_tmp0__length1 = args_length1;
	if (_tmp0__length1 > 1) {
		gchar** _tmp1_;
		gint _tmp1__length1;
		const gchar* _tmp2_;
		gint _tmp3_ = 0;
		_tmp1_ = args;
		_tmp1__length1 = args_length1;
		_tmp2_ = _tmp1_[1];
		_tmp3_ = atoi (_tmp2_);
		num_rows = _tmp3_;
	}
	_tmp4_ = num_rows;
	if (_tmp4_ == 0) {
		num_rows = 1000;
	}
	_tmp5_ = (GtkWindow*) gtk_window_new (GTK_WINDOW_TOPLEVEL);
	g_object_ref_sink (_tmp5_);
	w = _tmp5_;
	_tmp6_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
	g_object_ref_sink (_tmp6_);
	hbox = _tmp6_;
	_tmp7_ = w;
	_tmp8_ = hbox;
	gtk_container_add ((GtkContainer*) _tmp7_, (GtkWidget*) _tmp8_);
	_tmp9_ = (GtkScrolledWindow*) gtk_scrolled_window_new (NULL, NULL);
	g_object_ref_sink (_tmp9_);
	scrolled = _tmp9_;
	_tmp10_ = scrolled;
	gtk_scrolled_window_set_policy (_tmp10_, GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
	_tmp11_ = hbox;
	_tmp12_ = scrolled;
	gtk_container_add ((GtkContainer*) _tmp11_, (GtkWidget*) _tmp12_);
	_tmp13_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp13_);
	scrolled_box = _tmp13_;
	_tmp14_ = scrolled;
	_tmp15_ = scrolled_box;
	gtk_scrolled_window_add_with_viewport (_tmp14_, (GtkWidget*) _tmp15_);
	_tmp16_ = (GtkLabel*) gtk_label_new ("This is \na LABEL\nwith rows");
	g_object_ref_sink (_tmp16_);
	label = _tmp16_;
	_tmp17_ = scrolled_box;
	_tmp18_ = label;
	gtk_container_add ((GtkContainer*) _tmp17_, (GtkWidget*) _tmp18_);
	_tmp19_ = egg_list_box_new ();
	g_object_ref_sink (_tmp19_);
	_data1_->list = _tmp19_;
	_tmp20_ = scrolled_box;
	_tmp21_ = _data1_->list;
	gtk_container_add ((GtkContainer*) _tmp20_, (GtkWidget*) _tmp21_);
	_tmp22_ = _data1_->list;
	_tmp23_ = scrolled;
	_tmp24_ = gtk_scrolled_window_get_vadjustment (_tmp23_);
	egg_list_box_set_adjustment (_tmp22_, _tmp24_);
	{
		gint i;
		i = 0;
		{
			gboolean _tmp25_;
			_tmp25_ = TRUE;
			while (TRUE) {
				gboolean _tmp26_;
				gint _tmp28_;
				gint _tmp29_;
				Row* _tmp30_;
				Row* row;
				EggListBox* _tmp31_;
				Row* _tmp32_;
				_tmp26_ = _tmp25_;
				if (!_tmp26_) {
					gint _tmp27_;
					_tmp27_ = i;
					i = _tmp27_ + 1;
				}
				_tmp25_ = FALSE;
				_tmp28_ = i;
				_tmp29_ = num_rows;
				if (!(_tmp28_ < _tmp29_)) {
					break;
				}
				_tmp30_ = row_new ();
				g_object_ref_sink (_tmp30_);
				row = _tmp30_;
				_tmp31_ = _data1_->list;
				_tmp32_ = row;
				gtk_container_add ((GtkContainer*) _tmp31_, (GtkWidget*) _tmp32_);
				_g_object_unref0 (row);
			}
		}
	}
	_tmp33_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp33_);
	vbox = _tmp33_;
	_tmp34_ = hbox;
	gtk_container_add ((GtkContainer*) _tmp34_, (GtkWidget*) vbox);
	_tmp35_ = (GtkButton*) gtk_button_new_with_label ("sort");
	g_object_ref_sink (_tmp35_);
	b = _tmp35_;
	_tmp36_ = b;
	gtk_container_add ((GtkContainer*) vbox, (GtkWidget*) _tmp36_);
	_tmp37_ = b;
	g_signal_connect_data (_tmp37_, "clicked", (GCallback) ___lambda2__gtk_button_clicked, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0);
	_tmp38_ = (GtkButton*) gtk_button_new_with_label ("filter");
	g_object_ref_sink (_tmp38_);
	_g_object_unref0 (b);
	b = _tmp38_;
	_tmp39_ = b;
	gtk_container_add ((GtkContainer*) vbox, (GtkWidget*) _tmp39_);
	_tmp40_ = b;
	g_signal_connect_data (_tmp40_, "clicked", (GCallback) ___lambda3__gtk_button_clicked, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0);
	_tmp41_ = (GtkButton*) gtk_button_new_with_label ("unfilter");
	g_object_ref_sink (_tmp41_);
	_g_object_unref0 (b);
	b = _tmp41_;
	_tmp42_ = b;
	gtk_container_add ((GtkContainer*) vbox, (GtkWidget*) _tmp42_);
	_tmp43_ = b;
	g_signal_connect_data (_tmp43_, "clicked", (GCallback) ___lambda4__gtk_button_clicked, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0);
	_tmp44_ = w;
	gtk_widget_show_all ((GtkWidget*) _tmp44_);
	gtk_main ();
	result = 0;
	_g_object_unref0 (b);
	_g_object_unref0 (vbox);
	_g_object_unref0 (label);
	_g_object_unref0 (scrolled_box);
	_g_object_unref0 (scrolled);
	_g_object_unref0 (hbox);
	_g_object_unref0 (w);
	block1_data_unref (_data1_);
	_data1_ = NULL;
	return result;
}


int main (int argc, char ** argv) {
	g_type_init ();
	return _vala_main (argv, argc);
}



