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

#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <gee.h>
#include <gdk/gdk.h>
#include <float.h>
#include <math.h>
#include <cairo-gobject.h>
#include <poppler.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 PDFPC_VIEW_BEHAVIOUR_TYPE_BASE (pdfpc_view_behaviour_base_get_type ())
#define PDFPC_VIEW_BEHAVIOUR_BASE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PDFPC_VIEW_BEHAVIOUR_TYPE_BASE, pdfpcViewBehaviourBase))
#define PDFPC_VIEW_BEHAVIOUR_BASE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PDFPC_VIEW_BEHAVIOUR_TYPE_BASE, pdfpcViewBehaviourBaseClass))
#define PDFPC_VIEW_BEHAVIOUR_IS_BASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PDFPC_VIEW_BEHAVIOUR_TYPE_BASE))
#define PDFPC_VIEW_BEHAVIOUR_IS_BASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PDFPC_VIEW_BEHAVIOUR_TYPE_BASE))
#define PDFPC_VIEW_BEHAVIOUR_BASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PDFPC_VIEW_BEHAVIOUR_TYPE_BASE, pdfpcViewBehaviourBaseClass))

typedef struct _pdfpcViewBehaviourBase pdfpcViewBehaviourBase;
typedef struct _pdfpcViewBehaviourBaseClass pdfpcViewBehaviourBaseClass;
typedef struct _pdfpcViewBehaviourBasePrivate pdfpcViewBehaviourBasePrivate;

#define PDFPC_VIEW_TYPE_PDF (pdfpc_view_pdf_get_type ())
#define PDFPC_VIEW_PDF(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PDFPC_VIEW_TYPE_PDF, pdfpcViewPdf))
#define PDFPC_VIEW_PDF_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PDFPC_VIEW_TYPE_PDF, pdfpcViewPdfClass))
#define PDFPC_VIEW_IS_PDF(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PDFPC_VIEW_TYPE_PDF))
#define PDFPC_VIEW_IS_PDF_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PDFPC_VIEW_TYPE_PDF))
#define PDFPC_VIEW_PDF_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PDFPC_VIEW_TYPE_PDF, pdfpcViewPdfClass))

typedef struct _pdfpcViewPdf pdfpcViewPdf;
typedef struct _pdfpcViewPdfClass pdfpcViewPdfClass;

#define PDFPC_VIEW_BEHAVIOUR_TYPE_ASSOCIATION_ERROR (pdfpc_view_behaviour_association_error_get_type ())

#define PDFPC_VIEW_BEHAVIOUR_TYPE_PDF_LINK (pdfpc_view_behaviour_pdf_link_get_type ())
#define PDFPC_VIEW_BEHAVIOUR_PDF_LINK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PDFPC_VIEW_BEHAVIOUR_TYPE_PDF_LINK, pdfpcViewBehaviourPdfLink))
#define PDFPC_VIEW_BEHAVIOUR_PDF_LINK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PDFPC_VIEW_BEHAVIOUR_TYPE_PDF_LINK, pdfpcViewBehaviourPdfLinkClass))
#define PDFPC_VIEW_BEHAVIOUR_IS_PDF_LINK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PDFPC_VIEW_BEHAVIOUR_TYPE_PDF_LINK))
#define PDFPC_VIEW_BEHAVIOUR_IS_PDF_LINK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PDFPC_VIEW_BEHAVIOUR_TYPE_PDF_LINK))
#define PDFPC_VIEW_BEHAVIOUR_PDF_LINK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PDFPC_VIEW_BEHAVIOUR_TYPE_PDF_LINK, pdfpcViewBehaviourPdfLinkClass))

typedef struct _pdfpcViewBehaviourPdfLink pdfpcViewBehaviourPdfLink;
typedef struct _pdfpcViewBehaviourPdfLinkClass pdfpcViewBehaviourPdfLinkClass;
typedef struct _pdfpcViewBehaviourPdfLinkPrivate pdfpcViewBehaviourPdfLinkPrivate;

#define PDFPC_TYPE_ACTION_MAPPING (pdfpc_action_mapping_get_type ())
#define PDFPC_ACTION_MAPPING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PDFPC_TYPE_ACTION_MAPPING, pdfpcActionMapping))
#define PDFPC_ACTION_MAPPING_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PDFPC_TYPE_ACTION_MAPPING, pdfpcActionMappingClass))
#define PDFPC_IS_ACTION_MAPPING(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PDFPC_TYPE_ACTION_MAPPING))
#define PDFPC_IS_ACTION_MAPPING_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PDFPC_TYPE_ACTION_MAPPING))
#define PDFPC_ACTION_MAPPING_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PDFPC_TYPE_ACTION_MAPPING, pdfpcActionMappingClass))

