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

/*
 * SPDX-License-Identifier: GPL-3.0
 * SPDX-FileCopyrightText: 2011-2013 Mathijs Henquet
 *                         2023 elementary, Inc. (https://elementary.io)
 *
 * Authored by: Mathijs Henquet <mathijs.henquet@gmail.com>,
 *              ammonkey <am.monkeyd@gmail.com>
 */

#include "pantheon-files-core.h"
#include <gtk/gtk.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gdk/gdk.h>
#include <gio/gio.h>
#include <float.h>
#include <math.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

enum  {
	FILES_VIEW_CHROME_BUTTON_WITH_MENU_0_PROPERTY,
	FILES_VIEW_CHROME_BUTTON_WITH_MENU_MENU_PROPERTY,
	FILES_VIEW_CHROME_BUTTON_WITH_MENU_NUM_PROPERTIES
};
static GParamSpec* files_view_chrome_button_with_menu_properties[FILES_VIEW_CHROME_BUTTON_WITH_MENU_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define __vala_GdkEvent_free0(var) ((var == NULL) ? NULL : (var = (_vala_GdkEvent_free (var), NULL)))
typedef struct _Block40Data Block40Data;
enum  {
	FILES_VIEW_CHROME_BUTTON_WITH_MENU_SLOW_PRESS_SIGNAL,
	FILES_VIEW_CHROME_BUTTON_WITH_MENU_NUM_SIGNALS
};
static guint files_view_chrome_button_with_menu_signals[FILES_VIEW_CHROME_BUTTON_WITH_MENU_NUM_SIGNALS] = {0};

struct _FilesViewChromeButtonWithMenuPrivate {
	GtkMenu* gtk_menu;
};

struct _Block40Data {
	int _ref_count_;
	FilesViewChromeButtonWithMenu* self;
	GtkGestureMultiPress* press_gesture;
	GtkGestureMultiPress* secondary_click_gesture;
	GtkGestureLongPress* long_press_gesture;
};

static gint FilesViewChromeButtonWithMenu_private_offset;
static gpointer files_view_chrome_button_with_menu_parent_class = NULL;

static gboolean files_view_chrome_button_with_menu_on_mnemonic_activate (FilesViewChromeButtonWithMenu* self,
                                                                  gboolean group_cycling);
static void _vala_GdkEvent_free (GdkEvent* self);
static GObject * files_view_chrome_button_with_menu_constructor (GType type,
                                                          guint n_construct_properties,
                                                          GObjectConstructParam * construct_properties);
static Block40Data* block40_data_ref (Block40Data* _data40_);
static void block40_data_unref (void * _userdata_);
static void _files_view_chrome_button_with_menu___lambda66_ (FilesViewChromeButtonWithMenu* self);
static void __files_view_chrome_button_with_menu___lambda66__gtk_menu_shell_deactivate (GtkMenuShell* _sender,
                                                                                 gpointer self);
static gboolean _files_view_chrome_button_with_menu_on_mnemonic_activate_gtk_widget_mnemonic_activate (GtkWidget* _sender,
                                                                                                gboolean group_cycling,
                                                                                                gpointer self);
static void _files_view_chrome_button_with_menu___lambda67_ (Block40Data* _data40_);
static void __files_view_chrome_button_with_menu___lambda67__gtk_gesture_multi_press_released (GtkGestureMultiPress* _sender,
                                                                                        gint n_press,
                                                                                        gdouble x,
                                                                                        gdouble y,
                                                                                        gpointer self);
static void _files_view_chrome_button_with_menu___lambda68_ (Block40Data* _data40_);
static void __files_view_chrome_button_with_menu___lambda68__gtk_gesture_multi_press_pressed (GtkGestureMultiPress* _sender,
                                                                                       gint n_press,
                                                                                       gdouble x,
                                                                                       gdouble y,
                                                                                       gpointer self);
static void _files_view_chrome_button_with_menu___lambda69_ (Block40Data* _data40_);
static void __files_view_chrome_button_with_menu___lambda69__gtk_gesture_long_press_pressed (GtkGestureLongPress* _sender,
                                                                                      gdouble x,
                                                                                      gdouble y,
                                                                                      gpointer self);
static void files_view_chrome_button_with_menu_finalize (GObject * obj);
static GType files_view_chrome_button_with_menu_get_type_once (void);
static void _vala_files_view_chrome_button_with_menu_set_property (GObject * object,
                                                            guint property_id,
                                                            const GValue * value,
                                                            GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
files_view_chrome_button_with_menu_get_instance_private (FilesViewChromeButtonWithMenu* self)
{
	return G_STRUCT_MEMBER_P (self, FilesViewChromeButtonWithMenu_private_offset);
}

FilesViewChromeButtonWithMenu*
files_view_chrome_button_with_menu_construct (GType object_type,
                                              const gchar* icon_name)
{
	FilesViewChromeButtonWithMenu * self = NULL;
	GtkImage* _tmp0_;
	GtkImage* _tmp1_;
	g_return_val_if_fail (icon_name != NULL, NULL);
	self = (FilesViewChromeButtonWithMenu*) g_object_new (object_type, NULL);
	_tmp0_ = (GtkImage*) gtk_image_new_from_icon_name (icon_name, (GtkIconSize) GTK_ICON_SIZE_LARGE_TOOLBAR);
	g_object_ref_sink (_tmp0_);
	_tmp1_ = _tmp0_;
	gtk_button_set_image ((GtkButton*) self, (GtkWidget*) _tmp1_);
	_g_object_unref0 (_tmp1_);
	return self;
}

FilesViewChromeButtonWithMenu*
files_view_chrome_button_with_menu_new (const gchar* icon_name)
{
	return files_view_chrome_button_with_menu_construct (FILES_VIEW_CHROME_TYPE_BUTTON_WITH_MENU, icon_name);
}

static gboolean
files_view_chrome_button_with_menu_on_mnemonic_activate (FilesViewChromeButtonWithMenu* self,
                                                         gboolean group_cycling)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	if (!group_cycling) {
		g_signal_emit_by_name ((GtkButton*) self, "activate");
	} else {
		gboolean _tmp0_;
		gboolean _tmp1_;
		_tmp0_ = gtk_widget_get_can_focus ((GtkWidget*) self);
		_tmp1_ = _tmp0_;
		if (_tmp1_) {
			gtk_widget_grab_focus ((GtkWidget*) self);
		}
	}
	result = TRUE;
	return result;
}

static void
_vala_GdkEvent_free (GdkEvent* self)
{
	g_boxed_free (gdk_event_get_type (), self);
}

void
files_view_chrome_button_with_menu_popup_menu (FilesViewChromeButtonWithMenu* self)
{
	GtkMenu* _tmp0_;
	GdkEvent* _tmp1_;
	GdkEvent* _tmp2_;
	GtkMenu* _tmp3_;
	g_return_if_fail (self != NULL);
	gtk_toggle_button_set_active ((GtkToggleButton*) self, TRUE);
	_tmp0_ = self->priv->gtk_menu;
	_tmp1_ = gtk_get_current_event ();
	_tmp2_ = _tmp1_;
	gtk_menu_popup_at_widget (_tmp0_, (GtkWidget*) self, GDK_GRAVITY_SOUTH_WEST, GDK_GRAVITY_NORTH_WEST, _tmp2_);
	__vala_GdkEvent_free0 (_tmp2_);
	_tmp3_ = self->priv->gtk_menu;
	gtk_menu_shell_select_first ((GtkMenuShell*) _tmp3_, FALSE);
}

void
files_view_chrome_button_with_menu_set_menu (FilesViewChromeButtonWithMenu* self,
                                             GMenu* value)
{
	GtkMenu* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->gtk_menu;
	gtk_menu_shell_bind_model ((GtkMenuShell*) _tmp0_, (GMenuModel*) value, NULL, FALSE);
	g_object_notify_by_pspec ((GObject *) self, files_view_chrome_button_with_menu_properties[FILES_VIEW_CHROME_BUTTON_WITH_MENU_MENU_PROPERTY]);
}

static Block40Data*
block40_data_ref (Block40Data* _data40_)
{
	g_atomic_int_inc (&_data40_->_ref_count_);
	return _data40_;
}

static void
block40_data_unref (void * _userdata_)
{
	Block40Data* _data40_;
	_data40_ = (Block40Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data40_->_ref_count_)) {
		FilesViewChromeButtonWithMenu* self;
		self = _data40_->self;
		_g_object_unref0 (_data40_->long_press_gesture);
		_g_object_unref0 (_data40_->secondary_click_gesture);
		_g_object_unref0 (_data40_->press_gesture);
		_g_object_unref0 (self);
		g_slice_free (Block40Data, _data40_);
	}
}

