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

/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 4 -*-
 * -*- coding: utf-8 -*-
 *
 * Copyright (C) 2011 ~ 2018 Deepin, Inc.
 *               2011 ~ 2018 Wang Yong
 *
 * Author:     Wang Yong <wangyong@deepin.com>
 * Maintainer: Wang Yong <wangyong@deepin.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 3 of the License, or
 * 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 <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include <string.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#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 WIDGETS_TYPE_SWITCHER (widgets_switcher_get_type ())
#define WIDGETS_SWITCHER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WIDGETS_TYPE_SWITCHER, WidgetsSwitcher))
#define WIDGETS_SWITCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WIDGETS_TYPE_SWITCHER, WidgetsSwitcherClass))
#define WIDGETS_IS_SWITCHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WIDGETS_TYPE_SWITCHER))
#define WIDGETS_IS_SWITCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WIDGETS_TYPE_SWITCHER))
#define WIDGETS_SWITCHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WIDGETS_TYPE_SWITCHER, WidgetsSwitcherClass))

typedef struct _WidgetsSwitcher WidgetsSwitcher;
typedef struct _WidgetsSwitcherClass WidgetsSwitcherClass;
typedef struct _WidgetsSwitcherPrivate WidgetsSwitcherPrivate;

#define ANIMATION_TYPE_ANIMATE_TIMER (animation_animate_timer_get_type ())
#define ANIMATION_ANIMATE_TIMER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ANIMATION_TYPE_ANIMATE_TIMER, AnimationAnimateTimer))
#define ANIMATION_ANIMATE_TIMER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ANIMATION_TYPE_ANIMATE_TIMER, AnimationAnimateTimerClass))
#define ANIMATION_IS_ANIMATE_TIMER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ANIMATION_TYPE_ANIMATE_TIMER))
#define ANIMATION_IS_ANIMATE_TIMER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ANIMATION_TYPE_ANIMATE_TIMER))
#define ANIMATION_ANIMATE_TIMER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ANIMATION_TYPE_ANIMATE_TIMER, AnimationAnimateTimerClass))

typedef struct _AnimationAnimateTimer AnimationAnimateTimer;
typedef struct _AnimationAnimateTimerClass AnimationAnimateTimerClass;
enum  {
	WIDGETS_SWITCHER_0_PROPERTY,
	WIDGETS_SWITCHER_NUM_PROPERTIES
};
static GParamSpec* widgets_switcher_properties[WIDGETS_SWITCHER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef gdouble (*AnimationAnimateTimerEasingFunc) (gdouble x, gpointer user_data);

struct _WidgetsSwitcher {
	GtkHBox parent_instance;
	WidgetsSwitcherPrivate * priv;
	AnimationAnimateTimer* scroll_to_left_timer;
	AnimationAnimateTimer* scroll_to_right_timer;
	GtkBox* box;
	GtkBox* left_box;
	GtkBox* right_box;
	GtkScrolledWindow* scrolledwindow;
	gint scroll_to_left_end_x;
	gint scroll_to_left_interval;
	gint scroll_to_left_start_x;
	gint scroll_to_right_end_x;
	gint scroll_to_right_interval;
	gint scroll_to_right_start_x;
	gint width;
};

struct _WidgetsSwitcherClass {
	GtkHBoxClass parent_class;
};

static gpointer widgets_switcher_parent_class = NULL;

VALA_EXTERN GType widgets_switcher_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WidgetsSwitcher, g_object_unref)
VALA_EXTERN GType animation_animate_timer_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (AnimationAnimateTimer, g_object_unref)
VALA_EXTERN WidgetsSwitcher* widgets_switcher_new (gint w);
VALA_EXTERN WidgetsSwitcher* widgets_switcher_construct (GType object_type,
                                             gint w);
VALA_EXTERN gdouble animation_animate_timer_ease_out_quint (gdouble x);
static gdouble _animation_animate_timer_ease_out_quint_animation_animate_timer_easing_func (gdouble x,
                                                                                     gpointer self);