typedef struct _pdfpcActionMapping pdfpcActionMapping;
typedef struct _pdfpcActionMappingClass pdfpcActionMappingClass;
enum  {
	PDFPC_VIEW_BEHAVIOUR_PDF_LINK_0_PROPERTY,
	PDFPC_VIEW_BEHAVIOUR_PDF_LINK_NUM_PROPERTIES
};
static GParamSpec* pdfpc_view_behaviour_pdf_link_properties[PDFPC_VIEW_BEHAVIOUR_PDF_LINK_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block8Data Block8Data;

#define PDFPC_METADATA_TYPE_PDF (pdfpc_metadata_pdf_get_type ())
#define PDFPC_METADATA_PDF(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PDFPC_METADATA_TYPE_PDF, pdfpcMetadataPdf))
#define PDFPC_METADATA_PDF_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PDFPC_METADATA_TYPE_PDF, pdfpcMetadataPdfClass))
#define PDFPC_METADATA_IS_PDF(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PDFPC_METADATA_TYPE_PDF))
#define PDFPC_METADATA_IS_PDF_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PDFPC_METADATA_TYPE_PDF))
#define PDFPC_METADATA_PDF_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PDFPC_METADATA_TYPE_PDF, pdfpcMetadataPdfClass))

typedef struct _pdfpcMetadataPdf pdfpcMetadataPdf;
typedef struct _pdfpcMetadataPdfClass pdfpcMetadataPdfClass;
typedef struct _pdfpcActionMappingPrivate pdfpcActionMappingPrivate;

#define PDFPC_TYPE_PRESENTATION_CONTROLLER (pdfpc_presentation_controller_get_type ())
#define PDFPC_PRESENTATION_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PDFPC_TYPE_PRESENTATION_CONTROLLER, pdfpcPresentationController))
#define PDFPC_PRESENTATION_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PDFPC_TYPE_PRESENTATION_CONTROLLER, pdfpcPresentationControllerClass))
#define PDFPC_IS_PRESENTATION_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PDFPC_TYPE_PRESENTATION_CONTROLLER))
#define PDFPC_IS_PRESENTATION_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PDFPC_TYPE_PRESENTATION_CONTROLLER))
#define PDFPC_PRESENTATION_CONTROLLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PDFPC_TYPE_PRESENTATION_CONTROLLER, pdfpcPresentationControllerClass))

typedef struct _pdfpcPresentationController pdfpcPresentationController;
typedef struct _pdfpcPresentationControllerClass pdfpcPresentationControllerClass;
typedef enum  {
	PDFPC_ACTION_MAPPING_ACTION_TYPE_LINK,
	PDFPC_ACTION_MAPPING_ACTION_TYPE_MOVIE
} pdfpcActionMappingActionType;

#define PDFPC_ACTION_MAPPING_TYPE_ACTION_TYPE (pdfpc_action_mapping_action_type_get_type ())

typedef enum  {
	PDFPC_VIEW_BEHAVIOUR_ASSOCIATION_ERROR_BEHAVIOUR_ALREADY_ASSOCIATED,
	PDFPC_VIEW_BEHAVIOUR_ASSOCIATION_ERROR_VIEW_NOT_SUPPORTED
} pdfpcViewBehaviourAssociationError;
#define PDFPC_VIEW_BEHAVIOUR_ASSOCIATION_ERROR pdfpc_view_behaviour_association_error_quark ()

struct _pdfpcViewBehaviourBase {
	GObject parent_instance;
	pdfpcViewBehaviourBasePrivate * priv;
	pdfpcViewPdf* target;
};

struct _pdfpcViewBehaviourBaseClass {
	GObjectClass parent_class;
	void (*associate) (pdfpcViewBehaviourBase* self, pdfpcViewPdf* target, GError** error);
};

struct _pdfpcViewBehaviourPdfLink {
	pdfpcViewBehaviourBase parent_instance;
	pdfpcViewBehaviourPdfLinkPrivate * priv;
	pdfpcActionMapping* active_mapping;
	GeeList* page_link_mappings;
	GdkRectangle* precalculated_mapping_rectangles;
	gint precalculated_mapping_rectangles_length1;
};

struct _pdfpcViewBehaviourPdfLinkClass {
	pdfpcViewBehaviourBaseClass parent_class;
};

struct _Block8Data {
	int _ref_count_;
	pdfpcViewBehaviourPdfLink* self;
	pdfpcViewPdf* source;
	gint page_number;
};

struct _pdfpcActionMapping {
	GObject parent_instance;
	pdfpcActionMappingPrivate * priv;
	pdfpcActionMappingActionType type;
	PopplerRectangle area;
	pdfpcPresentationController* controller;
};

struct _pdfpcActionMappingClass {
	GObjectClass parent_class;
	void (*init) (pdfpcActionMapping* self, PopplerRectangle* area, pdfpcPresentationController* controller);
	pdfpcActionMapping* (*new_from_link_mapping) (pdfpcActionMapping* self, PopplerLinkMapping* mapping, pdfpcPresentationController* controller);
	pdfpcActionMapping* (*new_from_annot_mapping) (pdfpcActionMapping* self, PopplerAnnotMapping* mapping, pdfpcPresentationController* controller);
	void (*on_mouse_enter) (pdfpcActionMapping* self, GtkWidget* widget, GdkEventMotion* event);
	void (*on_mouse_leave) (pdfpcActionMapping* self, GtkWidget* widget, GdkEventMotion* event);
	gboolean (*on_button_press) (pdfpcActionMapping* self, GtkWidget* widget, GdkEventButton* event);
	gboolean (*on_button_release) (pdfpcActionMapping* self, GtkWidget* widget, GdkEventButton* event);
	gboolean (*on_mouse_move) (pdfpcActionMapping* self, GtkWidget* widget, GdkEventMotion* event);
	gboolean (*is_sensitive) (pdfpcActionMapping* self);
	void (*on_freeze) (pdfpcActionMapping* self, gboolean frozen);
	void (*deactivate) (pdfpcActionMapping* self);
};

static gpointer pdfpc_view_behaviour_pdf_link_parent_class = NULL;

VALA_EXTERN GType pdfpc_view_behaviour_base_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (pdfpcViewBehaviourBase, g_object_unref)
VALA_EXTERN GType pdfpc_view_pdf_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (pdfpcViewPdf, g_object_unref)
VALA_EXTERN GQuark pdfpc_view_behaviour_association_error_quark (void);
VALA_EXTERN GType pdfpc_view_behaviour_association_error_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType pdfpc_view_behaviour_pdf_link_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (pdfpcViewBehaviourPdfLink, g_object_unref)
VALA_EXTERN GType pdfpc_action_mapping_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (pdfpcActionMapping, g_object_unref)
VALA_EXTERN void pdfpc_view_behaviour_base_associate (pdfpcViewBehaviourBase* self,
                                          pdfpcViewPdf* target,
                                          GError** error);
static void pdfpc_view_behaviour_pdf_link_real_associate (pdfpcViewBehaviourBase* base,
                                                   pdfpcViewPdf* target,
                                                   GError** error);
VALA_EXTERN void pdfpc_view_behaviour_base_enforce_exclusive_association (pdfpcViewBehaviourBase* self,
                                                              pdfpcViewPdf* target,
                                                              GError** error);
VALA_EXTERN void pdfpc_view_behaviour_pdf_link_attach (pdfpcViewBehaviourPdfLink* self,
                                           pdfpcViewPdf* view);
VALA_EXTERN gboolean pdfpc_view_behaviour_pdf_link_on_button_press (pdfpcViewBehaviourPdfLink* self,
                                                        GtkWidget* source,
                                                        GdkEventButton* e);
static gboolean _pdfpc_view_behaviour_pdf_link_on_button_press_gtk_widget_button_press_event (GtkWidget* _sender,
                                                                                       GdkEventButton* event,
                                                                                       gpointer self);
VALA_EXTERN gboolean pdfpc_view_behaviour_pdf_link_on_button_release (pdfpcViewBehaviourPdfLink* self,
                                                          GtkWidget* source,
                                                          GdkEventButton* e);
static gboolean _pdfpc_view_behaviour_pdf_link_on_button_release_gtk_widget_button_release_event (GtkWidget* _sender,
                                                                                           GdkEventButton* event,
                                                                                           gpointer self);
VALA_EXTERN gboolean pdfpc_view_behaviour_pdf_link_on_mouse_move (pdfpcViewBehaviourPdfLink* self,
                                                      GtkWidget* source,
                                                      GdkEventMotion* event);
static gboolean _pdfpc_view_behaviour_pdf_link_on_mouse_move_gtk_widget_motion_notify_event (GtkWidget* _sender,
                                                                                      GdkEventMotion* event,
                                                                                      gpointer self);
VALA_EXTERN void pdfpc_view_behaviour_pdf_link_on_entering_slide (pdfpcViewBehaviourPdfLink* self,
                                                      pdfpcViewPdf* source,
                                                      gint page_number);
static void _pdfpc_view_behaviour_pdf_link_on_entering_slide_pdfpc_view_pdf_entering_slide (pdfpcViewPdf* _sender,
                                                                                     gint slide_number,
                                                                                     gpointer self);
VALA_EXTERN void pdfpc_view_behaviour_pdf_link_on_leaving_slide (pdfpcViewBehaviourPdfLink* self,
                                                     pdfpcViewPdf* source,
                                                     gint from,
                                                     gint to);
static void _pdfpc_view_behaviour_pdf_link_on_leaving_slide_pdfpc_view_pdf_leaving_slide (pdfpcViewPdf* _sender,
                                                                                   gint from,
                                                                                   gint to,
                                                                                   gpointer self);
VALA_EXTERN void pdfpc_view_behaviour_pdf_link_on_freeze_toggle (pdfpcViewBehaviourPdfLink* self,
                                                     pdfpcViewPdf* source,
                                                     gboolean frozen);
static void _pdfpc_view_behaviour_pdf_link_on_freeze_toggle_pdfpc_view_pdf_freeze_toggled (pdfpcViewPdf* _sender,
                                                                                    gboolean frozen,
                                                                                    gpointer self);
VALA_EXTERN pdfpcActionMapping* pdfpc_view_behaviour_pdf_link_get_link_mapping_by_coordinates (pdfpcViewBehaviourPdfLink* self,
                                                                                   gdouble x,
                                                                                   gdouble y);
VALA_EXTERN gboolean pdfpc_action_mapping_is_sensitive (pdfpcActionMapping* self);
VALA_EXTERN gboolean pdfpc_action_mapping_on_button_press (pdfpcActionMapping* self,
                                               GtkWidget* widget,
                                               GdkEventButton* event);
VALA_EXTERN gboolean pdfpc_action_mapping_on_button_release (pdfpcActionMapping* self,
                                                 GtkWidget* widget,
                                                 GdkEventButton* event);
VALA_EXTERN void pdfpc_action_mapping_on_mouse_leave (pdfpcActionMapping* self,
                                          GtkWidget* widget,
                                          GdkEventMotion* event);
VALA_EXTERN void pdfpc_action_mapping_on_mouse_enter (pdfpcActionMapping* self,
                                          GtkWidget* widget,
                                          GdkEventMotion* event);
VALA_EXTERN gboolean pdfpc_action_mapping_on_mouse_move (pdfpcActionMapping* self,
                                             GtkWidget* widget,
                                             GdkEventMotion* event);
static Block8Data* block8_data_ref (Block8Data* _data8_);
static void block8_data_unref (void * _userdata_);
static void ___lambda12_ (Block8Data* _data8_);
static void ____lambda12__gtk_widget_realize (GtkWidget* _sender,
                                       gpointer self);
VALA_EXTERN GType pdfpc_metadata_pdf_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (pdfpcMetadataPdf, g_object_unref)
VALA_EXTERN pdfpcMetadataPdf* pdfpc_view_pdf_get_metadata (pdfpcViewPdf* self);
VALA_EXTERN guint pdfpc_metadata_pdf_get_slide_count (pdfpcMetadataPdf* self);
VALA_EXTERN GeeList* pdfpc_metadata_pdf_get_action_mapping (pdfpcMetadataPdf* self,
                                                gint page_num);
VALA_EXTERN void pdfpc_view_pdf_convert_poppler_rectangle_to_gdk_rectangle (pdfpcViewPdf* self,
                                                                PopplerRectangle* poppler_rectangle,
                                                                GdkRectangle* result);
VALA_EXTERN GType pdfpc_presentation_controller_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (pdfpcPresentationController, g_object_unref)
VALA_EXTERN GType pdfpc_action_mapping_action_type_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void pdfpc_action_mapping_on_freeze (pdfpcActionMapping* self,
                                     gboolean frozen);
VALA_EXTERN pdfpcViewBehaviourPdfLink* pdfpc_view_behaviour_pdf_link_new (void);
VALA_EXTERN pdfpcViewBehaviourPdfLink* pdfpc_view_behaviour_pdf_link_construct (GType object_type);
VALA_EXTERN pdfpcViewBehaviourBase* pdfpc_view_behaviour_base_construct (GType object_type);
static void pdfpc_view_behaviour_pdf_link_finalize (GObject * obj);
static GType pdfpc_view_behaviour_pdf_link_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static void
pdfpc_view_behaviour_pdf_link_real_associate (pdfpcViewBehaviourBase* base,
                                              pdfpcViewPdf* target,
                                              GError** error)
{
	pdfpcViewBehaviourPdfLink * self;
	GError* _inner_error0_ = NULL;
	self = (pdfpcViewBehaviourPdfLink*) base;
	g_return_if_fail (target != NULL);
	pdfpc_view_behaviour_base_enforce_exclusive_association ((pdfpcViewBehaviourBase*) self, target, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == PDFPC_VIEW_BEHAVIOUR_ASSOCIATION_ERROR) {
			g_propagate_error (error, _inner_error0_);
			return;
		} else {
			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;
		}
	}
	pdfpc_view_behaviour_pdf_link_attach (self, target);
}