static void
_files_view_chrome_button_with_menu___lambda66_ (FilesViewChromeButtonWithMenu* self)
{
	gtk_toggle_button_set_active ((GtkToggleButton*) self, FALSE);
}

static void
__files_view_chrome_button_with_menu___lambda66__gtk_menu_shell_deactivate (GtkMenuShell* _sender,
                                                                            gpointer self)
{
	_files_view_chrome_button_with_menu___lambda66_ ((FilesViewChromeButtonWithMenu*) self);
}

static gboolean
_files_view_chrome_button_with_menu_on_mnemonic_activate_gtk_widget_mnemonic_activate (GtkWidget* _sender,
                                                                                       gboolean group_cycling,
                                                                                       gpointer self)
{
	gboolean result;
	result = files_view_chrome_button_with_menu_on_mnemonic_activate ((FilesViewChromeButtonWithMenu*) self, group_cycling);
	return result;
}

static void
_files_view_chrome_button_with_menu___lambda67_ (Block40Data* _data40_)
{
	FilesViewChromeButtonWithMenu* self;
	GtkGestureMultiPress* _tmp0_;
	self = _data40_->self;
	g_signal_emit (self, files_view_chrome_button_with_menu_signals[FILES_VIEW_CHROME_BUTTON_WITH_MENU_SLOW_PRESS_SIGNAL], 0);
	_tmp0_ = _data40_->press_gesture;
	gtk_gesture_set_state ((GtkGesture*) _tmp0_, GTK_EVENT_SEQUENCE_CLAIMED);
}

