/* check_button.c generated by valac 0.56.17, the Vala compiler
 * generated from check_button.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 <cairo-gobject.h>
#include <stdlib.h>
#include <string.h>
#include <gdk/gdk.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_CHECK_BUTTON (widgets_check_button_get_type ())
#define WIDGETS_CHECK_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WIDGETS_TYPE_CHECK_BUTTON, WidgetsCheckButton))
#define WIDGETS_CHECK_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WIDGETS_TYPE_CHECK_BUTTON, WidgetsCheckButtonClass))
#define WIDGETS_IS_CHECK_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WIDGETS_TYPE_CHECK_BUTTON))
#define WIDGETS_IS_CHECK_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WIDGETS_TYPE_CHECK_BUTTON))
#define WIDGETS_CHECK_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WIDGETS_TYPE_CHECK_BUTTON, WidgetsCheckButtonClass))

typedef struct _WidgetsCheckButton WidgetsCheckButton;
typedef struct _WidgetsCheckButtonClass WidgetsCheckButtonClass;
typedef struct _WidgetsCheckButtonPrivate WidgetsCheckButtonPrivate;
enum  {
	WIDGETS_CHECK_BUTTON_0_PROPERTY,
	WIDGETS_CHECK_BUTTON_NUM_PROPERTIES
};
static GParamSpec* widgets_check_button_properties[WIDGETS_CHECK_BUTTON_NUM_PROPERTIES];
#define _cairo_surface_destroy0(var) ((var == NULL) ? NULL : (var = (cairo_surface_destroy (var), NULL)))

struct _WidgetsCheckButton {
	GtkCheckButton parent_instance;
	WidgetsCheckButtonPrivate * priv;
	gboolean is_hover;
	gboolean is_press;
	cairo_surface_t* checked_hover_surface;
	cairo_surface_t* checked_insensitive_surface;
	cairo_surface_t* checked_normal_surface;
	cairo_surface_t* checked_press_surface;
	cairo_surface_t* unchecked_hover_surface;
	cairo_surface_t* unchecked_insensitive_surface;
	cairo_surface_t* unchecked_normal_surface;
	cairo_surface_t* unchecked_press_surface;
};

struct _WidgetsCheckButtonClass {
	GtkCheckButtonClass parent_class;
};

static gpointer widgets_check_button_parent_class = NULL;

VALA_EXTERN GType widgets_check_button_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WidgetsCheckButton, g_object_unref)
VALA_EXTERN WidgetsCheckButton* widgets_check_button_new (void);
VALA_EXTERN WidgetsCheckButton* widgets_check_button_construct (GType object_type);
VALA_EXTERN cairo_surface_t* utils_create_image_surface (const gchar* surface_path);
static gboolean widgets_check_button_on_draw (WidgetsCheckButton* self,
                                       GtkWidget* widget,
                                       cairo_t* cr);
static gboolean _widgets_check_button_on_draw_gtk_widget_draw (GtkWidget* _sender,
                                                        cairo_t* cr,
                                                        gpointer self);
static gboolean __lambda157_ (WidgetsCheckButton* self,
                       GtkWidget* w,
                       GdkEventCrossing* e);
static gboolean ___lambda157__gtk_widget_enter_notify_event (GtkWidget* _sender,
                                                      GdkEventCrossing* event,
                                                      gpointer self);
static gboolean __lambda158_ (WidgetsCheckButton* self,
                       GtkWidget* w,
                       GdkEventCrossing* e);
static gboolean ___lambda158__gtk_widget_leave_notify_event (GtkWidget* _sender,
                                                      GdkEventCrossing* event,
                                                      gpointer self);
static gboolean __lambda159_ (WidgetsCheckButton* self,
                       GtkWidget* w,
                       GdkEventButton* e);
static gboolean ___lambda159__gtk_widget_button_press_event (GtkWidget* _sender,
                                                      GdkEventButton* event,
                                                      gpointer self);
static gboolean __lambda160_ (WidgetsCheckButton* self,
                       GtkWidget* w,
                       GdkEventButton* e);
static gboolean ___lambda160__gtk_widget_button_release_event (GtkWidget* _sender,
                                                        GdkEventButton* event,
                                                        gpointer self);
VALA_EXTERN void draw_draw_surface (cairo_t* cr,
                        cairo_surface_t* surface,
                        gint x,
                        gint y,
                        gint width,
                        gint height);
static void widgets_check_button_finalize (GObject * obj);
static GType widgets_check_button_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static gboolean
_widgets_check_button_on_draw_gtk_widget_draw (GtkWidget* _sender,
                                               cairo_t* cr,
                                               gpointer self)
{
	gboolean result;
	result = widgets_check_button_on_draw ((WidgetsCheckButton*) self, _sender, cr);
	return result;
}

static gboolean
__lambda157_ (WidgetsCheckButton* self,
              GtkWidget* w,
              GdkEventCrossing* e)
{
	gboolean result;
	g_return_val_if_fail (w != NULL, FALSE);
	g_return_val_if_fail (e != NULL, FALSE);
	self->is_hover = TRUE;
	gtk_widget_queue_draw ((GtkWidget*) self);
	result = FALSE;
	return result;
}

static gboolean
___lambda157__gtk_widget_enter_notify_event (GtkWidget* _sender,
                                             GdkEventCrossing* event,
                                             gpointer self)
{
	gboolean result;
	result = __lambda157_ ((WidgetsCheckButton*) self, _sender, event);
	return result;
}

static gboolean
__lambda158_ (WidgetsCheckButton* self,
              GtkWidget* w,
              GdkEventCrossing* e)
{
	gboolean result;
	g_return_val_if_fail (w != NULL, FALSE);
	g_return_val_if_fail (e != NULL, FALSE);
	self->is_hover = FALSE;
	gtk_widget_queue_draw ((GtkWidget*) self);
	result = FALSE;
	return result;
}

static gboolean
___lambda158__gtk_widget_leave_notify_event (GtkWidget* _sender,
                                             GdkEventCrossing* event,
                                             gpointer self)
{
	gboolean result;
	result = __lambda158_ ((WidgetsCheckButton*) self, _sender, event);
	return result;
}

static gboolean
__lambda159_ (WidgetsCheckButton* self,
              GtkWidget* w,
              GdkEventButton* e)
{
	gboolean result;
	g_return_val_if_fail (w != NULL, FALSE);
	g_return_val_if_fail (e != NULL, FALSE);
	self->is_press = TRUE;
	gtk_widget_queue_draw ((GtkWidget*) self);
	result = FALSE;
	return result;
}

static gboolean
___lambda159__gtk_widget_button_press_event (GtkWidget* _sender,
                                             GdkEventButton* event,
                                             gpointer self)
{
	gboolean result;
	result = __lambda159_ ((WidgetsCheckButton*) self, _sender, event);
	return result;
}

static gboolean
__lambda160_ (WidgetsCheckButton* self,
              GtkWidget* w,
              GdkEventButton* e)
{
	gboolean result;
	g_return_val_if_fail (w != NULL, FALSE);
	g_return_val_if_fail (e != NULL, FALSE);
	self->is_hover = FALSE;
	self->is_press = FALSE;
	gtk_widget_queue_draw ((GtkWidget*) self);
	result = FALSE;
	return result;
}

static gboolean
___lambda160__gtk_widget_button_release_event (GtkWidget* _sender,
                                               GdkEventButton* event,
                                               gpointer self)
{
	gboolean result;
	result = __lambda160_ ((WidgetsCheckButton*) self, _sender, event);
	return result;
}

WidgetsCheckButton*
widgets_check_button_construct (GType object_type)
{
	WidgetsCheckButton * self = NULL;
	cairo_surface_t* _tmp0_;
	cairo_surface_t* _tmp1_;
	cairo_surface_t* _tmp2_;
	cairo_surface_t* _tmp3_;
	cairo_surface_t* _tmp4_;
	cairo_surface_t* _tmp5_;
	cairo_surface_t* _tmp6_;
	cairo_surface_t* _tmp7_;
	cairo_surface_t* _tmp8_;
	cairo_surface_t* _tmp9_;
	self = (WidgetsCheckButton*) g_object_new (object_type, NULL);
	_tmp0_ = utils_create_image_surface ("checkbox_checked_normal.svg");
	_cairo_surface_destroy0 (self->checked_normal_surface);
	self->checked_normal_surface = _tmp0_;
	_tmp1_ = utils_create_image_surface ("checkbox_checked_hover.svg");
	_cairo_surface_destroy0 (self->checked_hover_surface);
	self->checked_hover_surface = _tmp1_;
	_tmp2_ = utils_create_image_surface ("checkbox_checked_press.svg");
	_cairo_surface_destroy0 (self->checked_press_surface);
	self->checked_press_surface = _tmp2_;
	_tmp3_ = utils_create_image_surface ("checkbox_checked_insensitive.svg");
	_cairo_surface_destroy0 (self->checked_insensitive_surface);
	self->checked_insensitive_surface = _tmp3_;
	_tmp4_ = utils_create_image_surface ("checkbox_unchecked_normal.svg");
	_cairo_surface_destroy0 (self->unchecked_normal_surface);
	self->unchecked_normal_surface = _tmp4_;
	_tmp5_ = utils_create_image_surface ("checkbox_unchecked_hover.svg");
	_cairo_surface_destroy0 (self->unchecked_hover_surface);
	self->unchecked_hover_surface = _tmp5_;
	_tmp6_ = utils_create_image_surface ("checkbox_unchecked_press.svg");
	_cairo_surface_destroy0 (self->unchecked_press_surface);
	self->unchecked_press_surface = _tmp6_;
	_tmp7_ = utils_create_image_surface ("checkbox_unchecked_insensitive.svg");
	_cairo_surface_destroy0 (self->unchecked_insensitive_surface);
	self->unchecked_insensitive_surface = _tmp7_;
	_tmp8_ = self->checked_normal_surface;
	_tmp9_ = self->checked_normal_surface;
	gtk_widget_set_size_request ((GtkWidget*) self, cairo_image_surface_get_width (_tmp8_) / gtk_widget_get_scale_factor ((GtkWidget*) self), cairo_image_surface_get_height (_tmp9_) / gtk_widget_get_scale_factor ((GtkWidget*) self));
	g_signal_connect_object ((GtkWidget*) self, "draw", (GCallback) _widgets_check_button_on_draw_gtk_widget_draw, self, 0);
	g_signal_connect_object ((GtkWidget*) self, "enter-notify-event", (GCallback) ___lambda157__gtk_widget_enter_notify_event, self, 0);
	g_signal_connect_object ((GtkWidget*) self, "leave-notify-event", (GCallback) ___lambda158__gtk_widget_leave_notify_event, self, 0);
	g_signal_connect_object ((GtkWidget*) self, "button-press-event", (GCallback) ___lambda159__gtk_widget_button_press_event, self, 0);
	g_signal_connect_object ((GtkWidget*) self, "button-release-event", (GCallback) ___lambda160__gtk_widget_button_release_event, self, 0);
	return self;
}

WidgetsCheckButton*
widgets_check_button_new (void)
{
	return widgets_check_button_construct (WIDGETS_TYPE_CHECK_BUTTON);
}

static gboolean
widgets_check_button_on_draw (WidgetsCheckButton* self,
                              GtkWidget* widget,
                              cairo_t* cr)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (widget != NULL, FALSE);
	g_return_val_if_fail (cr != NULL, FALSE);
	if (gtk_widget_get_sensitive ((GtkWidget*) self)) {
		if (gtk_toggle_button_get_active ((GtkToggleButton*) self)) {
			if (self->is_press) {
				cairo_surface_t* _tmp0_;
				_tmp0_ = self->checked_press_surface;
				draw_draw_surface (cr, _tmp0_, 0, 0, 0, 0);
			} else {
				if (self->is_hover) {
					cairo_surface_t* _tmp1_;
					_tmp1_ = self->checked_hover_surface;
					draw_draw_surface (cr, _tmp1_, 0, 0, 0, 0);
				} else {
					cairo_surface_t* _tmp2_;
					_tmp2_ = self->checked_normal_surface;
					draw_draw_surface (cr, _tmp2_, 0, 0, 0, 0);
				}
			}
		} else {
			if (self->is_press) {
				cairo_surface_t* _tmp3_;
				_tmp3_ = self->unchecked_press_surface;
				draw_draw_surface (cr, _tmp3_, 0, 0, 0, 0);
			} else {
				if (self->is_hover) {
					cairo_surface_t* _tmp4_;
					_tmp4_ = self->unchecked_hover_surface;
					draw_draw_surface (cr, _tmp4_, 0, 0, 0, 0);
				} else {
					cairo_surface_t* _tmp5_;
					_tmp5_ = self->unchecked_normal_surface;
					draw_draw_surface (cr, _tmp5_, 0, 0, 0, 0);
				}
			}
		}
	} else {
		if (gtk_toggle_button_get_active ((GtkToggleButton*) self)) {
			cairo_surface_t* _tmp6_;
			_tmp6_ = self->checked_insensitive_surface;
			draw_draw_surface (cr, _tmp6_, 0, 0, 0, 0);
		} else {
			cairo_surface_t* _tmp7_;
			_tmp7_ = self->unchecked_insensitive_surface;
			draw_draw_surface (cr, _tmp7_, 0, 0, 0, 0);
		}
	}
	result = TRUE;
	return result;
}

static void
widgets_check_button_class_init (WidgetsCheckButtonClass * klass,
                                 gpointer klass_data)
{
	widgets_check_button_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = widgets_check_button_finalize;
}

static void
widgets_check_button_instance_init (WidgetsCheckButton * self,
                                    gpointer klass)
{
	self->is_hover = FALSE;
	self->is_press = FALSE;
}

static void
widgets_check_button_finalize (GObject * obj)
{
	WidgetsCheckButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_CHECK_BUTTON, WidgetsCheckButton);
	_cairo_surface_destroy0 (self->checked_hover_surface);
	_cairo_surface_destroy0 (self->checked_insensitive_surface);
	_cairo_surface_destroy0 (self->checked_normal_surface);
	_cairo_surface_destroy0 (self->checked_press_surface);
	_cairo_surface_destroy0 (self->unchecked_hover_surface);
	_cairo_surface_destroy0 (self->unchecked_insensitive_surface);
	_cairo_surface_destroy0 (self->unchecked_normal_surface);
	_cairo_surface_destroy0 (self->unchecked_press_surface);
	G_OBJECT_CLASS (widgets_check_button_parent_class)->finalize (obj);
}

static GType
widgets_check_button_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WidgetsCheckButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) widgets_check_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WidgetsCheckButton), 0, (GInstanceInitFunc) widgets_check_button_instance_init, NULL };
	GType widgets_check_button_type_id;
	widgets_check_button_type_id = g_type_register_static (gtk_check_button_get_type (), "WidgetsCheckButton", &g_define_type_info, 0);
	return widgets_check_button_type_id;
}

GType
widgets_check_button_get_type (void)
{
	static volatile gsize widgets_check_button_type_id__once = 0;
	if (g_once_init_enter (&widgets_check_button_type_id__once)) {
		GType widgets_check_button_type_id;
		widgets_check_button_type_id = widgets_check_button_get_type_once ();
		g_once_init_leave (&widgets_check_button_type_id__once, widgets_check_button_type_id);
	}
	return widgets_check_button_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;
}

