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

/*
 * This file is part of gitg
 *
 * Copyright (C) 2013 - Ignacio Casal Quinteiro
 *
 * 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 "libgitg.h"
#include <glib.h>
#include <float.h>
#include <math.h>
#include <gtk/gtk.h>
#include <cairo-gobject.h>
#include <gdk/gdk.h>
#include <glib-object.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  {
	GITG_PROGRESS_BIN_0_PROPERTY,
	GITG_PROGRESS_BIN_FRACTION_PROPERTY,
	GITG_PROGRESS_BIN_NUM_PROPERTIES
};
static GParamSpec* gitg_progress_bin_properties[GITG_PROGRESS_BIN_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _GitgProgressBinPrivate {
	gdouble d_fraction;
};

static gint GitgProgressBin_private_offset;
static gpointer gitg_progress_bin_parent_class = NULL;

static void gitg_progress_bin_real_realize (GtkWidget* base);
static void gitg_progress_bin_real_size_allocate (GtkWidget* base,
                                           GtkAllocation* allocation);
static gboolean gitg_progress_bin_real_draw (GtkWidget* base,
                                      cairo_t* cr);
static GObject * gitg_progress_bin_constructor (GType type,
                                         guint n_construct_properties,
                                         GObjectConstructParam * construct_properties);
static void gitg_progress_bin_finalize (GObject * obj);
static GType gitg_progress_bin_get_type_once (void);
static void _vala_gitg_progress_bin_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec);
static void _vala_gitg_progress_bin_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec);

static inline gpointer
gitg_progress_bin_get_instance_private (GitgProgressBin* self)
{
	return G_STRUCT_MEMBER_P (self, GitgProgressBin_private_offset);
}

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

static void
gitg_progress_bin_real_realize (GtkWidget* base)
{
	GitgProgressBin * self;
	GtkAllocation allocation = {0};
	GtkAllocation _tmp0_ = {0};
	GdkWindowAttr attributes = {0};
	GdkWindowAttr _tmp1_ = {0};
	GtkAllocation _tmp2_;
	GtkAllocation _tmp3_;
	GtkAllocation _tmp4_;
	GtkAllocation _tmp5_;
	GdkWindowAttributesType attributes_mask = 0U;
	GdkWindow* window = NULL;
	GdkWindow* _tmp6_;
	GdkWindowAttr _tmp7_;
	GdkWindow* _tmp8_;
	GdkWindow* _tmp9_;
	self = (GitgProgressBin*) base;
	gtk_widget_set_realized ((GtkWidget*) self, TRUE);
	gtk_widget_get_allocation ((GtkWidget*) self, &_tmp0_);
	allocation = _tmp0_;
	attributes = _tmp1_;
	_tmp2_ = allocation;
	attributes.x = _tmp2_.x;
	_tmp3_ = allocation;
	attributes.y = _tmp3_.y;
	_tmp4_ = allocation;
	attributes.width = _tmp4_.width;
	_tmp5_ = allocation;
	attributes.height = _tmp5_.height;
	attributes.window_type = GDK_WINDOW_CHILD;
	attributes.wclass = GDK_INPUT_OUTPUT;
	attributes.event_mask = ((gtk_widget_get_events ((GtkWidget*) self) | GDK_EXPOSURE_MASK) | GDK_BUTTON_PRESS_MASK) | GDK_BUTTON_RELEASE_MASK;
	attributes_mask = GDK_WA_X | GDK_WA_Y;
	_tmp6_ = gtk_widget_get_parent_window ((GtkWidget*) self);
	_tmp7_ = attributes;
	_tmp8_ = gdk_window_new (_tmp6_, &_tmp7_, attributes_mask);
	window = _tmp8_;
	_tmp9_ = _g_object_ref0 (window);
	gtk_widget_set_window ((GtkWidget*) self, _tmp9_);
	gdk_window_set_user_data (window, (GObject*) self);
	_g_object_unref0 (window);
}

static void
gitg_progress_bin_real_size_allocate (GtkWidget* base,
                                      GtkAllocation* allocation)
{
	GitgProgressBin * self;
	GtkAllocation _tmp0_;
	GdkWindow* window = NULL;
	GdkWindow* _tmp1_;
	GdkWindow* _tmp2_;
	GdkWindow* _tmp3_;
	GtkWidget* child = NULL;
	GtkWidget* _tmp9_;
	GtkWidget* _tmp10_;
	gboolean _tmp11_ = FALSE;
	GtkWidget* _tmp12_;
	self = (GitgProgressBin*) base;
	g_return_if_fail (allocation != NULL);
	_tmp0_ = *allocation;
	gtk_widget_set_allocation ((GtkWidget*) self, &_tmp0_);
	_tmp1_ = gtk_widget_get_window ((GtkWidget*) self);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	window = _tmp2_;
	_tmp3_ = window;
	if (_tmp3_ != NULL) {
		GdkWindow* _tmp4_;
		GtkAllocation _tmp5_;
		GtkAllocation _tmp6_;
		GtkAllocation _tmp7_;
		GtkAllocation _tmp8_;
		_tmp4_ = window;
		_tmp5_ = *allocation;
		_tmp6_ = *allocation;
		_tmp7_ = *allocation;
		_tmp8_ = *allocation;
		gdk_window_move_resize (_tmp4_, _tmp5_.x, _tmp6_.y, _tmp7_.width, _tmp8_.height);
	}
	_tmp9_ = gtk_bin_get_child ((GtkBin*) self);
	_tmp10_ = _g_object_ref0 (_tmp9_);
	child = _tmp10_;
	_tmp12_ = child;
	if (_tmp12_ != NULL) {
		GtkWidget* _tmp13_;
		_tmp13_ = child;
		_tmp11_ = gtk_widget_get_visible (_tmp13_);
	} else {
		_tmp11_ = FALSE;
	}
	if (_tmp11_) {
		GtkAllocation child_allocation = {0};
		GtkAllocation _tmp14_ = {0};
		gint border_width = 0;
		GtkAllocation _tmp15_;
		GtkAllocation _tmp16_;
		GtkWidget* _tmp17_;
		GtkAllocation _tmp18_;
		child_allocation = _tmp14_;
		border_width = (gint) gtk_container_get_border_width ((GtkContainer*) self);
		child_allocation.x = border_width;
		child_allocation.y = border_width;
		_tmp15_ = *allocation;
		child_allocation.width = _tmp15_.width - (2 * border_width);
		_tmp16_ = *allocation;
		child_allocation.height = _tmp16_.height - (2 * border_width);
		_tmp17_ = child;
		_tmp18_ = child_allocation;
		gtk_widget_size_allocate (_tmp17_, &_tmp18_);
	}
	_g_object_unref0 (child);
	_g_object_unref0 (window);
}

static gboolean
gitg_progress_bin_real_draw (GtkWidget* base,
                             cairo_t* cr)
{
	GitgProgressBin * self;
	GtkAllocation allocation = {0};
	GtkAllocation _tmp0_ = {0};
	GtkStyleContext* context = NULL;
	GtkStyleContext* _tmp1_;
	GtkStyleContext* _tmp2_;
	GtkAllocation _tmp3_;
	GtkAllocation _tmp4_;
	GtkAllocation _tmp5_;
	GtkAllocation _tmp6_;
	gboolean result;
	self = (GitgProgressBin*) base;
	g_return_val_if_fail (cr != NULL, FALSE);
	gtk_widget_get_allocation ((GtkWidget*) self, &_tmp0_);
	allocation = _tmp0_;
	_tmp1_ = gtk_widget_get_style_context ((GtkWidget*) self);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	context = _tmp2_;
	_tmp3_ = allocation;
	_tmp4_ = allocation;
	gtk_render_background (context, cr, (gdouble) 0, (gdouble) 0, (gdouble) _tmp3_.width, (gdouble) _tmp4_.height);
	gtk_style_context_save (context);
	gtk_style_context_add_class (context, "progress-bin");
	_tmp5_ = allocation;
	_tmp6_ = allocation;
	gtk_render_background (context, cr, (gdouble) 0, (gdouble) 0, _tmp5_.width * self->priv->d_fraction, (gdouble) _tmp6_.height);
	gtk_style_context_restore (context);
	GTK_WIDGET_CLASS (gitg_progress_bin_parent_class)->draw ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_bin_get_type (), GtkBin), cr);
	result = TRUE;
	_g_object_unref0 (context);
	return result;
}

GitgProgressBin*
gitg_progress_bin_construct (GType object_type)
{
	GitgProgressBin * self = NULL;
	self = (GitgProgressBin*) g_object_new (object_type, NULL);
	return self;
}

GitgProgressBin*
gitg_progress_bin_new (void)
{
	return gitg_progress_bin_construct (GITG_TYPE_PROGRESS_BIN);
}

gdouble
gitg_progress_bin_get_fraction (GitgProgressBin* self)
{
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	result = self->priv->d_fraction;
	return result;
}

void
gitg_progress_bin_set_fraction (GitgProgressBin* self,
                                gdouble value)
{
	g_return_if_fail (self != NULL);
	self->priv->d_fraction = value;
	gtk_widget_queue_draw ((GtkWidget*) self);
	g_object_notify_by_pspec ((GObject *) self, gitg_progress_bin_properties[GITG_PROGRESS_BIN_FRACTION_PROPERTY]);
}

static GObject *
gitg_progress_bin_constructor (GType type,
                               guint n_construct_properties,
                               GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GitgProgressBin * self;
	parent_class = G_OBJECT_CLASS (gitg_progress_bin_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GITG_TYPE_PROGRESS_BIN, GitgProgressBin);
	gtk_widget_set_has_window ((GtkWidget*) self, TRUE);
	gtk_widget_set_redraw_on_allocate ((GtkWidget*) self, FALSE);
	return obj;
}

static void
gitg_progress_bin_class_init (GitgProgressBinClass * klass,
                              gpointer klass_data)
{
	gitg_progress_bin_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GitgProgressBin_private_offset);
	((GtkWidgetClass *) klass)->realize = (void (*) (GtkWidget*)) gitg_progress_bin_real_realize;
	((GtkWidgetClass *) klass)->size_allocate = (void (*) (GtkWidget*, GtkAllocation*)) gitg_progress_bin_real_size_allocate;
	((GtkWidgetClass *) klass)->draw = (gboolean (*) (GtkWidget*, cairo_t*)) gitg_progress_bin_real_draw;
	G_OBJECT_CLASS (klass)->get_property = _vala_gitg_progress_bin_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gitg_progress_bin_set_property;
	G_OBJECT_CLASS (klass)->constructor = gitg_progress_bin_constructor;
	G_OBJECT_CLASS (klass)->finalize = gitg_progress_bin_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GITG_PROGRESS_BIN_FRACTION_PROPERTY, gitg_progress_bin_properties[GITG_PROGRESS_BIN_FRACTION_PROPERTY] = g_param_spec_double ("fraction", "fraction", "fraction", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
gitg_progress_bin_instance_init (GitgProgressBin * self,
                                 gpointer klass)
{
	self->priv = gitg_progress_bin_get_instance_private (self);
}

static void
gitg_progress_bin_finalize (GObject * obj)
{
	GitgProgressBin * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GITG_TYPE_PROGRESS_BIN, GitgProgressBin);
	G_OBJECT_CLASS (gitg_progress_bin_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gitg_progress_bin_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GitgProgressBinClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gitg_progress_bin_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GitgProgressBin), 0, (GInstanceInitFunc) gitg_progress_bin_instance_init, NULL };
	GType gitg_progress_bin_type_id;
	gitg_progress_bin_type_id = g_type_register_static (gtk_bin_get_type (), "GitgProgressBin", &g_define_type_info, 0);
	GitgProgressBin_private_offset = g_type_add_instance_private (gitg_progress_bin_type_id, sizeof (GitgProgressBinPrivate));
	return gitg_progress_bin_type_id;
}

GType
gitg_progress_bin_get_type (void)
{
	static gsize gitg_progress_bin_type_id__once = 0;
	if (g_once_init_enter (&gitg_progress_bin_type_id__once)) {
		GType gitg_progress_bin_type_id;
		gitg_progress_bin_type_id = gitg_progress_bin_get_type_once ();
		g_once_init_leave (&gitg_progress_bin_type_id__once, gitg_progress_bin_type_id);
	}
	return gitg_progress_bin_type_id__once;
}

static void
_vala_gitg_progress_bin_get_property (GObject * object,
                                      guint property_id,
                                      GValue * value,
                                      GParamSpec * pspec)
{
	GitgProgressBin * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GITG_TYPE_PROGRESS_BIN, GitgProgressBin);
	switch (property_id) {
		case GITG_PROGRESS_BIN_FRACTION_PROPERTY:
		g_value_set_double (value, gitg_progress_bin_get_fraction (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gitg_progress_bin_set_property (GObject * object,
                                      guint property_id,
                                      const GValue * value,
                                      GParamSpec * pspec)
{
	GitgProgressBin * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GITG_TYPE_PROGRESS_BIN, GitgProgressBin);
	switch (property_id) {
		case GITG_PROGRESS_BIN_FRACTION_PROPERTY:
		gitg_progress_bin_set_fraction (self, g_value_get_double (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

