/* link_button.c generated by valac 0.56.17, the Vala compiler
 * generated from link_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 <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_CLICK_EVENT_BOX (widgets_click_event_box_get_type ())
#define WIDGETS_CLICK_EVENT_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WIDGETS_TYPE_CLICK_EVENT_BOX, WidgetsClickEventBox))
#define WIDGETS_CLICK_EVENT_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WIDGETS_TYPE_CLICK_EVENT_BOX, WidgetsClickEventBoxClass))
#define WIDGETS_IS_CLICK_EVENT_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WIDGETS_TYPE_CLICK_EVENT_BOX))
#define WIDGETS_IS_CLICK_EVENT_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WIDGETS_TYPE_CLICK_EVENT_BOX))
#define WIDGETS_CLICK_EVENT_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WIDGETS_TYPE_CLICK_EVENT_BOX, WidgetsClickEventBoxClass))

typedef struct _WidgetsClickEventBox WidgetsClickEventBox;
typedef struct _WidgetsClickEventBoxClass WidgetsClickEventBoxClass;
typedef struct _WidgetsClickEventBoxPrivate WidgetsClickEventBoxPrivate;

#define WIDGETS_TYPE_LINK_BUTTON (widgets_link_button_get_type ())
#define WIDGETS_LINK_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WIDGETS_TYPE_LINK_BUTTON, WidgetsLinkButton))
#define WIDGETS_LINK_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WIDGETS_TYPE_LINK_BUTTON, WidgetsLinkButtonClass))
#define WIDGETS_IS_LINK_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WIDGETS_TYPE_LINK_BUTTON))
#define WIDGETS_IS_LINK_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WIDGETS_TYPE_LINK_BUTTON))
#define WIDGETS_LINK_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WIDGETS_TYPE_LINK_BUTTON, WidgetsLinkButtonClass))

typedef struct _WidgetsLinkButton WidgetsLinkButton;
typedef struct _WidgetsLinkButtonClass WidgetsLinkButtonClass;
typedef struct _WidgetsLinkButtonPrivate WidgetsLinkButtonPrivate;
enum  {
	WIDGETS_LINK_BUTTON_0_PROPERTY,
	WIDGETS_LINK_BUTTON_NUM_PROPERTIES
};
static GParamSpec* widgets_link_button_properties[WIDGETS_LINK_BUTTON_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block15Data Block15Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _WidgetsClickEventBox {
	GtkEventBox parent_instance;
	WidgetsClickEventBoxPrivate * priv;
	gboolean is_press;
};

struct _WidgetsClickEventBoxClass {
	GtkEventBoxClass parent_class;
};

struct _WidgetsLinkButton {
	WidgetsClickEventBox parent_instance;
	WidgetsLinkButtonPrivate * priv;
	gchar* link_css;
	gchar* link_name;
	gchar* link_uri;
};

struct _WidgetsLinkButtonClass {
	WidgetsClickEventBoxClass parent_class;
};

struct _Block15Data {
	int _ref_count_;
	WidgetsLinkButton* self;
	gchar* link_uri;
};

static gpointer widgets_link_button_parent_class = NULL;

VALA_EXTERN GType widgets_click_event_box_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WidgetsClickEventBox, g_object_unref)
VALA_EXTERN GType widgets_link_button_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WidgetsLinkButton, g_object_unref)
VALA_EXTERN WidgetsLinkButton* widgets_link_button_new (const gchar* link_name,
                                            const gchar* link_uri,
                                            const gchar* link_css);
VALA_EXTERN WidgetsLinkButton* widgets_link_button_construct (GType object_type,
                                                  const gchar* link_name,
                                                  const gchar* link_uri,
                                                  const gchar* link_css);
static Block15Data* block15_data_ref (Block15Data* _data15_);
static void block15_data_unref (void * _userdata_);
VALA_EXTERN WidgetsClickEventBox* widgets_click_event_box_new (void);
VALA_EXTERN WidgetsClickEventBox* widgets_click_event_box_construct (GType object_type);
static gboolean __lambda154_ (WidgetsLinkButton* self,
                       GtkWidget* w,
                       GdkEventCrossing* e);
static gboolean ___lambda154__gtk_widget_enter_notify_event (GtkWidget* _sender,
                                                      GdkEventCrossing* event,
                                                      gpointer self);
static gboolean __lambda155_ (WidgetsLinkButton* self,
                       GtkWidget* w,
                       GdkEventCrossing* e);
static gboolean ___lambda155__gtk_widget_leave_notify_event (GtkWidget* _sender,
                                                      GdkEventCrossing* event,
                                                      gpointer self);
static void __lambda156_ (Block15Data* _data15_,
                   WidgetsClickEventBox* w,
                   GdkEventButton* e);
static void ___lambda156__widgets_click_event_box_clicked (WidgetsClickEventBox* _sender,
                                                    GdkEventButton* event,
                                                    gpointer self);
static void widgets_link_button_finalize (GObject * obj);
static GType widgets_link_button_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static Block15Data*
block15_data_ref (Block15Data* _data15_)
{
	g_atomic_int_inc (&_data15_->_ref_count_);
	return _data15_;
}

static void
block15_data_unref (void * _userdata_)
{
	Block15Data* _data15_;
	_data15_ = (Block15Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data15_->_ref_count_)) {
		WidgetsLinkButton* self;
		self = _data15_->self;
		_g_free0 (_data15_->link_uri);
		_g_object_unref0 (self);
		g_slice_free (Block15Data, _data15_);
	}
}

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

static gboolean
__lambda154_ (WidgetsLinkButton* self,
              GtkWidget* w,
              GdkEventCrossing* e)
{
	GdkDisplay* display = NULL;
	GdkDisplay* _tmp0_;
	GdkDisplay* _tmp1_;
	GdkWindow* _tmp2_;
	GdkCursor* _tmp3_;
	GdkCursor* _tmp4_;
	gboolean result;
	g_return_val_if_fail (w != NULL, FALSE);
	g_return_val_if_fail (e != NULL, FALSE);
	_tmp0_ = gdk_display_get_default ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	display = _tmp1_;
	_tmp2_ = gtk_widget_get_window ((GtkWidget*) self);
	_tmp3_ = gdk_cursor_new_for_display (display, GDK_HAND1);
	_tmp4_ = _tmp3_;
	gdk_window_set_cursor (_tmp2_, _tmp4_);
	_g_object_unref0 (_tmp4_);
	result = FALSE;
	_g_object_unref0 (display);
	return result;
}

static gboolean
___lambda154__gtk_widget_enter_notify_event (GtkWidget* _sender,
                                             GdkEventCrossing* event,
                                             gpointer self)
{
	gboolean result;
	result = __lambda154_ ((WidgetsLinkButton*) self, _sender, event);
	return result;
}

static gboolean
__lambda155_ (WidgetsLinkButton* self,
              GtkWidget* w,
              GdkEventCrossing* e)
{
	GdkWindow* _tmp0_;
	gboolean result;
	g_return_val_if_fail (w != NULL, FALSE);
	g_return_val_if_fail (e != NULL, FALSE);
	_tmp0_ = gtk_widget_get_window ((GtkWidget*) self);
	gdk_window_set_cursor (_tmp0_, NULL);
	result = FALSE;
	return result;
}

static gboolean
___lambda155__gtk_widget_leave_notify_event (GtkWidget* _sender,
                                             GdkEventCrossing* event,
                                             gpointer self)
{
	gboolean result;
	result = __lambda155_ ((WidgetsLinkButton*) self, _sender, event);
	return result;
}

static void
__lambda156_ (Block15Data* _data15_,
              WidgetsClickEventBox* w,
              GdkEventButton* e)
{
	WidgetsLinkButton* self;
	GdkScreen* screen = NULL;
	GdkScreen* _tmp0_;
	GdkScreen* _tmp1_;
	GError* _inner_error0_ = NULL;
	self = _data15_->self;
	g_return_if_fail (w != NULL);
	g_return_if_fail (e != NULL);
	_tmp0_ = gdk_screen_get_default ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	screen = _tmp1_;
	{
		gtk_show_uri (screen, _data15_->link_uri, e->time, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp2_;
		const gchar* _tmp3_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp2_ = e;
		_tmp3_ = _tmp2_->message;
		g_print ("LinkButton: %s\n", _tmp3_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (screen);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	_g_object_unref0 (screen);
}

static void
___lambda156__widgets_click_event_box_clicked (WidgetsClickEventBox* _sender,
                                               GdkEventButton* event,
                                               gpointer self)
{
	__lambda156_ (self, _sender, event);
}

WidgetsLinkButton*
widgets_link_button_construct (GType object_type,
                               const gchar* link_name,
                               const gchar* link_uri,
                               const gchar* link_css)
{
	WidgetsLinkButton * self = NULL;
	Block15Data* _data15_;
	gchar* _tmp0_;
	GtkLabel* link_label = NULL;
	GtkLabel* _tmp1_;
	GtkStyleContext* _tmp2_;
	g_return_val_if_fail (link_name != NULL, NULL);
	g_return_val_if_fail (link_uri != NULL, NULL);
	g_return_val_if_fail (link_css != NULL, NULL);
	_data15_ = g_slice_new0 (Block15Data);
	_data15_->_ref_count_ = 1;
	_tmp0_ = g_strdup (link_uri);
	_g_free0 (_data15_->link_uri);
	_data15_->link_uri = _tmp0_;
	self = (WidgetsLinkButton*) widgets_click_event_box_construct (object_type);
	_data15_->self = g_object_ref (self);
	gtk_widget_add_events ((GtkWidget*) self, (gint) (((GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK) | GDK_POINTER_MOTION_MASK) | GDK_LEAVE_NOTIFY_MASK));
	gtk_event_box_set_visible_window ((GtkEventBox*) self, FALSE);
	_tmp1_ = (GtkLabel*) gtk_label_new (NULL);
	g_object_ref_sink (_tmp1_);
	link_label = _tmp1_;
	gtk_label_set_text (link_label, link_name);
	_tmp2_ = gtk_widget_get_style_context ((GtkWidget*) link_label);
	gtk_style_context_add_class (_tmp2_, link_css);
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) link_label);
	g_signal_connect_object ((GtkWidget*) self, "enter-notify-event", (GCallback) ___lambda154__gtk_widget_enter_notify_event, self, 0);
	g_signal_connect_object ((GtkWidget*) self, "leave-notify-event", (GCallback) ___lambda155__gtk_widget_leave_notify_event, self, 0);
	g_signal_connect_data ((WidgetsClickEventBox*) self, "clicked", (GCallback) ___lambda156__widgets_click_event_box_clicked, block15_data_ref (_data15_), (GClosureNotify) block15_data_unref, 0);
	_g_object_unref0 (link_label);
	block15_data_unref (_data15_);
	_data15_ = NULL;
	return self;
}

WidgetsLinkButton*
widgets_link_button_new (const gchar* link_name,
                         const gchar* link_uri,
                         const gchar* link_css)
{
	return widgets_link_button_construct (WIDGETS_TYPE_LINK_BUTTON, link_name, link_uri, link_css);
}

static void
widgets_link_button_class_init (WidgetsLinkButtonClass * klass,
                                gpointer klass_data)
{
	widgets_link_button_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = widgets_link_button_finalize;
}

static void
widgets_link_button_instance_init (WidgetsLinkButton * self,
                                   gpointer klass)
{
}

static void
widgets_link_button_finalize (GObject * obj)
{
	WidgetsLinkButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_LINK_BUTTON, WidgetsLinkButton);
	_g_free0 (self->link_css);
	_g_free0 (self->link_name);
	_g_free0 (self->link_uri);
	G_OBJECT_CLASS (widgets_link_button_parent_class)->finalize (obj);
}

static GType
widgets_link_button_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WidgetsLinkButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) widgets_link_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WidgetsLinkButton), 0, (GInstanceInitFunc) widgets_link_button_instance_init, NULL };
	GType widgets_link_button_type_id;
	widgets_link_button_type_id = g_type_register_static (WIDGETS_TYPE_CLICK_EVENT_BOX, "WidgetsLinkButton", &g_define_type_info, 0);
	return widgets_link_button_type_id;
}

GType
widgets_link_button_get_type (void)
{
	static volatile gsize widgets_link_button_type_id__once = 0;
	if (g_once_init_enter (&widgets_link_button_type_id__once)) {
		GType widgets_link_button_type_id;
		widgets_link_button_type_id = widgets_link_button_get_type_once ();
		g_once_init_leave (&widgets_link_button_type_id__once, widgets_link_button_type_id);
	}
	return widgets_link_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;
}