static void
__files_view_chrome_button_with_menu___lambda67__gtk_gesture_multi_press_released (GtkGestureMultiPress* _sender,
                                                                                   gint n_press,
                                                                                   gdouble x,
                                                                                   gdouble y,
                                                                                   gpointer self)
{
	_files_view_chrome_button_with_menu___lambda67_ (self);
}

static void
_files_view_chrome_button_with_menu___lambda68_ (Block40Data* _data40_)
{
	FilesViewChromeButtonWithMenu* self;
	GtkGestureMultiPress* _tmp0_;
	self = _data40_->self;
	files_view_chrome_button_with_menu_popup_menu (self);
	_tmp0_ = _data40_->secondary_click_gesture;
	gtk_gesture_set_state ((GtkGesture*) _tmp0_, GTK_EVENT_SEQUENCE_CLAIMED);
}

static void
__files_view_chrome_button_with_menu___lambda68__gtk_gesture_multi_press_pressed (GtkGestureMultiPress* _sender,
                                                                                  gint n_press,
                                                                                  gdouble x,
                                                                                  gdouble y,
                                                                                  gpointer self)
{
	_files_view_chrome_button_with_menu___lambda68_ (self);
}

static void
_files_view_chrome_button_with_menu___lambda69_ (Block40Data* _data40_)
{
	FilesViewChromeButtonWithMenu* self;
	GtkGestureLongPress* _tmp0_;
	self = _data40_->self;
	files_view_chrome_button_with_menu_popup_menu (self);
	_tmp0_ = _data40_->long_press_gesture;
	gtk_gesture_set_state ((GtkGesture*) _tmp0_, GTK_EVENT_SEQUENCE_CLAIMED);
}