VALA_EXTERN AnimationAnimateTimer* animation_animate_timer_new (AnimationAnimateTimerEasingFunc func,
                                                    gpointer func_target,
                                                    gint speed);
VALA_EXTERN AnimationAnimateTimer* animation_animate_timer_construct (GType object_type,
                                                          AnimationAnimateTimerEasingFunc func,
                                                          gpointer func_target,
                                                          gint speed);
VALA_EXTERN void widgets_switcher_scroll_to_left_animate (WidgetsSwitcher* self,
                                              gdouble progress);
static void _widgets_switcher_scroll_to_left_animate_animation_animate_timer_animate (AnimationAnimateTimer* _sender,
                                                                               gdouble progress,
                                                                               gpointer self);
VALA_EXTERN void widgets_switcher_scroll_to_right_animate (WidgetsSwitcher* self,
                                               gdouble progress);
static void _widgets_switcher_scroll_to_right_animate_animation_animate_timer_animate (AnimationAnimateTimer* _sender,
                                                                                gdouble progress,
                                                                                gpointer self);
VALA_EXTERN void widgets_switcher_add_to_left_box (WidgetsSwitcher* self,
                                       GtkWidget* start_widget);
VALA_EXTERN void utils_remove_all_children (GtkContainer* container);
VALA_EXTERN void widgets_switcher_scroll_to_left (WidgetsSwitcher* self,
                                      GtkWidget* start_widget,
                                      GtkWidget* end_widget);
VALA_EXTERN void animation_animate_timer_reset (AnimationAnimateTimer* self,
                                    gint temp_speed);
VALA_EXTERN void widgets_switcher_scroll_to_right (WidgetsSwitcher* self,
                                       GtkWidget* start_widget,
                                       GtkWidget* end_widget);
VALA_EXTERN void animation_animate_timer_stop (AnimationAnimateTimer* self);
static void widgets_switcher_finalize (GObject * obj);
static GType widgets_switcher_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static gdouble
_animation_animate_timer_ease_out_quint_animation_animate_timer_easing_func (gdouble x,
                                                                             gpointer self)
{
	gdouble result;
	result = animation_animate_timer_ease_out_quint (x);
	return result;
}

static void
_widgets_switcher_scroll_to_left_animate_animation_animate_timer_animate (AnimationAnimateTimer* _sender,
                                                                          gdouble progress,
                                                                          gpointer self)
{
	widgets_switcher_scroll_to_left_animate ((WidgetsSwitcher*) self, progress);
}

static void
_widgets_switcher_scroll_to_right_animate_animation_animate_timer_animate (AnimationAnimateTimer* _sender,
                                                                           gdouble progress,
                                                                           gpointer self)
{
	widgets_switcher_scroll_to_right_animate ((WidgetsSwitcher*) self, progress);
}