/**
         * Attach a View.Pdf to this signal provider
         */
static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static gboolean
_pdfpc_view_behaviour_pdf_link_on_button_press_gtk_widget_button_press_event (GtkWidget* _sender,
                                                                              GdkEventButton* event,
                                                                              gpointer self)
{
	gboolean result;
	result = pdfpc_view_behaviour_pdf_link_on_button_press ((pdfpcViewBehaviourPdfLink*) self, _sender, event);
	return result;
}

static gboolean
_pdfpc_view_behaviour_pdf_link_on_button_release_gtk_widget_button_release_event (GtkWidget* _sender,
                                                                                  GdkEventButton* event,
                                                                                  gpointer self)
{
	gboolean result;
	result = pdfpc_view_behaviour_pdf_link_on_button_release ((pdfpcViewBehaviourPdfLink*) self, _sender, event);
	return result;
}

static gboolean
_pdfpc_view_behaviour_pdf_link_on_mouse_move_gtk_widget_motion_notify_event (GtkWidget* _sender,
                                                                             GdkEventMotion* event,
                                                                             gpointer self)
{
	gboolean result;
	result = pdfpc_view_behaviour_pdf_link_on_mouse_move ((pdfpcViewBehaviourPdfLink*) self, _sender, event);
	return result;
}

