/* AutoScroll.c generated by valac 0.54.3, 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-object.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include <string.h>

#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#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;

VALA_EXTERN GType moserial_auto_scroll_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (moserialAutoScroll, g_object_unref)
VALA_EXTERN void moserial_auto_scroll_scroll (GtkAdjustment* va);
VALA_EXTERN void moserial_auto_scroll_doAutoScroll (GtkAdjustment* va);
static void _moserial_auto_scroll_scroll_gtk_adjustment_changed (GtkAdjustment* _sender,
                                                          gpointer self);
VALA_EXTERN 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);
VALA_EXTERN moserialAutoScroll* moserial_auto_scroll_new (void);
VALA_EXTERN moserialAutoScroll* moserial_auto_scroll_construct (GType object_type);
static GType moserial_auto_scroll_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

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

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)
{
	gdouble _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	gdouble _tmp3_;
	gdouble _tmp4_;
	gdouble _tmp5_;
	g_return_if_fail (va != NULL);
	_tmp0_ = gtk_adjustment_get_value (va);
	_tmp1_ = _tmp0_;
	_tmp2_ = gtk_adjustment_get_upper (va);
	_tmp3_ = _tmp2_;
	_tmp4_ = gtk_adjustment_get_page_size (va);
	_tmp5_ = _tmp4_;
	if (_tmp1_ == (_tmp3_ - _tmp5_)) {
		g_signal_connect (va, "changed", (GCallback) _moserial_auto_scroll_scroll_gtk_adjustment_changed, NULL);
	} else {
		guint _tmp6_;
		g_signal_parse_name ("changed", gtk_adjustment_get_type (), &_tmp6_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (va, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp6_, 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)
{
	g_return_if_fail (incomingAsciiVerticalAdjuster != NULL);
	g_return_if_fail (incomingHexVerticalAdjuster != NULL);
	g_return_if_fail (outgoingAsciiVerticalAdjuster != NULL);
	g_return_if_fail (outgoingHexVerticalAdjuster != NULL);
	g_signal_connect (incomingAsciiVerticalAdjuster, "changed", (GCallback) _moserial_auto_scroll_scroll_gtk_adjustment_changed, NULL);
	g_signal_connect (incomingAsciiVerticalAdjuster, "value-changed", (GCallback) _moserial_auto_scroll_doAutoScroll_gtk_adjustment_value_changed, NULL);
	g_signal_connect (incomingHexVerticalAdjuster, "changed", (GCallback) _moserial_auto_scroll_scroll_gtk_adjustment_changed, NULL);
	g_signal_connect (incomingHexVerticalAdjuster, "value-changed", (GCallback) _moserial_auto_scroll_doAutoScroll_gtk_adjustment_value_changed, NULL);
	g_signal_connect (outgoingAsciiVerticalAdjuster, "changed", (GCallback) _moserial_auto_scroll_scroll_gtk_adjustment_changed, NULL);
	g_signal_connect (outgoingAsciiVerticalAdjuster, "value-changed", (GCallback) _moserial_auto_scroll_doAutoScroll_gtk_adjustment_value_changed, NULL);
	g_signal_connect (outgoingHexVerticalAdjuster, "changed", (GCallback) _moserial_auto_scroll_scroll_gtk_adjustment_changed, NULL);
	g_signal_connect (outgoingHexVerticalAdjuster, "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,
                                 gpointer klass_data)
{
	moserial_auto_scroll_parent_class = g_type_class_peek_parent (klass);
}

static void
moserial_auto_scroll_instance_init (moserialAutoScroll * self,
                                    gpointer klass)
{
}

static GType
moserial_auto_scroll_get_type_once (void)
{
	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);
	return moserial_auto_scroll_type_id;
}

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)) {
		GType moserial_auto_scroll_type_id;
		moserial_auto_scroll_type_id = moserial_auto_scroll_get_type_once ();
		g_once_init_leave (&moserial_auto_scroll_type_id__volatile, moserial_auto_scroll_type_id);
	}
	return moserial_auto_scroll_type_id__volatile;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