WidgetsSwitcher*
widgets_switcher_construct (GType object_type,
                            gint w)
{
	WidgetsSwitcher * self = NULL;
	AnimationAnimateTimer* _tmp0_;
	AnimationAnimateTimer* _tmp1_;
	AnimationAnimateTimer* _tmp2_;
	AnimationAnimateTimer* _tmp3_;
	GtkScrolledWindow* _tmp4_;
	GtkScrolledWindow* _tmp5_;
	GtkScrolledWindow* _tmp6_;
	GtkStyleContext* _tmp7_;
	GtkScrolledWindow* _tmp8_;
	GtkWidget* _tmp9_;
	GtkStyleContext* _tmp10_;
	GtkScrolledWindow* _tmp11_;
	GtkWidget* _tmp12_;
	GtkStyleContext* _tmp13_;
	GtkBox* _tmp14_;
	GtkBox* _tmp15_;
	GtkBox* _tmp16_;
	GtkBox* _tmp17_;
	GtkBox* _tmp18_;
	GtkBox* _tmp19_;
	GtkBox* _tmp20_;
	GtkScrolledWindow* _tmp21_;
	GtkBox* _tmp22_;
	GtkScrolledWindow* _tmp23_;
	self = (WidgetsSwitcher*) g_object_new (object_type, NULL);
	self->width = w;
	_tmp0_ = animation_animate_timer_new (_animation_animate_timer_ease_out_quint_animation_animate_timer_easing_func, NULL, self->scroll_to_left_interval);
	_g_object_unref0 (self->scroll_to_left_timer);
	self->scroll_to_left_timer = _tmp0_;
	_tmp1_ = self->scroll_to_left_timer;
	g_signal_connect_object (_tmp1_, "animate", (GCallback) _widgets_switcher_scroll_to_left_animate_animation_animate_timer_animate, self, 0);
	_tmp2_ = animation_animate_timer_new (_animation_animate_timer_ease_out_quint_animation_animate_timer_easing_func, NULL, self->scroll_to_right_interval);
	_g_object_unref0 (self->scroll_to_right_timer);
	self->scroll_to_right_timer = _tmp2_;
	_tmp3_ = self->scroll_to_right_timer;
	g_signal_connect_object (_tmp3_, "animate", (GCallback) _widgets_switcher_scroll_to_right_animate_animation_animate_timer_animate, self, 0);
	_tmp4_ = (GtkScrolledWindow*) gtk_scrolled_window_new (NULL, NULL);
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->scrolledwindow);
	self->scrolledwindow = _tmp4_;
	_tmp5_ = self->scrolledwindow;
	gtk_scrolled_window_set_shadow_type (_tmp5_, GTK_SHADOW_NONE);
	_tmp6_ = self->scrolledwindow;
	_tmp7_ = gtk_widget_get_style_context ((GtkWidget*) _tmp6_);
	gtk_style_context_add_class (_tmp7_, "scrolledwindow");
	_tmp8_ = self->scrolledwindow;
	_tmp9_ = gtk_scrolled_window_get_vscrollbar (_tmp8_);
	_tmp10_ = gtk_widget_get_style_context (_tmp9_);
	gtk_style_context_add_class (_tmp10_, "switcher_scrollbar");
	_tmp11_ = self->scrolledwindow;
	_tmp12_ = gtk_scrolled_window_get_hscrollbar (_tmp11_);
	_tmp13_ = gtk_widget_get_style_context (_tmp12_);
	gtk_style_context_add_class (_tmp13_, "switcher_scrollbar");
	_tmp14_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
	g_object_ref_sink (_tmp14_);
	_g_object_unref0 (self->box);
	self->box = _tmp14_;
	_tmp15_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp15_);
	_g_object_unref0 (self->left_box);
	self->left_box = _tmp15_;
	_tmp16_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp16_);
	_g_object_unref0 (self->right_box);
	self->right_box = _tmp16_;
	gtk_widget_set_size_request ((GtkWidget*) self, self->width, -1);
	_tmp17_ = self->box;
	_tmp18_ = self->left_box;
	gtk_box_pack_start (_tmp17_, (GtkWidget*) _tmp18_, FALSE, FALSE, (guint) 0);
	_tmp19_ = self->box;
	_tmp20_ = self->right_box;
	gtk_box_pack_start (_tmp19_, (GtkWidget*) _tmp20_, FALSE, FALSE, (guint) 0);
	_tmp21_ = self->scrolledwindow;
	_tmp22_ = self->box;
	gtk_container_add ((GtkContainer*) _tmp21_, (GtkWidget*) _tmp22_);
	_tmp23_ = self->scrolledwindow;
	gtk_box_pack_start ((GtkBox*) self, (GtkWidget*) _tmp23_, TRUE, TRUE, (guint) 0);
	return self;
}

WidgetsSwitcher*
widgets_switcher_new (gint w)
{
	return widgets_switcher_construct (WIDGETS_TYPE_SWITCHER, w);
}