static void
_pdfpc_view_behaviour_pdf_link_on_entering_slide_pdfpc_view_pdf_entering_slide (pdfpcViewPdf* _sender,
                                                                                gint slide_number,
                                                                                gpointer self)
{
	pdfpc_view_behaviour_pdf_link_on_entering_slide ((pdfpcViewBehaviourPdfLink*) self, _sender, slide_number);
}

static void
_pdfpc_view_behaviour_pdf_link_on_leaving_slide_pdfpc_view_pdf_leaving_slide (pdfpcViewPdf* _sender,
                                                                              gint from,
                                                                              gint to,
                                                                              gpointer self)
{
	pdfpc_view_behaviour_pdf_link_on_leaving_slide ((pdfpcViewBehaviourPdfLink*) self, _sender, from, to);
}

static void
_pdfpc_view_behaviour_pdf_link_on_freeze_toggle_pdfpc_view_pdf_freeze_toggled (pdfpcViewPdf* _sender,
                                                                               gboolean frozen,
                                                                               gpointer self)
{
	pdfpc_view_behaviour_pdf_link_on_freeze_toggle ((pdfpcViewBehaviourPdfLink*) self, _sender, frozen);
}

void
pdfpc_view_behaviour_pdf_link_attach (pdfpcViewBehaviourPdfLink* self,
                                      pdfpcViewPdf* view)
{
	pdfpcViewPdf* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (view != NULL);
	_tmp0_ = _g_object_ref0 (view);
	_g_object_unref0 (((pdfpcViewBehaviourBase*) self)->target);
	((pdfpcViewBehaviourBase*) self)->target = _tmp0_;
	gtk_widget_add_events ((GtkWidget*) view, (gint) GDK_BUTTON_PRESS_MASK);
	gtk_widget_add_events ((GtkWidget*) view, (gint) GDK_BUTTON_RELEASE_MASK);
	gtk_widget_add_events ((GtkWidget*) view, (gint) GDK_POINTER_MOTION_MASK);
	g_signal_connect_object ((GtkWidget*) view, "button-press-event", (GCallback) _pdfpc_view_behaviour_pdf_link_on_button_press_gtk_widget_button_press_event, self, 0);
	g_signal_connect_object ((GtkWidget*) view, "button-release-event", (GCallback) _pdfpc_view_behaviour_pdf_link_on_button_release_gtk_widget_button_release_event, self, 0);
	g_signal_connect_object ((GtkWidget*) view, "motion-notify-event", (GCallback) _pdfpc_view_behaviour_pdf_link_on_mouse_move_gtk_widget_motion_notify_event, self, 0);
	g_signal_connect_object (view, "entering-slide", (GCallback) _pdfpc_view_behaviour_pdf_link_on_entering_slide_pdfpc_view_pdf_entering_slide, self, 0);
	g_signal_connect_object (view, "leaving-slide", (GCallback) _pdfpc_view_behaviour_pdf_link_on_leaving_slide_pdfpc_view_pdf_leaving_slide, self, 0);
	g_signal_connect_object (view, "freeze-toggled", (GCallback) _pdfpc_view_behaviour_pdf_link_on_freeze_toggle_pdfpc_view_pdf_freeze_toggled, self, 0);
}

