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

/*
 * BrightnessController
 * This file is part of budgie-extras
 *
 * Author: Serdar ŞEN github.com/serdarsen
 *
 * Copyright © 2018 Ubuntu Budgie Developers
 *
 * 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
 * (at your option) any later version.
 */

#include "brightnesscontroller.h"
#include <gtk/gtk.h>
#include <glib.h>
#include <glib-object.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

enum  {
	BRIGHTNESS_CONTROLLER_WIDGETS_CUSTOM_MENU_BUTTON_0_PROPERTY,
	BRIGHTNESS_CONTROLLER_WIDGETS_CUSTOM_MENU_BUTTON_NUM_PROPERTIES
};
static GParamSpec* brightness_controller_widgets_custom_menu_button_properties[BRIGHTNESS_CONTROLLER_WIDGETS_CUSTOM_MENU_BUTTON_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _BrightnessControllerWidgetsCustomMenuButtonPrivate {
	GtkMenu* menu;
	GList* itemList;
};

static gint BrightnessControllerWidgetsCustomMenuButton_private_offset;
static gpointer brightness_controller_widgets_custom_menu_button_parent_class = NULL;
static GType brightness_controller_widgets_custom_menu_button_type_id = 0;

static void _g_object_unref0_ (gpointer var);
static inline void _g_list_free__g_object_unref0_ (GList* self);
static void __lambda8_ (BrightnessControllerWidgetsCustomMenuButton* self,
                 GtkMenuItem* item);
static void ___lambda8__gfunc (gconstpointer data,
                        gpointer self);
static void brightness_controller_widgets_custom_menu_button_finalize (GObject * obj);

static inline gpointer
brightness_controller_widgets_custom_menu_button_get_instance_private (BrightnessControllerWidgetsCustomMenuButton* self)
{
	return G_STRUCT_MEMBER_P (self, BrightnessControllerWidgetsCustomMenuButton_private_offset);
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

static inline void
_g_list_free__g_object_unref0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_object_unref0_);
}

BrightnessControllerWidgetsCustomMenuButton*
brightness_controller_widgets_custom_menu_button_construct (GType object_type,
                                                            const gchar* labelText)
{
	BrightnessControllerWidgetsCustomMenuButton * self = NULL;
	GtkLabel* _tmp0_;
	GtkLabel* _tmp1_;
	GtkStyleContext* _tmp2_;
	GtkMenu* _tmp3_;
	GtkMenu* _tmp4_;
	g_return_val_if_fail (labelText != NULL, NULL);
	self = (BrightnessControllerWidgetsCustomMenuButton*) g_object_new (object_type, NULL);
	_tmp0_ = (GtkLabel*) gtk_label_new (_ (labelText));
	g_object_ref_sink (_tmp0_);
	_tmp1_ = _tmp0_;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp1_);
	_g_object_unref0 (_tmp1_);
	gtk_menu_button_set_direction ((GtkMenuButton*) self, GTK_ARROW_DOWN);
	_tmp2_ = gtk_widget_get_style_context ((GtkWidget*) self);
	gtk_style_context_add_class (_tmp2_, GTK_STYLE_CLASS_FLAT);
	(self->priv->itemList == NULL) ? NULL : (self->priv->itemList = (_g_list_free__g_object_unref0_ (self->priv->itemList), NULL));
	self->priv->itemList = NULL;
	_tmp3_ = (GtkMenu*) gtk_menu_new ();
	g_object_ref_sink (_tmp3_);
	_g_object_unref0 (self->priv->menu);
	self->priv->menu = _tmp3_;
	_tmp4_ = self->priv->menu;
	gtk_menu_button_set_popup ((GtkMenuButton*) self, _tmp4_);
	return self;
}

BrightnessControllerWidgetsCustomMenuButton*
brightness_controller_widgets_custom_menu_button_new (const gchar* labelText)
{
	return brightness_controller_widgets_custom_menu_button_construct (BRIGHTNESS_CONTROLLER_WIDGETS_TYPE_CUSTOM_MENU_BUTTON, labelText);
}

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