void
widgets_switcher_add_to_left_box (WidgetsSwitcher* self,
                                  GtkWidget* start_widget)
{
	GtkBox* _tmp0_;
	GtkBox* _tmp1_;
	GtkBox* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (start_widget != NULL);
	_tmp0_ = self->left_box;
	utils_remove_all_children ((GtkContainer*) _tmp0_);
	_tmp1_ = self->right_box;
	utils_remove_all_children ((GtkContainer*) _tmp1_);
	_tmp2_ = self->left_box;
	gtk_box_pack_start (_tmp2_, start_widget, TRUE, TRUE, (guint) 0);
}

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

void
widgets_switcher_scroll_to_left (WidgetsSwitcher* self,
                                 GtkWidget* start_widget,
                                 GtkWidget* end_widget)
{
	GtkBox* _tmp0_;
	GtkBox* _tmp1_;
	GtkBox* _tmp2_;
	GtkBox* _tmp3_;
	GtkAdjustment* adjust = NULL;
	GtkScrolledWindow* _tmp4_;
	GtkAdjustment* _tmp5_;
	GtkAdjustment* _tmp6_;
	AnimationAnimateTimer* _tmp7_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (start_widget != NULL);
	g_return_if_fail (end_widget != NULL);
	_tmp0_ = self->left_box;
	utils_remove_all_children ((GtkContainer*) _tmp0_);
	_tmp1_ = self->right_box;
	utils_remove_all_children ((GtkContainer*) _tmp1_);
	_tmp2_ = self->left_box;
	gtk_box_pack_start (_tmp2_, end_widget, TRUE, TRUE, (guint) 0);
	_tmp3_ = self->right_box;
	gtk_box_pack_start (_tmp3_, start_widget, TRUE, TRUE, (guint) 0);
	_tmp4_ = self->scrolledwindow;
	_tmp5_ = gtk_scrolled_window_get_hadjustment (_tmp4_);
	_tmp6_ = _g_object_ref0 (_tmp5_);
	adjust = _tmp6_;
	gtk_adjustment_set_value (adjust, (gdouble) self->width);
	self->scroll_to_left_start_x = self->width;
	self->scroll_to_left_end_x = 0;
	_tmp7_ = self->scroll_to_left_timer;
	animation_animate_timer_reset (_tmp7_, -1);
	_g_object_unref0 (adjust);
}

void
widgets_switcher_scroll_to_right (WidgetsSwitcher* self,
                                  GtkWidget* start_widget,
                                  GtkWidget* end_widget)
{
	GtkBox* _tmp0_;
	GtkBox* _tmp1_;
	GtkBox* _tmp2_;
	GtkBox* _tmp3_;
	GtkAdjustment* adjust = NULL;
	GtkScrolledWindow* _tmp4_;
	GtkAdjustment* _tmp5_;
	GtkAdjustment* _tmp6_;
	AnimationAnimateTimer* _tmp7_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (start_widget != NULL);
	g_return_if_fail (end_widget != NULL);
	_tmp0_ = self->left_box;
	utils_remove_all_children ((GtkContainer*) _tmp0_);
	_tmp1_ = self->right_box;
	utils_remove_all_children ((GtkContainer*) _tmp1_);
	_tmp2_ = self->left_box;
	gtk_box_pack_start (_tmp2_, start_widget, TRUE, TRUE, (guint) 0);
	_tmp3_ = self->right_box;
	gtk_box_pack_start (_tmp3_, end_widget, TRUE, TRUE, (guint) 0);
	_tmp4_ = self->scrolledwindow;
	_tmp5_ = gtk_scrolled_window_get_hadjustment (_tmp4_);
	_tmp6_ = _g_object_ref0 (_tmp5_);
	adjust = _tmp6_;
	gtk_adjustment_set_value (adjust, (gdouble) 0);
	self->scroll_to_right_start_x = 0;
	self->scroll_to_right_end_x = self->width;
	_tmp7_ = self->scroll_to_right_timer;
	animation_animate_timer_reset (_tmp7_, -1);
	_g_object_unref0 (adjust);
}