/**
         * Return the Poppler.LinkMapping associated with link for the given
         * coordinates.
         *
         * If there is no link for the given coordinates null is returned
         * instead.
         */
pdfpcActionMapping*
pdfpc_view_behaviour_pdf_link_get_link_mapping_by_coordinates (pdfpcViewBehaviourPdfLink* self,
                                                               gdouble x,
                                                               gdouble y)
{
	pdfpcActionMapping* result;
	g_return_val_if_fail (self != NULL, NULL);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				GdkRectangle* _tmp2_;
				gint _tmp2__length1;
				GdkRectangle r = {0};
				GdkRectangle* _tmp3_;
				gint _tmp3__length1;
				GdkRectangle _tmp4_;
				gboolean _tmp5_ = FALSE;
				gboolean _tmp6_ = FALSE;
				gboolean _tmp7_ = FALSE;
				GdkRectangle _tmp8_;
				if (!_tmp0_) {
					gint _tmp1_;
					i = i + 1;
					_tmp1_ = i;
				}
				_tmp0_ = FALSE;
				_tmp2_ = self->precalculated_mapping_rectangles;
				_tmp2__length1 = self->precalculated_mapping_rectangles_length1;
				if (!(i < _tmp2__length1)) {
					break;
				}
				_tmp3_ = self->precalculated_mapping_rectangles;
				_tmp3__length1 = self->precalculated_mapping_rectangles_length1;
				_tmp4_ = _tmp3_[i];
				r = _tmp4_;
				_tmp8_ = r;
				if (x >= ((gdouble) _tmp8_.x)) {
					GdkRectangle _tmp9_;
					GdkRectangle _tmp10_;
					_tmp9_ = r;
					_tmp10_ = r;
					_tmp7_ = x <= ((gdouble) (_tmp9_.x + _tmp10_.width));
				} else {
					_tmp7_ = FALSE;
				}
				if (_tmp7_) {
					GdkRectangle _tmp11_;
					_tmp11_ = r;
					_tmp6_ = y >= ((gdouble) _tmp11_.y);
				} else {
					_tmp6_ = FALSE;
				}
				if (_tmp6_) {
					GdkRectangle _tmp12_;
					GdkRectangle _tmp13_;
					_tmp12_ = r;
					_tmp13_ = r;
					_tmp5_ = y <= ((gdouble) (_tmp12_.y + _tmp13_.height));
				} else {
					_tmp5_ = FALSE;
				}
				if (_tmp5_) {
					GeeList* _tmp14_;
					gpointer _tmp15_;
					_tmp14_ = self->page_link_mappings;
					_tmp15_ = gee_list_get (_tmp14_, i);
					result = (pdfpcActionMapping*) _tmp15_;
					return result;
				}
			}
		}
	}
	result = NULL;
	return result;
}

/**
         * Called whenever a mouse button is pressed inside the View.Pdf
         *
         * Maybe a link has been clicked. Therefore we need to handle this.
         */
gboolean
pdfpc_view_behaviour_pdf_link_on_button_press (pdfpcViewBehaviourPdfLink* self,
                                               GtkWidget* source,
                                               GdkEventButton* e)
{
	pdfpcActionMapping* mapping = NULL;
	pdfpcActionMapping* _tmp0_;
	gboolean _tmp1_ = FALSE;
	pdfpcActionMapping* _tmp2_;
	pdfpcActionMapping* _tmp4_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (source != NULL, FALSE);
	g_return_val_if_fail (e != NULL, FALSE);
	_tmp0_ = pdfpc_view_behaviour_pdf_link_get_link_mapping_by_coordinates (self, e->x, e->y);
	mapping = _tmp0_;
	_tmp2_ = mapping;
	if (_tmp2_ == NULL) {
		_tmp1_ = TRUE;
	} else {
		pdfpcActionMapping* _tmp3_;
		_tmp3_ = mapping;
		_tmp1_ = !pdfpc_action_mapping_is_sensitive (_tmp3_);
	}
	if (_tmp1_) {
		result = FALSE;
		_g_object_unref0 (mapping);
		return result;
	}
	_tmp4_ = mapping;
	result = pdfpc_action_mapping_on_button_press (_tmp4_, source, e);
	_g_object_unref0 (mapping);
	return result;
}

