/* AutoScroll.c generated by valac 0.38.4, the Vala compiler
 * generated from AutoScroll.vala, do not modify */

/*
 *  Copyright (C) 2009-2010 Michael J. Chudobiak.
 *
 *  This file is part of moserial.
 *
 *  moserial 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.
 *
 *  moserial 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 moserial.  If not, see <http://www.gnu.org/licenses/>.
 */

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


#define MOSERIAL_TYPE_AUTO_SCROLL (moserial_auto_scroll_get_type ())
#define MOSERIAL_AUTO_SCROLL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MOSERIAL_TYPE_AUTO_SCROLL, moserialAutoScroll))
#define MOSERIAL_AUTO_SCROLL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOSERIAL_TYPE_AUTO_SCROLL, moserialAutoScrollClass))
#define MOSERIAL_IS_AUTO_SCROLL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MOSERIAL_TYPE_AUTO_SCROLL))
#define MOSERIAL_IS_AUTO_SCROLL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOSERIAL_TYPE_AUTO_SCROLL))
#define MOSERIAL_AUTO_SCROLL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOSERIAL_TYPE_AUTO_SCROLL, moserialAutoScrollClass))

typedef struct _moserialAutoScroll moserialAutoScroll;
typedef struct _moserialAutoScrollClass moserialAutoScrollClass;
typedef struct _moserialAutoScrollPrivate moserialAutoScrollPrivate;
enum  {
	MOSERIAL_AUTO_SCROLL_0_PROPERTY,
	MOSERIAL_AUTO_SCROLL_NUM_PROPERTIES
};
static GParamSpec* moserial_auto_scroll_properties[MOSERIAL_AUTO_SCROLL_NUM_PROPERTIES];

struct _moserialAutoScroll {
	GObject parent_instance;
	moserialAutoScrollPrivate * priv;
};

struct _moserialAutoScrollClass {
	GObjectClass parent_class;
};


static gpointer moserial_auto_scroll_parent_class = NULL;

GType moserial_auto_scroll_get_type (void) G_GNUC_CONST;
void moserial_auto_scroll_scroll (GtkAdjustment* va);
void moserial_auto_scroll_doAutoScroll (GtkAdjustment* va);
static void _moserial_auto_scroll_scroll_gtk_adjustment_changed (GtkAdjustment* _sender, gpointer self);
void moserial_auto_scroll_setup (GtkAdjustment* incomingAsciiVerticalAdjuster, GtkAdjustment* incomingHexVerticalAdjuster, GtkAdjustment* outgoingAsciiVerticalAdjuster, GtkAdjustment* outgoingHexVerticalAdjuster);
static void _moserial_auto_scroll_doAutoScroll_gtk_adjustment_value_changed (GtkAdjustment* _sender, gpointer self);
moserialAutoScroll* moserial_auto_scroll_new (void);
moserialAutoScroll* moserial_auto_scroll_construct (GType object_type);