void
widgets_switcher_scroll_to_left_animate (WidgetsSwitcher* self,
                                         gdouble progress)
{
	GtkAdjustment* adjust = NULL;
	GtkScrolledWindow* _tmp0_;
	GtkAdjustment* _tmp1_;
	GtkAdjustment* _tmp2_;
	GtkAdjustment* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->scrolledwindow;
	_tmp1_ = gtk_scrolled_window_get_hadjustment (_tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	adjust = _tmp2_;
	_tmp3_ = adjust;
	gtk_adjustment_set_value (_tmp3_, self->scroll_to_left_start_x + (((gint) (self->scroll_to_left_end_x - self->scroll_to_left_start_x)) * progress));
	if (progress >= 1.0) {
		AnimationAnimateTimer* _tmp4_;
		_tmp4_ = self->scroll_to_left_timer;
		animation_animate_timer_stop (_tmp4_);
	}
	_g_object_unref0 (adjust);
}

void
widgets_switcher_scroll_to_right_animate (WidgetsSwitcher* self,
                                          gdouble progress)
{
	GtkAdjustment* adjust = NULL;
	GtkScrolledWindow* _tmp0_;
	GtkAdjustment* _tmp1_;
	GtkAdjustment* _tmp2_;
	GtkAdjustment* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->scrolledwindow;
	_tmp1_ = gtk_scrolled_window_get_hadjustment (_tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	adjust = _tmp2_;
	_tmp3_ = adjust;
	gtk_adjustment_set_value (_tmp3_, self->scroll_to_right_start_x + (((gint) (self->scroll_to_right_end_x - self->scroll_to_right_start_x)) * progress));
	if (progress >= 1.0) {
		AnimationAnimateTimer* _tmp4_;
		_tmp4_ = self->scroll_to_right_timer;
		animation_animate_timer_stop (_tmp4_);
	}
	_g_object_unref0 (adjust);
}

static void
widgets_switcher_class_init (WidgetsSwitcherClass * klass,
                             gpointer klass_data)
{
	widgets_switcher_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = widgets_switcher_finalize;
}

static void
widgets_switcher_instance_init (WidgetsSwitcher * self,
                                gpointer klass)
{
	self->scroll_to_left_interval = 500;
	self->scroll_to_right_interval = 500;
}

static void
widgets_switcher_finalize (GObject * obj)
{
	WidgetsSwitcher * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_SWITCHER, WidgetsSwitcher);
	_g_object_unref0 (self->scroll_to_left_timer);
	_g_object_unref0 (self->scroll_to_right_timer);
	_g_object_unref0 (self->box);
	_g_object_unref0 (self->left_box);
	_g_object_unref0 (self->right_box);
	_g_object_unref0 (self->scrolledwindow);
	G_OBJECT_CLASS (widgets_switcher_parent_class)->finalize (obj);
}

static GType
widgets_switcher_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WidgetsSwitcherClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) widgets_switcher_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WidgetsSwitcher), 0, (GInstanceInitFunc) widgets_switcher_instance_init, NULL };
	GType widgets_switcher_type_id;
	widgets_switcher_type_id = g_type_register_static (gtk_hbox_get_type (), "WidgetsSwitcher", &g_define_type_info, 0);
	return widgets_switcher_type_id;
}

GType
widgets_switcher_get_type (void)
{
	static volatile gsize widgets_switcher_type_id__once = 0;
	if (g_once_init_enter (&widgets_switcher_type_id__once)) {
		GType widgets_switcher_type_id;
		widgets_switcher_type_id = widgets_switcher_get_type_once ();
		g_once_init_leave (&widgets_switcher_type_id__once, widgets_switcher_type_id);
	}
	return widgets_switcher_type_id__once;
}

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