/**
         * Similarly, for button release events
         */
gboolean
pdfpc_view_behaviour_pdf_link_on_button_release (pdfpcViewBehaviourPdfLink* self,
                                                 GtkWidget* source,
                                                 GdkEventButton* e)
{
	pdfpcActionMapping* mapping = NULL;
	pdfpcActionMapping* _tmp0_;
	gboolean _tmp1_ = FALSE;
	pdfpcActionMapping* _tmp2_;
	pdfpcActionMapping* _tmp4_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (source != NULL, FALSE);
	g_return_val_if_fail (e != NULL, FALSE);
	_tmp0_ = pdfpc_view_behaviour_pdf_link_get_link_mapping_by_coordinates (self, e->x, e->y);
	mapping = _tmp0_;
	_tmp2_ = mapping;
	if (_tmp2_ == NULL) {
		_tmp1_ = TRUE;
	} else {
		pdfpcActionMapping* _tmp3_;
		_tmp3_ = mapping;
		_tmp1_ = !pdfpc_action_mapping_is_sensitive (_tmp3_);
	}
	if (_tmp1_) {
		result = FALSE;
		_g_object_unref0 (mapping);
		return result;
	}
	_tmp4_ = mapping;
	result = pdfpc_action_mapping_on_button_release (_tmp4_, source, e);
	_g_object_unref0 (mapping);
	return result;
}

/**
         * Called whenever the mouse is moved on the surface of the View.Pdf
         *
         * The signal emitted by this method may for example be used to change
         * the mouse cursor if the pointer enters or leaves a link
         */
gboolean
pdfpc_view_behaviour_pdf_link_on_mouse_move (pdfpcViewBehaviourPdfLink* self,
                                             GtkWidget* source,
                                             GdkEventMotion* event)
{
	pdfpcActionMapping* link_mapping = NULL;
	pdfpcActionMapping* _tmp0_;
	pdfpcActionMapping* _tmp1_;
	pdfpcActionMapping* _tmp2_;
	pdfpcActionMapping* _tmp10_;
	pdfpcActionMapping* _tmp11_;
	gboolean _tmp12_ = FALSE;
	pdfpcActionMapping* _tmp13_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (source != NULL, FALSE);
	g_return_val_if_fail (event != NULL, FALSE);
	_tmp0_ = pdfpc_view_behaviour_pdf_link_get_link_mapping_by_coordinates (self, event->x, event->y);
	link_mapping = _tmp0_;
	_tmp1_ = link_mapping;
	_tmp2_ = self->active_mapping;
	if (_tmp1_ != _tmp2_) {
		pdfpcActionMapping* _tmp3_;
		gboolean _tmp6_ = FALSE;
		pdfpcActionMapping* _tmp7_;
		_tmp3_ = self->active_mapping;
		if (_tmp3_ != NULL) {
			GdkWindow* _tmp4_;
			pdfpcActionMapping* _tmp5_;
			_tmp4_ = event->window;
			gdk_window_set_cursor (_tmp4_, NULL);
			_tmp5_ = self->active_mapping;
			pdfpc_action_mapping_on_mouse_leave (_tmp5_, source, event);
		}
		_tmp7_ = link_mapping;
		if (_tmp7_ != NULL) {
			pdfpcActionMapping* _tmp8_;
			_tmp8_ = link_mapping;
			_tmp6_ = pdfpc_action_mapping_is_sensitive (_tmp8_);
		} else {
			_tmp6_ = FALSE;
		}
		if (_tmp6_) {
			pdfpcActionMapping* _tmp9_;
			_tmp9_ = link_mapping;
			pdfpc_action_mapping_on_mouse_enter (_tmp9_, source, event);
		}
	}
	_tmp10_ = link_mapping;
	_tmp11_ = _g_object_ref0 (_tmp10_);
	_g_object_unref0 (self->active_mapping);
	self->active_mapping = _tmp11_;
	_tmp13_ = link_mapping;
	if (_tmp13_ != NULL) {
		pdfpcActionMapping* _tmp14_;
		_tmp14_ = link_mapping;
		_tmp12_ = pdfpc_action_mapping_is_sensitive (_tmp14_);
	} else {
		_tmp12_ = FALSE;
	}
	if (_tmp12_) {
		pdfpcActionMapping* _tmp15_;
		_tmp15_ = link_mapping;
		result = pdfpc_action_mapping_on_mouse_move (_tmp15_, source, event);
		_g_object_unref0 (link_mapping);
		return result;
	} else {
		result = FALSE;
		_g_object_unref0 (link_mapping);
		return result;
	}
}

/**
         * Handle newly entered pdf pages to create a link mapping table for
         * further requests and checks.
         */
static Block8Data*
block8_data_ref (Block8Data* _data8_)
{
	g_atomic_int_inc (&_data8_->_ref_count_);
	return _data8_;
}

static void
block8_data_unref (void * _userdata_)
{
	Block8Data* _data8_;
	_data8_ = (Block8Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data8_->_ref_count_)) {
		pdfpcViewBehaviourPdfLink* self;
		self = _data8_->self;
		_g_object_unref0 (_data8_->source);
		_g_object_unref0 (self);
		g_slice_free (Block8Data, _data8_);
	}
}

static void
___lambda12_ (Block8Data* _data8_)
{
	pdfpcViewBehaviourPdfLink* self;
	self = _data8_->self;
	pdfpc_view_behaviour_pdf_link_on_entering_slide (self, _data8_->source, _data8_->page_number);
}