static void
__files_view_chrome_button_with_menu___lambda69__gtk_gesture_long_press_pressed (GtkGestureLongPress* _sender,
                                                                                 gdouble x,
                                                                                 gdouble y,
                                                                                 gpointer self)
{
	_files_view_chrome_button_with_menu___lambda69_ (self);
}

static GObject *
files_view_chrome_button_with_menu_constructor (GType type,
                                                guint n_construct_properties,
                                                GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	FilesViewChromeButtonWithMenu * self;
	Block40Data* _data40_;
	GtkMenu* _tmp0_;
	GtkMenu* _tmp1_;
	GtkMenu* _tmp2_;
	GtkGestureMultiPress* _tmp3_ = NULL;
	GtkGestureMultiPress* _tmp4_;
	GtkGestureMultiPress* _tmp5_ = NULL;
	GtkGestureMultiPress* _tmp6_;
	GtkGestureLongPress* _tmp7_;
	GtkGestureLongPress* _tmp8_;
	parent_class = G_OBJECT_CLASS (files_view_chrome_button_with_menu_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FILES_VIEW_CHROME_TYPE_BUTTON_WITH_MENU, FilesViewChromeButtonWithMenu);
	_data40_ = g_slice_new0 (Block40Data);
	_data40_->_ref_count_ = 1;
	_data40_->self = g_object_ref (self);
	gtk_button_set_use_underline ((GtkButton*) self, TRUE);
	_tmp0_ = (GtkMenu*) gtk_menu_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->gtk_menu);
	self->priv->gtk_menu = _tmp0_;
	_tmp1_ = self->priv->gtk_menu;
	gtk_menu_attach_to_widget (_tmp1_, (GtkWidget*) self, NULL);
	_tmp2_ = self->priv->gtk_menu;
	g_signal_connect_object ((GtkMenuShell*) _tmp2_, "deactivate", (GCallback) __files_view_chrome_button_with_menu___lambda66__gtk_menu_shell_deactivate, self, 0);
	g_signal_connect_object ((GtkWidget*) self, "mnemonic-activate", (GCallback) _files_view_chrome_button_with_menu_on_mnemonic_activate_gtk_widget_mnemonic_activate, self, 0);
	_tmp3_ = (GtkGestureMultiPress*) gtk_gesture_multi_press_new ((GtkWidget*) self);
	gtk_gesture_single_set_button ((GtkGestureSingle*) _tmp3_, (guint) GDK_BUTTON_PRIMARY);
	_data40_->press_gesture = _tmp3_;
	_tmp4_ = _data40_->press_gesture;
	g_signal_connect_data (_tmp4_, "released", (GCallback) __files_view_chrome_button_with_menu___lambda67__gtk_gesture_multi_press_released, block40_data_ref (_data40_), (GClosureNotify) block40_data_unref, 0);
	_tmp5_ = (GtkGestureMultiPress*) gtk_gesture_multi_press_new ((GtkWidget*) self);
	gtk_gesture_single_set_button ((GtkGestureSingle*) _tmp5_, (guint) GDK_BUTTON_SECONDARY);
	_data40_->secondary_click_gesture = _tmp5_;
	_tmp6_ = _data40_->secondary_click_gesture;
	g_signal_connect_data (_tmp6_, "pressed", (GCallback) __files_view_chrome_button_with_menu___lambda68__gtk_gesture_multi_press_pressed, block40_data_ref (_data40_), (GClosureNotify) block40_data_unref, 0);
	_tmp7_ = (GtkGestureLongPress*) gtk_gesture_long_press_new ((GtkWidget*) self);
	_data40_->long_press_gesture = _tmp7_;
	_tmp8_ = _data40_->long_press_gesture;
	g_signal_connect_data (_tmp8_, "pressed", (GCallback) __files_view_chrome_button_with_menu___lambda69__gtk_gesture_long_press_pressed, block40_data_ref (_data40_), (GClosureNotify) block40_data_unref, 0);
	block40_data_unref (_data40_);
	_data40_ = NULL;
	return obj;
}