void moserial_auto_scroll_scroll (GtkAdjustment* va) {
	GtkAdjustment* _tmp0_;
	GtkAdjustment* _tmp1_;
	gdouble _tmp2_;
	gdouble _tmp3_;
	GtkAdjustment* _tmp4_;
	gdouble _tmp5_;
	gdouble _tmp6_;
	g_return_if_fail (va != NULL);
	_tmp0_ = va;
	_tmp1_ = va;
	_tmp2_ = gtk_adjustment_get_upper (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = va;
	_tmp5_ = gtk_adjustment_get_page_size (_tmp4_);
	_tmp6_ = _tmp5_;
	gtk_adjustment_set_value (_tmp0_, _tmp3_ - _tmp6_);
}


static void _moserial_auto_scroll_scroll_gtk_adjustment_changed (GtkAdjustment* _sender, gpointer self) {
	moserial_auto_scroll_scroll (_sender);
}


void moserial_auto_scroll_doAutoScroll (GtkAdjustment* va) {
	GtkAdjustment* _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	GtkAdjustment* _tmp3_;
	gdouble _tmp4_;
	gdouble _tmp5_;
	GtkAdjustment* _tmp6_;
	gdouble _tmp7_;
	gdouble _tmp8_;
	g_return_if_fail (va != NULL);
	_tmp0_ = va;
	_tmp1_ = gtk_adjustment_get_value (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = va;
	_tmp4_ = gtk_adjustment_get_upper (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = va;
	_tmp7_ = gtk_adjustment_get_page_size (_tmp6_);
	_tmp8_ = _tmp7_;
	if (_tmp2_ == (_tmp5_ - _tmp8_)) {
		GtkAdjustment* _tmp9_;
		_tmp9_ = va;
		g_signal_connect (_tmp9_, "changed", (GCallback) _moserial_auto_scroll_scroll_gtk_adjustment_changed, NULL);
	} else {
		GtkAdjustment* _tmp10_;
		guint _tmp11_;
		_tmp10_ = va;
		g_signal_parse_name ("changed", gtk_adjustment_get_type (), &_tmp11_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp10_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp11_, 0, NULL, (GCallback) _moserial_auto_scroll_scroll_gtk_adjustment_changed, NULL);
	}
}


static void _moserial_auto_scroll_doAutoScroll_gtk_adjustment_value_changed (GtkAdjustment* _sender, gpointer self) {
	moserial_auto_scroll_doAutoScroll (_sender);
}


void moserial_auto_scroll_setup (GtkAdjustment* incomingAsciiVerticalAdjuster, GtkAdjustment* incomingHexVerticalAdjuster, GtkAdjustment* outgoingAsciiVerticalAdjuster, GtkAdjustment* outgoingHexVerticalAdjuster) {
	GtkAdjustment* _tmp0_;
	GtkAdjustment* _tmp1_;
	GtkAdjustment* _tmp2_;
	GtkAdjustment* _tmp3_;
	GtkAdjustment* _tmp4_;
	GtkAdjustment* _tmp5_;
	GtkAdjustment* _tmp6_;
	GtkAdjustment* _tmp7_;
	g_return_if_fail (incomingAsciiVerticalAdjuster != NULL);
	g_return_if_fail (incomingHexVerticalAdjuster != NULL);
	g_return_if_fail (outgoingAsciiVerticalAdjuster != NULL);
	g_return_if_fail (outgoingHexVerticalAdjuster != NULL);
	_tmp0_ = incomingAsciiVerticalAdjuster;
	g_signal_connect (_tmp0_, "changed", (GCallback) _moserial_auto_scroll_scroll_gtk_adjustment_changed, NULL);
	_tmp1_ = incomingAsciiVerticalAdjuster;
	g_signal_connect (_tmp1_, "value-changed", (GCallback) _moserial_auto_scroll_doAutoScroll_gtk_adjustment_value_changed, NULL);
	_tmp2_ = incomingHexVerticalAdjuster;
	g_signal_connect (_tmp2_, "changed", (GCallback) _moserial_auto_scroll_scroll_gtk_adjustment_changed, NULL);
	_tmp3_ = incomingHexVerticalAdjuster;
	g_signal_connect (_tmp3_, "value-changed", (GCallback) _moserial_auto_scroll_doAutoScroll_gtk_adjustment_value_changed, NULL);
	_tmp4_ = outgoingAsciiVerticalAdjuster;
	g_signal_connect (_tmp4_, "changed", (GCallback) _moserial_auto_scroll_scroll_gtk_adjustment_changed, NULL);
	_tmp5_ = outgoingAsciiVerticalAdjuster;
	g_signal_connect (_tmp5_, "value-changed", (GCallback) _moserial_auto_scroll_doAutoScroll_gtk_adjustment_value_changed, NULL);
	_tmp6_ = outgoingHexVerticalAdjuster;
	g_signal_connect (_tmp6_, "changed", (GCallback) _moserial_auto_scroll_scroll_gtk_adjustment_changed, NULL);
	_tmp7_ = outgoingHexVerticalAdjuster;
	g_signal_connect (_tmp7_, "value-changed", (GCallback) _moserial_auto_scroll_doAutoScroll_gtk_adjustment_value_changed, NULL);
}


moserialAutoScroll* moserial_auto_scroll_construct (GType object_type) {
	moserialAutoScroll * self = NULL;
	self = (moserialAutoScroll*) g_object_new (object_type, NULL);
	return self;
}


moserialAutoScroll* moserial_auto_scroll_new (void) {
	return moserial_auto_scroll_construct (MOSERIAL_TYPE_AUTO_SCROLL);
}


static void moserial_auto_scroll_class_init (moserialAutoScrollClass * klass) {
	moserial_auto_scroll_parent_class = g_type_class_peek_parent (klass);
}


static void moserial_auto_scroll_instance_init (moserialAutoScroll * self) {
}


GType moserial_auto_scroll_get_type (void) {
	static volatile gsize moserial_auto_scroll_type_id__volatile = 0;
	if (g_once_init_enter (&moserial_auto_scroll_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (moserialAutoScrollClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) moserial_auto_scroll_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (moserialAutoScroll), 0, (GInstanceInitFunc) moserial_auto_scroll_instance_init, NULL };
		GType moserial_auto_scroll_type_id;
		moserial_auto_scroll_type_id = g_type_register_static (G_TYPE_OBJECT, "moserialAutoScroll", &g_define_type_info, 0);
		g_once_init_leave (&moserial_auto_scroll_type_id__volatile, moserial_auto_scroll_type_id);
	}
	return moserial_auto_scroll_type_id__volatile;
}