static void
____lambda12__gtk_widget_realize (GtkWidget* _sender,
                                  gpointer self)
{
	___lambda12_ (self);
}

void
pdfpc_view_behaviour_pdf_link_on_entering_slide (pdfpcViewBehaviourPdfLink* self,
                                                 pdfpcViewPdf* source,
                                                 gint page_number)
{
	Block8Data* _data8_;
	pdfpcViewPdf* _tmp0_;
	pdfpcViewPdf* _tmp1_;
	gboolean in_range = FALSE;
	pdfpcMetadataPdf* metadata = NULL;
	pdfpcMetadataPdf* _tmp3_;
	pdfpcMetadataPdf* _tmp4_;
	GeeList* _tmp7_;
	gint _tmp8_;
	gint _tmp9_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (source != NULL);
	_data8_ = g_slice_new0 (Block8Data);
	_data8_->_ref_count_ = 1;
	_data8_->self = g_object_ref (self);
	_tmp0_ = _g_object_ref0 (source);
	_g_object_unref0 (_data8_->source);
	_data8_->source = _tmp0_;
	_data8_->page_number = page_number;
	_tmp1_ = ((pdfpcViewBehaviourBase*) self)->target;
	if (!gtk_widget_get_mapped ((GtkWidget*) _tmp1_)) {
		pdfpcViewPdf* _tmp2_;
		_tmp2_ = ((pdfpcViewBehaviourBase*) self)->target;
		g_signal_connect_data ((GtkWidget*) _tmp2_, "realize", (GCallback) ____lambda12__gtk_widget_realize, block8_data_ref (_data8_), (GClosureNotify) block8_data_unref, 0);
	}
	in_range = TRUE;
	_tmp3_ = pdfpc_view_pdf_get_metadata (_data8_->source);
	metadata = _tmp3_;
	_tmp4_ = metadata;
	if (((guint) _data8_->page_number) < pdfpc_metadata_pdf_get_slide_count (_tmp4_)) {
		pdfpcMetadataPdf* _tmp5_;
		GeeList* _tmp6_;
		_tmp5_ = metadata;
		_tmp6_ = pdfpc_metadata_pdf_get_action_mapping (_tmp5_, _data8_->page_number);
		self->page_link_mappings = _tmp6_;
	} else {
		self->page_link_mappings = NULL;
		in_range = FALSE;
	}
	if (!in_range) {
		_g_object_unref0 (metadata);
		block8_data_unref (_data8_);
		_data8_ = NULL;
		return;
	}
	_tmp7_ = self->page_link_mappings;
	_tmp8_ = gee_collection_get_size ((GeeCollection*) _tmp7_);
	_tmp9_ = _tmp8_;
	if (_tmp9_ > 0) {
		GeeList* _tmp10_;
		gint _tmp11_;
		gint _tmp12_;
		GdkRectangle* _tmp13_;
		gint i = 0;
		_tmp10_ = self->page_link_mappings;
		_tmp11_ = gee_collection_get_size ((GeeCollection*) _tmp10_);
		_tmp12_ = _tmp11_;
		_tmp13_ = g_new0 (GdkRectangle, _tmp12_);
		self->precalculated_mapping_rectangles = (g_free (self->precalculated_mapping_rectangles), NULL);
		self->precalculated_mapping_rectangles = _tmp13_;
		self->precalculated_mapping_rectangles_length1 = _tmp12_;
		i = 0;
		{
			GeeList* _mapping_list = NULL;
			GeeList* _tmp14_;
			gint _mapping_size = 0;
			GeeList* _tmp15_;
			gint _tmp16_;
			gint _tmp17_;
			gint _mapping_index = 0;
			_tmp14_ = self->page_link_mappings;
			_mapping_list = _tmp14_;
			_tmp15_ = _mapping_list;
			_tmp16_ = gee_collection_get_size ((GeeCollection*) _tmp15_);
			_tmp17_ = _tmp16_;
			_mapping_size = _tmp17_;
			_mapping_index = -1;
			while (TRUE) {
				gint _tmp18_;
				gint _tmp19_;
				pdfpcActionMapping* mapping = NULL;
				GeeList* _tmp20_;
				gpointer _tmp21_;
				GdkRectangle* _tmp22_;
				gint _tmp22__length1;
				gint _tmp23_;
				pdfpcViewPdf* _tmp24_;
				pdfpcActionMapping* _tmp25_;
				PopplerRectangle _tmp26_;
				GdkRectangle _tmp27_ = {0};
				_mapping_index = _mapping_index + 1;
				_tmp18_ = _mapping_index;
				_tmp19_ = _mapping_size;
				if (!(_tmp18_ < _tmp19_)) {
					break;
				}
				_tmp20_ = _mapping_list;
				_tmp21_ = gee_list_get (_tmp20_, _mapping_index);
				mapping = (pdfpcActionMapping*) _tmp21_;
				_tmp22_ = self->precalculated_mapping_rectangles;
				_tmp22__length1 = self->precalculated_mapping_rectangles_length1;
				_tmp23_ = i;
				i = _tmp23_ + 1;
				_tmp24_ = ((pdfpcViewBehaviourBase*) self)->target;
				_tmp25_ = mapping;
				_tmp26_ = _tmp25_->area;
				pdfpc_view_pdf_convert_poppler_rectangle_to_gdk_rectangle (_tmp24_, &_tmp26_, &_tmp27_);
				_tmp22_[_tmp23_] = _tmp27_;
				_g_object_unref0 (mapping);
			}
		}
	}
	_g_object_unref0 (metadata);
	block8_data_unref (_data8_);
	_data8_ = NULL;
}