static void
files_view_chrome_button_with_menu_class_init (FilesViewChromeButtonWithMenuClass * klass,
                                               gpointer klass_data)
{
	files_view_chrome_button_with_menu_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FilesViewChromeButtonWithMenu_private_offset);
	G_OBJECT_CLASS (klass)->set_property = _vala_files_view_chrome_button_with_menu_set_property;
	G_OBJECT_CLASS (klass)->constructor = files_view_chrome_button_with_menu_constructor;
	G_OBJECT_CLASS (klass)->finalize = files_view_chrome_button_with_menu_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FILES_VIEW_CHROME_BUTTON_WITH_MENU_MENU_PROPERTY, files_view_chrome_button_with_menu_properties[FILES_VIEW_CHROME_BUTTON_WITH_MENU_MENU_PROPERTY] = g_param_spec_object ("menu", "menu", "menu", g_menu_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE));
	files_view_chrome_button_with_menu_signals[FILES_VIEW_CHROME_BUTTON_WITH_MENU_SLOW_PRESS_SIGNAL] = g_signal_new ("slow-press", FILES_VIEW_CHROME_TYPE_BUTTON_WITH_MENU, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
files_view_chrome_button_with_menu_instance_init (FilesViewChromeButtonWithMenu * self,
                                                  gpointer klass)
{
	self->priv = files_view_chrome_button_with_menu_get_instance_private (self);
}

static void
files_view_chrome_button_with_menu_finalize (GObject * obj)
{
	FilesViewChromeButtonWithMenu * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FILES_VIEW_CHROME_TYPE_BUTTON_WITH_MENU, FilesViewChromeButtonWithMenu);
	_g_object_unref0 (self->priv->gtk_menu);
	G_OBJECT_CLASS (files_view_chrome_button_with_menu_parent_class)->finalize (obj);
}

/**
 * ButtonWithMenu
 * - support long click / right click with depressed button states
 * - activate a GtkAction if any or popup a menu
 * (used in history navigation buttons)
 */
 G_GNUC_NO_INLINE static GType
files_view_chrome_button_with_menu_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FilesViewChromeButtonWithMenuClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) files_view_chrome_button_with_menu_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FilesViewChromeButtonWithMenu), 0, (GInstanceInitFunc) files_view_chrome_button_with_menu_instance_init, NULL };
	GType files_view_chrome_button_with_menu_type_id;
	files_view_chrome_button_with_menu_type_id = g_type_register_static (gtk_toggle_button_get_type (), "FilesViewChromeButtonWithMenu", &g_define_type_info, 0);
	FilesViewChromeButtonWithMenu_private_offset = g_type_add_instance_private (files_view_chrome_button_with_menu_type_id, sizeof (FilesViewChromeButtonWithMenuPrivate));
	return files_view_chrome_button_with_menu_type_id;
}

GType
files_view_chrome_button_with_menu_get_type (void)
{
	static volatile gsize files_view_chrome_button_with_menu_type_id__once = 0;
	if (g_once_init_enter (&files_view_chrome_button_with_menu_type_id__once)) {
		GType files_view_chrome_button_with_menu_type_id;
		files_view_chrome_button_with_menu_type_id = files_view_chrome_button_with_menu_get_type_once ();
		g_once_init_leave (&files_view_chrome_button_with_menu_type_id__once, files_view_chrome_button_with_menu_type_id);
	}
	return files_view_chrome_button_with_menu_type_id__once;
}

static void
_vala_files_view_chrome_button_with_menu_set_property (GObject * object,
                                                       guint property_id,
                                                       const GValue * value,
                                                       GParamSpec * pspec)
{
	FilesViewChromeButtonWithMenu * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FILES_VIEW_CHROME_TYPE_BUTTON_WITH_MENU, FilesViewChromeButtonWithMenu);
	switch (property_id) {
		case FILES_VIEW_CHROME_BUTTON_WITH_MENU_MENU_PROPERTY:
		files_view_chrome_button_with_menu_set_menu (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