void
brightness_controller_widgets_custom_menu_button_Add (BrightnessControllerWidgetsCustomMenuButton* self,
                                                      GtkMenuItem* item)
{
	GtkMenuItem* _tmp0_;
	GtkMenu* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (item != NULL);
	_tmp0_ = _g_object_ref0 (item);
	self->priv->itemList = g_list_append (self->priv->itemList, _tmp0_);
	_tmp1_ = self->priv->menu;
	gtk_menu_shell_append ((GtkMenuShell*) _tmp1_, item);
}

static void
__lambda8_ (BrightnessControllerWidgetsCustomMenuButton* self,
            GtkMenuItem* item)
{
	g_return_if_fail (item != NULL);
	gtk_menu_item_deselect (item);
}

static void
___lambda8__gfunc (gconstpointer data,
                   gpointer self)
{
	__lambda8_ ((BrightnessControllerWidgetsCustomMenuButton*) self, (GtkMenuItem*) data);
}

void
brightness_controller_widgets_custom_menu_button_Select (BrightnessControllerWidgetsCustomMenuButton* self,
                                                         GtkMenuItem* item)
{
	GList* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (item != NULL);
	_tmp0_ = self->priv->itemList;
	g_list_foreach (_tmp0_, ___lambda8__gfunc, self);
	gtk_menu_item_select (item);
}

void
brightness_controller_widgets_custom_menu_button_ShowAll (BrightnessControllerWidgetsCustomMenuButton* self)
{
	GtkMenu* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->menu;
	gtk_widget_show_all ((GtkWidget*) _tmp0_);
}

static void
brightness_controller_widgets_custom_menu_button_class_init (BrightnessControllerWidgetsCustomMenuButtonClass * klass,
                                                             gpointer klass_data)
{
	brightness_controller_widgets_custom_menu_button_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BrightnessControllerWidgetsCustomMenuButton_private_offset);
	G_OBJECT_CLASS (klass)->finalize = brightness_controller_widgets_custom_menu_button_finalize;
}

static void
brightness_controller_widgets_custom_menu_button_instance_init (BrightnessControllerWidgetsCustomMenuButton * self,
                                                                gpointer klass)
{
	self->priv = brightness_controller_widgets_custom_menu_button_get_instance_private (self);
}

static void
brightness_controller_widgets_custom_menu_button_finalize (GObject * obj)
{
	BrightnessControllerWidgetsCustomMenuButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BRIGHTNESS_CONTROLLER_WIDGETS_TYPE_CUSTOM_MENU_BUTTON, BrightnessControllerWidgetsCustomMenuButton);
	_g_object_unref0 (self->priv->menu);
	(self->priv->itemList == NULL) ? NULL : (self->priv->itemList = (_g_list_free__g_object_unref0_ (self->priv->itemList), NULL));
	G_OBJECT_CLASS (brightness_controller_widgets_custom_menu_button_parent_class)->finalize (obj);
}

GType
brightness_controller_widgets_custom_menu_button_get_type (void)
{
	return brightness_controller_widgets_custom_menu_button_type_id;
}

GType
brightness_controller_widgets_custom_menu_button_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (BrightnessControllerWidgetsCustomMenuButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) brightness_controller_widgets_custom_menu_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BrightnessControllerWidgetsCustomMenuButton), 0, (GInstanceInitFunc) brightness_controller_widgets_custom_menu_button_instance_init, NULL };
	brightness_controller_widgets_custom_menu_button_type_id = g_type_module_register_type (module, gtk_menu_button_get_type (), "BrightnessControllerWidgetsCustomMenuButton", &g_define_type_info, 0);
	BrightnessControllerWidgetsCustomMenuButton_private_offset = sizeof (BrightnessControllerWidgetsCustomMenuButtonPrivate);
	return brightness_controller_widgets_custom_menu_button_type_id;
}