/**
         * Free the allocated link mapping tables, which were created on page
         * entering
         */
void
pdfpc_view_behaviour_pdf_link_on_leaving_slide (pdfpcViewBehaviourPdfLink* self,
                                                pdfpcViewPdf* source,
                                                gint from,
                                                gint to)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (source != NULL);
	self->precalculated_mapping_rectangles = (g_free (self->precalculated_mapping_rectangles), NULL);
	self->precalculated_mapping_rectangles = NULL;
	self->precalculated_mapping_rectangles_length1 = 0;
}

/**
         * Update the mappings on freeze toggle
         */
void
pdfpc_view_behaviour_pdf_link_on_freeze_toggle (pdfpcViewBehaviourPdfLink* self,
                                                pdfpcViewPdf* source,
                                                gboolean frozen)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (source != NULL);
	{
		GeeList* _mapping_list = NULL;
		GeeList* _tmp0_;
		gint _mapping_size = 0;
		GeeList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _mapping_index = 0;
		_tmp0_ = self->page_link_mappings;
		_mapping_list = _tmp0_;
		_tmp1_ = _mapping_list;
		_tmp2_ = gee_collection_get_size ((GeeCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_mapping_size = _tmp3_;
		_mapping_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			pdfpcActionMapping* mapping = NULL;
			GeeList* _tmp6_;
			gpointer _tmp7_;
			pdfpcActionMapping* _tmp8_;
			_mapping_index = _mapping_index + 1;
			_tmp4_ = _mapping_index;
			_tmp5_ = _mapping_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _mapping_list;
			_tmp7_ = gee_list_get (_tmp6_, _mapping_index);
			mapping = (pdfpcActionMapping*) _tmp7_;
			_tmp8_ = mapping;
			pdfpc_action_mapping_on_freeze (_tmp8_, frozen);
			_g_object_unref0 (mapping);
		}
	}
}

pdfpcViewBehaviourPdfLink*
pdfpc_view_behaviour_pdf_link_construct (GType object_type)
{
	pdfpcViewBehaviourPdfLink * self = NULL;
	self = (pdfpcViewBehaviourPdfLink*) pdfpc_view_behaviour_base_construct (object_type);
	return self;
}

pdfpcViewBehaviourPdfLink*
pdfpc_view_behaviour_pdf_link_new (void)
{
	return pdfpc_view_behaviour_pdf_link_construct (PDFPC_VIEW_BEHAVIOUR_TYPE_PDF_LINK);
}

static void
pdfpc_view_behaviour_pdf_link_class_init (pdfpcViewBehaviourPdfLinkClass * klass,
                                          gpointer klass_data)
{
	pdfpc_view_behaviour_pdf_link_parent_class = g_type_class_peek_parent (klass);
	((pdfpcViewBehaviourBaseClass *) klass)->associate = (void (*) (pdfpcViewBehaviourBase*, pdfpcViewPdf*, GError**)) pdfpc_view_behaviour_pdf_link_real_associate;
	G_OBJECT_CLASS (klass)->finalize = pdfpc_view_behaviour_pdf_link_finalize;
}

static void
pdfpc_view_behaviour_pdf_link_instance_init (pdfpcViewBehaviourPdfLink * self,
                                             gpointer klass)
{
	self->active_mapping = NULL;
	self->page_link_mappings = NULL;
	self->precalculated_mapping_rectangles = NULL;
	self->precalculated_mapping_rectangles_length1 = 0;
}

static void
pdfpc_view_behaviour_pdf_link_finalize (GObject * obj)
{
	pdfpcViewBehaviourPdfLink * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PDFPC_VIEW_BEHAVIOUR_TYPE_PDF_LINK, pdfpcViewBehaviourPdfLink);
	_g_object_unref0 (self->active_mapping);
	self->precalculated_mapping_rectangles = (g_free (self->precalculated_mapping_rectangles), NULL);
	G_OBJECT_CLASS (pdfpc_view_behaviour_pdf_link_parent_class)->finalize (obj);
}

/**
     * Access provider to all signals related to PDF links.
     */
static GType
pdfpc_view_behaviour_pdf_link_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (pdfpcViewBehaviourPdfLinkClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) pdfpc_view_behaviour_pdf_link_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (pdfpcViewBehaviourPdfLink), 0, (GInstanceInitFunc) pdfpc_view_behaviour_pdf_link_instance_init, NULL };
	GType pdfpc_view_behaviour_pdf_link_type_id;
	pdfpc_view_behaviour_pdf_link_type_id = g_type_register_static (PDFPC_VIEW_BEHAVIOUR_TYPE_BASE, "pdfpcViewBehaviourPdfLink", &g_define_type_info, 0);
	return pdfpc_view_behaviour_pdf_link_type_id;
}

GType
pdfpc_view_behaviour_pdf_link_get_type (void)
{
	static volatile gsize pdfpc_view_behaviour_pdf_link_type_id__once = 0;
	if (g_once_init_enter (&pdfpc_view_behaviour_pdf_link_type_id__once)) {
		GType pdfpc_view_behaviour_pdf_link_type_id;
		pdfpc_view_behaviour_pdf_link_type_id = pdfpc_view_behaviour_pdf_link_get_type_once ();
		g_once_init_leave (&pdfpc_view_behaviour_pdf_link_type_id__once, pdfpc_view_behaviour_pdf_link_type_id);
	}
	return pdfpc_view_behaviour_pdf_link_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;
}

