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

#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.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 G4_TYPE_VOLUME_BUTTON (g4_volume_button_get_type ())
#define G4_VOLUME_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G4_TYPE_VOLUME_BUTTON, G4VolumeButton))
#define G4_VOLUME_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), G4_TYPE_VOLUME_BUTTON, G4VolumeButtonClass))
#define G4_IS_VOLUME_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G4_TYPE_VOLUME_BUTTON))
#define G4_IS_VOLUME_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), G4_TYPE_VOLUME_BUTTON))
#define G4_VOLUME_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), G4_TYPE_VOLUME_BUTTON, G4VolumeButtonClass))

typedef struct _G4VolumeButton G4VolumeButton;
typedef struct _G4VolumeButtonClass G4VolumeButtonClass;
typedef struct _G4VolumeButtonPrivate G4VolumeButtonPrivate;
enum  {
	G4_VOLUME_BUTTON_0_PROPERTY,
	G4_VOLUME_BUTTON_NUM_PROPERTIES
};
static GParamSpec* g4_volume_button_properties[G4_VOLUME_BUTTON_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _G4VolumeButton {
	GtkScaleButton parent_instance;
	G4VolumeButtonPrivate * priv;
};

struct _G4VolumeButtonClass {
	GtkScaleButtonClass parent_class;
};

static gpointer g4_volume_button_parent_class = NULL;
VALA_EXTERN gdouble g4_volume_button_EPSILON;
gdouble g4_volume_button_EPSILON = 1e-10;
VALA_EXTERN gchar** g4_volume_button_ICONS;
VALA_EXTERN gint g4_volume_button_ICONS_length1;
gchar** g4_volume_button_ICONS = NULL;
gint g4_volume_button_ICONS_length1 = 0;
static GtkAccessibleInterface * g4_volume_button_gtk_accessible_parent_iface = NULL;
static GtkBuildableIface * g4_volume_button_gtk_buildable_parent_iface = NULL;
static GtkConstraintTargetInterface * g4_volume_button_gtk_constraint_target_parent_iface = NULL;
static GtkOrientableIface * g4_volume_button_gtk_orientable_parent_iface = NULL;

VALA_EXTERN GType g4_volume_button_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (G4VolumeButton, g_object_unref)
static gchar* g4_volume_button_get_volume_text (G4VolumeButton* self);
static gboolean g4_volume_button_on_query_tooltip (G4VolumeButton* self,
                                            gint x,
                                            gint y,
                                            gboolean keyboard_mode,
                                            GtkTooltip* tooltip);
static void g4_volume_button_on_value_changed (G4VolumeButton* self,
                                        gdouble value);
VALA_EXTERN G4VolumeButton* g4_volume_button_new (void);
VALA_EXTERN G4VolumeButton* g4_volume_button_construct (GType object_type);
static GObject * g4_volume_button_constructor (GType type,
                                        guint n_construct_properties,
                                        GObjectConstructParam * construct_properties);
static gboolean _g4_volume_button_on_query_tooltip_gtk_widget_query_tooltip (GtkWidget* _sender,
                                                                      gint x,
                                                                      gint y,
                                                                      gboolean keyboard_tooltip,
                                                                      GtkTooltip* tooltip,
                                                                      gpointer self);
static void _g4_volume_button_on_value_changed_gtk_scale_button_value_changed (GtkScaleButton* _sender,
                                                                        gdouble value,
                                                                        gpointer self);
static void g4_volume_button_finalize (GObject * obj);
static GType g4_volume_button_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

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

static gchar*
g4_volume_button_get_volume_text (G4VolumeButton* self)
{
	GtkAdjustment* adj = NULL;
	GtkAdjustment* _tmp0_;
	GtkAdjustment* _tmp1_;
	GtkAdjustment* _tmp2_;
	gdouble value = 0.0;
	gint percent = 0;
	gdouble _tmp3_;
	gdouble _tmp4_;
	gdouble _tmp5_;
	gdouble _tmp6_;
	gchar* _tmp7_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = gtk_scale_button_get_adjustment ((GtkScaleButton*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	adj = _tmp2_;
	value = gtk_scale_button_get_value ((GtkScaleButton*) self);
	_tmp3_ = gtk_adjustment_get_upper (adj);
	_tmp4_ = _tmp3_;
	_tmp5_ = gtk_adjustment_get_lower (adj);
	_tmp6_ = _tmp5_;
	percent = (gint) (((100 * value) / (_tmp4_ - _tmp6_)) + 0.5);
	_tmp7_ = g_strdup_printf (_ ("Volume %d%%"), percent);
	result = _tmp7_;
	_g_object_unref0 (adj);
	return result;
}

static gboolean
g4_volume_button_on_query_tooltip (G4VolumeButton* self,
                                   gint x,
                                   gint y,
                                   gboolean keyboard_mode,
                                   GtkTooltip* tooltip)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (tooltip != NULL, FALSE);
	_tmp0_ = g4_volume_button_get_volume_text (self);
	_tmp1_ = _tmp0_;
	gtk_tooltip_set_text (tooltip, _tmp1_);
	_g_free0 (_tmp1_);
	result = TRUE;
	return result;
}

static void
g4_volume_button_on_value_changed (G4VolumeButton* self,
                                   gdouble value)
{
	g_return_if_fail (self != NULL);
	gtk_widget_trigger_tooltip_query ((GtkWidget*) self);
}

G4VolumeButton*
g4_volume_button_construct (GType object_type)
{
	G4VolumeButton * self = NULL;
	self = (G4VolumeButton*) g_object_new (object_type, NULL);
	return self;
}

G4VolumeButton*
g4_volume_button_new (void)
{
	return g4_volume_button_construct (G4_TYPE_VOLUME_BUTTON);
}

static gboolean
_g4_volume_button_on_query_tooltip_gtk_widget_query_tooltip (GtkWidget* _sender,
                                                             gint x,
                                                             gint y,
                                                             gboolean keyboard_tooltip,
                                                             GtkTooltip* tooltip,
                                                             gpointer self)
{
	gboolean result;
	result = g4_volume_button_on_query_tooltip ((G4VolumeButton*) self, x, y, keyboard_tooltip, tooltip);
	return result;
}

static void
_g4_volume_button_on_value_changed_gtk_scale_button_value_changed (GtkScaleButton* _sender,
                                                                   gdouble value,
                                                                   gpointer self)
{
	g4_volume_button_on_value_changed ((G4VolumeButton*) self, value);
}

static GObject *
g4_volume_button_constructor (GType type,
                              guint n_construct_properties,
                              GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	G4VolumeButton * self;
	GtkAdjustment* adj = NULL;
	GtkAdjustment* _tmp0_;
	GtkAdjustment* _tmp1_;
	GtkAdjustment* _tmp2_;
	GtkAdjustment* _tmp3_;
	GtkAdjustment* _tmp4_;
	GtkAdjustment* _tmp5_;
	GtkAdjustment* _tmp6_;
	gchar** _tmp7_;
	gint _tmp7__length1;
	gchar* _tmp8_;
	gchar* _tmp9_;
	parent_class = G_OBJECT_CLASS (g4_volume_button_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, G4_TYPE_VOLUME_BUTTON, G4VolumeButton);
	_tmp0_ = gtk_scale_button_get_adjustment ((GtkScaleButton*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	adj = _tmp2_;
	_tmp3_ = adj;
	gtk_adjustment_set_lower (_tmp3_, (gdouble) 0);
	_tmp4_ = adj;
	gtk_adjustment_set_upper (_tmp4_, 1.0);
	_tmp5_ = adj;
	gtk_adjustment_set_page_increment (_tmp5_, 0.1);
	_tmp6_ = adj;
	gtk_adjustment_set_step_increment (_tmp6_, 0.1);
	_tmp7_ = g4_volume_button_ICONS;
	_tmp7__length1 = g4_volume_button_ICONS_length1;
	g_object_set ((GtkScaleButton*) self, "icons", _tmp7_, NULL);
	g_signal_connect_object ((GtkWidget*) self, "query-tooltip", (GCallback) _g4_volume_button_on_query_tooltip_gtk_widget_query_tooltip, self, 0);
	g_signal_connect_object ((GtkScaleButton*) self, "value-changed", (GCallback) _g4_volume_button_on_value_changed_gtk_scale_button_value_changed, self, 0);
	_tmp8_ = g4_volume_button_get_volume_text (self);
	_tmp9_ = _tmp8_;
	gtk_widget_set_tooltip_text ((GtkWidget*) self, _tmp9_);
	_g_free0 (_tmp9_);
	_g_object_unref0 (adj);
	return obj;
}

static void
g4_volume_button_class_init (G4VolumeButtonClass * klass,
                             gpointer klass_data)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar** _tmp4_;
	g4_volume_button_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->constructor = g4_volume_button_constructor;
	G_OBJECT_CLASS (klass)->finalize = g4_volume_button_finalize;
	_tmp0_ = g_strdup ("audio-volume-muted-symbolic");
	_tmp1_ = g_strdup ("audio-volume-high-symbolic");
	_tmp2_ = g_strdup ("audio-volume-low-symbolic");
	_tmp3_ = g_strdup ("audio-volume-medium-symbolic");
	_tmp4_ = g_new0 (gchar*, 4 + 1);
	_tmp4_[0] = _tmp0_;
	_tmp4_[1] = _tmp1_;
	_tmp4_[2] = _tmp2_;
	_tmp4_[3] = _tmp3_;
	g4_volume_button_ICONS = _tmp4_;
	g4_volume_button_ICONS_length1 = 4;
}

static void
g4_volume_button_gtk_accessible_interface_init (GtkAccessibleInterface * iface,
                                                gpointer iface_data)
{
	g4_volume_button_gtk_accessible_parent_iface = g_type_interface_peek_parent (iface);
}

static void
g4_volume_button_gtk_buildable_interface_init (GtkBuildableIface * iface,
                                               gpointer iface_data)
{
	g4_volume_button_gtk_buildable_parent_iface = g_type_interface_peek_parent (iface);
}

static void
g4_volume_button_gtk_constraint_target_interface_init (GtkConstraintTargetInterface * iface,
                                                       gpointer iface_data)
{
	g4_volume_button_gtk_constraint_target_parent_iface = g_type_interface_peek_parent (iface);
}

static void
g4_volume_button_gtk_orientable_interface_init (GtkOrientableIface * iface,
                                                gpointer iface_data)
{
	g4_volume_button_gtk_orientable_parent_iface = g_type_interface_peek_parent (iface);
}

static void
g4_volume_button_instance_init (G4VolumeButton * self,
                                gpointer klass)
{
}

static void
g4_volume_button_finalize (GObject * obj)
{
	G4VolumeButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, G4_TYPE_VOLUME_BUTTON, G4VolumeButton);
	G_OBJECT_CLASS (g4_volume_button_parent_class)->finalize (obj);
}

static GType
g4_volume_button_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (G4VolumeButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) g4_volume_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (G4VolumeButton), 0, (GInstanceInitFunc) g4_volume_button_instance_init, NULL };
	static const GInterfaceInfo gtk_accessible_info = { (GInterfaceInitFunc) g4_volume_button_gtk_accessible_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	static const GInterfaceInfo gtk_buildable_info = { (GInterfaceInitFunc) g4_volume_button_gtk_buildable_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	static const GInterfaceInfo gtk_constraint_target_info = { (GInterfaceInitFunc) g4_volume_button_gtk_constraint_target_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	static const GInterfaceInfo gtk_orientable_info = { (GInterfaceInitFunc) g4_volume_button_gtk_orientable_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType g4_volume_button_type_id;
	g4_volume_button_type_id = g_type_register_static (gtk_scale_button_get_type (), "G4VolumeButton", &g_define_type_info, 0);
	g_type_add_interface_static (g4_volume_button_type_id, gtk_accessible_get_type (), &gtk_accessible_info);
	g_type_add_interface_static (g4_volume_button_type_id, gtk_buildable_get_type (), &gtk_buildable_info);
	g_type_add_interface_static (g4_volume_button_type_id, gtk_constraint_target_get_type (), &gtk_constraint_target_info);
	g_type_add_interface_static (g4_volume_button_type_id, gtk_orientable_get_type (), &gtk_orientable_info);
	return g4_volume_button_type_id;
}

GType
g4_volume_button_get_type (void)
{
	static volatile gsize g4_volume_button_type_id__once = 0;
	if (g_once_init_enter (&g4_volume_button_type_id__once)) {
		GType g4_volume_button_type_id;
		g4_volume_button_type_id = g4_volume_button_get_type_once ();
		g_once_init_leave (&g4_volume_button_type_id__once, g4_volume_button_type_id);
	}
	return g4_volume_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;
}

