/* gitg-popup-menu.c generated by valac 0.56.19, the Vala compiler
 * generated from gitg-popup-menu.vala, do not modify */

/*
 * This file is part of gitg
 *
 * Copyright (C) 2014 - Jesse van den Kieboom
 *
 * gitg 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 2 of the License, or
 * (at your option) any later version.
 *
 * gitg 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 gitg. If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib.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 GITG_TYPE_POPUP_MENU (gitg_popup_menu_get_type ())
#define GITG_POPUP_MENU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GITG_TYPE_POPUP_MENU, GitgPopupMenu))
#define GITG_POPUP_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GITG_TYPE_POPUP_MENU, GitgPopupMenuClass))
#define GITG_IS_POPUP_MENU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GITG_TYPE_POPUP_MENU))
#define GITG_IS_POPUP_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GITG_TYPE_POPUP_MENU))
#define GITG_POPUP_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GITG_TYPE_POPUP_MENU, GitgPopupMenuClass))

typedef struct _GitgPopupMenu GitgPopupMenu;
typedef struct _GitgPopupMenuClass GitgPopupMenuClass;
typedef struct _GitgPopupMenuPrivate GitgPopupMenuPrivate;
enum  {
	GITG_POPUP_MENU_0_PROPERTY,
	GITG_POPUP_MENU_NUM_PROPERTIES
};
static GParamSpec* gitg_popup_menu_properties[GITG_POPUP_MENU_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define __vala_GdkRectangle_free0(var) ((var == NULL) ? NULL : (var = (_vala_GdkRectangle_free (var), NULL)))
enum  {
	GITG_POPUP_MENU_POPULATE_MENU_SIGNAL,
	GITG_POPUP_MENU_REQUEST_MENU_POSITION_SIGNAL,
	GITG_POPUP_MENU_NUM_SIGNALS
};
static guint gitg_popup_menu_signals[GITG_POPUP_MENU_NUM_SIGNALS] = {0};

struct _GitgPopupMenu {
	GObject parent_instance;
	GitgPopupMenuPrivate * priv;
};

struct _GitgPopupMenuClass {
	GObjectClass parent_class;
};

struct _GitgPopupMenuPrivate {
	GtkWidget* d_widget;
};

static gint GitgPopupMenu_private_offset;
static gpointer gitg_popup_menu_parent_class = NULL;

VALA_EXTERN GType gitg_popup_menu_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GitgPopupMenu, g_object_unref)
VALA_EXTERN GitgPopupMenu* gitg_popup_menu_new (GtkWidget* widget);
VALA_EXTERN GitgPopupMenu* gitg_popup_menu_construct (GType object_type,
                                          GtkWidget* widget);
static gboolean gitg_popup_menu_on_button_press_event (GitgPopupMenu* self,
                                                GtkWidget* widget,
                                                GdkEventButton* event);
static gboolean _gitg_popup_menu_on_button_press_event_gtk_widget_button_press_event (GtkWidget* _sender,
                                                                               GdkEventButton* event,
                                                                               gpointer self);
static gboolean gitg_popup_menu_on_popup_menu (GitgPopupMenu* self,
                                        GtkWidget* widget);
static gboolean _gitg_popup_menu_on_popup_menu_gtk_widget_popup_menu (GtkWidget* _sender,
                                                               gpointer self);
static void gitg_popup_menu_real_dispose (GObject* base);
static gboolean gitg_popup_menu_popup_menu (GitgPopupMenu* self,
                                     GtkWidget* widget,
                                     GdkEventButton* event);
static void _vala_GdkRectangle_free (GdkRectangle* self);
static void g_cclosure_user_marshal_OBJECT__BOXED (GClosure * closure,
                                            GValue * return_value,
                                            guint n_param_values,
                                            const GValue * param_values,
                                            gpointer invocation_hint,
                                            gpointer marshal_data);
static void g_cclosure_user_marshal_POINTER__VOID (GClosure * closure,
                                            GValue * return_value,
                                            guint n_param_values,
                                            const GValue * param_values,
                                            gpointer invocation_hint,
                                            gpointer marshal_data);
static void gitg_popup_menu_finalize (GObject * obj);
static GType gitg_popup_menu_get_type_once (void);

static inline gpointer
gitg_popup_menu_get_instance_private (GitgPopupMenu* self)
{
	return G_STRUCT_MEMBER_P (self, GitgPopupMenu_private_offset);
}

static gboolean
_gitg_popup_menu_on_button_press_event_gtk_widget_button_press_event (GtkWidget* _sender,
                                                                      GdkEventButton* event,
                                                                      gpointer self)
{
	gboolean result;
	result = gitg_popup_menu_on_button_press_event ((GitgPopupMenu*) self, _sender, event);
	return result;
}

static gboolean
_gitg_popup_menu_on_popup_menu_gtk_widget_popup_menu (GtkWidget* _sender,
                                                      gpointer self)
{
	gboolean result;
	result = gitg_popup_menu_on_popup_menu ((GitgPopupMenu*) self, _sender);
	return result;
}

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

GitgPopupMenu*
gitg_popup_menu_construct (GType object_type,
                           GtkWidget* widget)
{
	GitgPopupMenu * self = NULL;
	GtkWidget* _tmp0_;
	g_return_val_if_fail (widget != NULL, NULL);
	self = (GitgPopupMenu*) g_object_new (object_type, NULL);
	g_signal_connect_object (widget, "button-press-event", (GCallback) _gitg_popup_menu_on_button_press_event_gtk_widget_button_press_event, self, 0);
	g_signal_connect_object (widget, "popup-menu", (GCallback) _gitg_popup_menu_on_popup_menu_gtk_widget_popup_menu, self, 0);
	_tmp0_ = _g_object_ref0 (widget);
	_g_object_unref0 (self->priv->d_widget);
	self->priv->d_widget = _tmp0_;
	return self;
}

GitgPopupMenu*
gitg_popup_menu_new (GtkWidget* widget)
{
	return gitg_popup_menu_construct (GITG_TYPE_POPUP_MENU, widget);
}

static void
gitg_popup_menu_real_dispose (GObject* base)
{
	GitgPopupMenu * self;
	GtkWidget* _tmp0_;
	self = (GitgPopupMenu*) base;
	_tmp0_ = self->priv->d_widget;
	if (_tmp0_ != NULL) {
		GtkWidget* _tmp1_;
		guint _tmp2_;
		GtkWidget* _tmp3_;
		guint _tmp4_;
		_tmp1_ = self->priv->d_widget;
		g_signal_parse_name ("button-press-event", gtk_widget_get_type (), &_tmp2_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp1_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp2_, 0, NULL, (GCallback) _gitg_popup_menu_on_button_press_event_gtk_widget_button_press_event, self);
		_tmp3_ = self->priv->d_widget;
		g_signal_parse_name ("popup-menu", gtk_widget_get_type (), &_tmp4_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp3_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp4_, 0, NULL, (GCallback) _gitg_popup_menu_on_popup_menu_gtk_widget_popup_menu, self);
		_g_object_unref0 (self->priv->d_widget);
		self->priv->d_widget = NULL;
	}
}

static void
_vala_GdkRectangle_free (GdkRectangle* self)
{
	g_boxed_free (gdk_rectangle_get_type (), self);
}

static gboolean
gitg_popup_menu_popup_menu (GitgPopupMenu* self,
                            GtkWidget* widget,
                            GdkEventButton* event)
{
	GtkMenu* menu = NULL;
	GtkMenu* _tmp0_ = NULL;
	GtkMenu* _tmp1_;
	GtkMenu* _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (widget != NULL, FALSE);
	g_signal_emit (self, gitg_popup_menu_signals[GITG_POPUP_MENU_POPULATE_MENU_SIGNAL], 0, event, &_tmp0_);
	menu = _tmp0_;
	_tmp1_ = menu;
	if (_tmp1_ == NULL) {
		result = FALSE;
		_g_object_unref0 (menu);
		return result;
	}
	_tmp2_ = menu;
	gtk_menu_attach_to_widget (_tmp2_, widget, NULL);
	if (event == NULL) {
		GdkRectangle* position = NULL;
		GdkRectangle* _tmp3_ = NULL;
		GdkRectangle* _tmp4_;
		g_signal_emit (self, gitg_popup_menu_signals[GITG_POPUP_MENU_REQUEST_MENU_POSITION_SIGNAL], 0, &_tmp3_);
		position = _tmp3_;
		_tmp4_ = position;
		if (_tmp4_ == NULL) {
			GtkMenu* _tmp5_;
			_tmp5_ = menu;
			gtk_menu_popup_at_widget (_tmp5_, widget, GDK_GRAVITY_CENTER, GDK_GRAVITY_CENTER, NULL);
		} else {
			GtkMenu* _tmp6_;
			GdkWindow* _tmp7_;
			GdkRectangle* _tmp8_;
			GdkRectangle _tmp9_;
			_tmp6_ = menu;
			_tmp7_ = gtk_widget_get_window (widget);
			_tmp8_ = position;
			_tmp9_ = *_tmp8_;
			gtk_menu_popup_at_rect (_tmp6_, _tmp7_, &_tmp9_, GDK_GRAVITY_CENTER, GDK_GRAVITY_WEST, NULL);
		}
		__vala_GdkRectangle_free0 (position);
	} else {
		GtkMenu* _tmp10_;
		_tmp10_ = menu;
		gtk_menu_popup_at_pointer (_tmp10_, (GdkEvent*) event);
	}
	result = TRUE;
	_g_object_unref0 (menu);
	return result;
}

static gboolean
gitg_popup_menu_on_popup_menu (GitgPopupMenu* self,
                               GtkWidget* widget)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (widget != NULL, FALSE);
	result = gitg_popup_menu_popup_menu (self, widget, NULL);
	return result;
}

static gboolean
gitg_popup_menu_on_button_press_event (GitgPopupMenu* self,
                                       GtkWidget* widget,
                                       GdkEventButton* event)
{
	GdkEvent* ev = NULL;
	GdkEvent* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (widget != NULL, FALSE);
	g_return_val_if_fail (event != NULL, FALSE);
	ev = (GdkEvent*) event;
	_tmp0_ = ev;
	if (!gdk_event_triggers_context_menu (_tmp0_)) {
		result = FALSE;
		return result;
	}
	result = gitg_popup_menu_popup_menu (self, widget, event);
	return result;
}

static void
g_cclosure_user_marshal_OBJECT__BOXED (GClosure * closure,
                                       GValue * return_value,
                                       guint n_param_values,
                                       const GValue * param_values,
                                       gpointer invocation_hint,
                                       gpointer marshal_data)
{
	typedef gpointer (*GMarshalFunc_OBJECT__BOXED) (gpointer data1, gpointer arg_1, gpointer data2);
	register GMarshalFunc_OBJECT__BOXED callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	gpointer v_return;
	cc = (GCClosure *) closure;
	g_return_if_fail (return_value != NULL);
	g_return_if_fail (n_param_values == 2);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_OBJECT__BOXED) (marshal_data ? marshal_data : cc->callback);
	v_return = callback (data1, g_value_get_boxed (param_values + 1), data2);
	g_value_take_object (return_value, v_return);
}

static void
g_cclosure_user_marshal_POINTER__VOID (GClosure * closure,
                                       GValue * return_value,
                                       guint n_param_values,
                                       const GValue * param_values,
                                       gpointer invocation_hint,
                                       gpointer marshal_data)
{
	typedef gpointer (*GMarshalFunc_POINTER__VOID) (gpointer data1, gpointer data2);
	register GMarshalFunc_POINTER__VOID callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	gpointer v_return;
	cc = (GCClosure *) closure;
	g_return_if_fail (return_value != NULL);
	g_return_if_fail (n_param_values == 1);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_POINTER__VOID) (marshal_data ? marshal_data : cc->callback);
	v_return = callback (data1, data2);
	g_value_set_pointer (return_value, v_return);
}

static void
gitg_popup_menu_class_init (GitgPopupMenuClass * klass,
                            gpointer klass_data)
{
	gitg_popup_menu_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GitgPopupMenu_private_offset);
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) gitg_popup_menu_real_dispose;
	G_OBJECT_CLASS (klass)->finalize = gitg_popup_menu_finalize;
	gitg_popup_menu_signals[GITG_POPUP_MENU_POPULATE_MENU_SIGNAL] = g_signal_new ("populate-menu", GITG_TYPE_POPUP_MENU, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_OBJECT__BOXED, gtk_menu_get_type (), 1, gdk_event_get_type ());
	gitg_popup_menu_signals[GITG_POPUP_MENU_REQUEST_MENU_POSITION_SIGNAL] = g_signal_new ("request-menu-position", GITG_TYPE_POPUP_MENU, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_POINTER__VOID, G_TYPE_POINTER, 0);
}

static void
gitg_popup_menu_instance_init (GitgPopupMenu * self,
                               gpointer klass)
{
	self->priv = gitg_popup_menu_get_instance_private (self);
}

static void
gitg_popup_menu_finalize (GObject * obj)
{
	GitgPopupMenu * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GITG_TYPE_POPUP_MENU, GitgPopupMenu);
	_g_object_unref0 (self->priv->d_widget);
	G_OBJECT_CLASS (gitg_popup_menu_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gitg_popup_menu_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GitgPopupMenuClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gitg_popup_menu_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GitgPopupMenu), 0, (GInstanceInitFunc) gitg_popup_menu_instance_init, NULL };
	GType gitg_popup_menu_type_id;
	gitg_popup_menu_type_id = g_type_register_static (G_TYPE_OBJECT, "GitgPopupMenu", &g_define_type_info, 0);
	GitgPopupMenu_private_offset = g_type_add_instance_private (gitg_popup_menu_type_id, sizeof (GitgPopupMenuPrivate));
	return gitg_popup_menu_type_id;
}

GType
gitg_popup_menu_get_type (void)
{
	static gsize gitg_popup_menu_type_id__once = 0;
	if (g_once_init_enter (&gitg_popup_menu_type_id__once)) {
		GType gitg_popup_menu_type_id;
		gitg_popup_menu_type_id = gitg_popup_menu_get_type_once ();
		g_once_init_leave (&gitg_popup_menu_type_id__once, gitg_popup_menu_type_id);
	}
	return gitg_popup_menu_type_id__once;
}

