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

/*
 * Copyright 2011-2020 elementary, Inc. (https://elementary.io)
 *
 * 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.
 * 
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Maxwell Barvian
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.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 CALENDAR_WIDGETS_TYPE_DATE_SWITCHER (calendar_widgets_date_switcher_get_type ())
#define CALENDAR_WIDGETS_DATE_SWITCHER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CALENDAR_WIDGETS_TYPE_DATE_SWITCHER, CalendarWidgetsDateSwitcher))
#define CALENDAR_WIDGETS_DATE_SWITCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CALENDAR_WIDGETS_TYPE_DATE_SWITCHER, CalendarWidgetsDateSwitcherClass))
#define CALENDAR_WIDGETS_IS_DATE_SWITCHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CALENDAR_WIDGETS_TYPE_DATE_SWITCHER))
#define CALENDAR_WIDGETS_IS_DATE_SWITCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CALENDAR_WIDGETS_TYPE_DATE_SWITCHER))
#define CALENDAR_WIDGETS_DATE_SWITCHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CALENDAR_WIDGETS_TYPE_DATE_SWITCHER, CalendarWidgetsDateSwitcherClass))

typedef struct _CalendarWidgetsDateSwitcher CalendarWidgetsDateSwitcher;
typedef struct _CalendarWidgetsDateSwitcherClass CalendarWidgetsDateSwitcherClass;
typedef struct _CalendarWidgetsDateSwitcherPrivate CalendarWidgetsDateSwitcherPrivate;
enum  {
	CALENDAR_WIDGETS_DATE_SWITCHER_0_PROPERTY,
	CALENDAR_WIDGETS_DATE_SWITCHER_WIDTH_CHARS_PROPERTY,
	CALENDAR_WIDGETS_DATE_SWITCHER_TEXT_PROPERTY,
	CALENDAR_WIDGETS_DATE_SWITCHER_NUM_PROPERTIES
};
static GParamSpec* calendar_widgets_date_switcher_properties[CALENDAR_WIDGETS_DATE_SWITCHER_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))
enum  {
	CALENDAR_WIDGETS_DATE_SWITCHER_LEFT_CLICKED_SIGNAL,
	CALENDAR_WIDGETS_DATE_SWITCHER_RIGHT_CLICKED_SIGNAL,
	CALENDAR_WIDGETS_DATE_SWITCHER_NUM_SIGNALS
};
static guint calendar_widgets_date_switcher_signals[CALENDAR_WIDGETS_DATE_SWITCHER_NUM_SIGNALS] = {0};

struct _CalendarWidgetsDateSwitcher {
	GtkGrid parent_instance;
	CalendarWidgetsDateSwitcherPrivate * priv;
};

struct _CalendarWidgetsDateSwitcherClass {
	GtkGridClass parent_class;
};

struct _CalendarWidgetsDateSwitcherPrivate {
	gint _width_chars;
	GtkLabel* label;
};

static gint CalendarWidgetsDateSwitcher_private_offset;
static gpointer calendar_widgets_date_switcher_parent_class = NULL;

VALA_EXTERN GType calendar_widgets_date_switcher_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (CalendarWidgetsDateSwitcher, g_object_unref)
VALA_EXTERN CalendarWidgetsDateSwitcher* calendar_widgets_date_switcher_new (gint width_chars);
VALA_EXTERN CalendarWidgetsDateSwitcher* calendar_widgets_date_switcher_construct (GType object_type,
                                                                       gint width_chars);
VALA_EXTERN gint calendar_widgets_date_switcher_get_width_chars (CalendarWidgetsDateSwitcher* self);
static void calendar_widgets_date_switcher_set_width_chars (CalendarWidgetsDateSwitcher* self,
                                                     gint value);
VALA_EXTERN const gchar* calendar_widgets_date_switcher_get_text (CalendarWidgetsDateSwitcher* self);
VALA_EXTERN void calendar_widgets_date_switcher_set_text (CalendarWidgetsDateSwitcher* self,
                                              const gchar* value);
static GObject * calendar_widgets_date_switcher_constructor (GType type,
                                                      guint n_construct_properties,
                                                      GObjectConstructParam * construct_properties);
static void _calendar_widgets_date_switcher___lambda5_ (CalendarWidgetsDateSwitcher* self);
static void __calendar_widgets_date_switcher___lambda5__gtk_button_clicked (GtkButton* _sender,
                                                                     gpointer self);
static void _calendar_widgets_date_switcher___lambda6_ (CalendarWidgetsDateSwitcher* self);
static void __calendar_widgets_date_switcher___lambda6__gtk_button_clicked (GtkButton* _sender,
                                                                     gpointer self);
static void calendar_widgets_date_switcher_finalize (GObject * obj);
static GType calendar_widgets_date_switcher_get_type_once (void);
static void _vala_calendar_widgets_date_switcher_get_property (GObject * object,
                                                        guint property_id,
                                                        GValue * value,
                                                        GParamSpec * pspec);
static void _vala_calendar_widgets_date_switcher_set_property (GObject * object,
                                                        guint property_id,
                                                        const GValue * value,
                                                        GParamSpec * pspec);

static inline gpointer
calendar_widgets_date_switcher_get_instance_private (CalendarWidgetsDateSwitcher* self)
{
	return G_STRUCT_MEMBER_P (self, CalendarWidgetsDateSwitcher_private_offset);
}

CalendarWidgetsDateSwitcher*
calendar_widgets_date_switcher_construct (GType object_type,
                                          gint width_chars)
{
	CalendarWidgetsDateSwitcher * self = NULL;
	self = (CalendarWidgetsDateSwitcher*) g_object_new (object_type, "width-chars", width_chars, NULL);
	return self;
}

CalendarWidgetsDateSwitcher*
calendar_widgets_date_switcher_new (gint width_chars)
{
	return calendar_widgets_date_switcher_construct (CALENDAR_WIDGETS_TYPE_DATE_SWITCHER, width_chars);
}

gint
calendar_widgets_date_switcher_get_width_chars (CalendarWidgetsDateSwitcher* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	result = self->priv->_width_chars;
	return result;
}

static void
calendar_widgets_date_switcher_set_width_chars (CalendarWidgetsDateSwitcher* self,
                                                gint value)
{
	gint old_value;
	g_return_if_fail (self != NULL);
	old_value = calendar_widgets_date_switcher_get_width_chars (self);
	if (old_value != value) {
		self->priv->_width_chars = value;
		g_object_notify_by_pspec ((GObject *) self, calendar_widgets_date_switcher_properties[CALENDAR_WIDGETS_DATE_SWITCHER_WIDTH_CHARS_PROPERTY]);
	}
}

const gchar*
calendar_widgets_date_switcher_get_text (CalendarWidgetsDateSwitcher* self)
{
	const gchar* result;
	GtkLabel* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->label;
	_tmp1_ = gtk_label_get_label (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < ((glong) 0)) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}

static gint
string_index_of_nth_char (const gchar* self,
                          glong c)
{
	gchar* _tmp0_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	_tmp0_ = g_utf8_offset_to_pointer (self, c);
	result = (gint) (_tmp0_ - ((gchar*) self));
	return result;
}

static gunichar
string_get_char (const gchar* self,
                 glong index)
{
	gunichar result;
	g_return_val_if_fail (self != NULL, 0U);
	result = g_utf8_get_char (((gchar*) self) + index);
	return result;
}

static gchar*
g_unichar_to_string (gunichar self)
{
	gchar* str = NULL;
	gchar* _tmp0_;
	gchar* result;
	_tmp0_ = g_new0 (gchar, 7);
	str = (gchar*) _tmp0_;
	g_unichar_to_utf8 (self, str);
	result = str;
	return result;
}

void
calendar_widgets_date_switcher_set_text (CalendarWidgetsDateSwitcher* self,
                                         const gchar* value)
{
	gchar* new_value = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	GtkLabel* _tmp5_;
	const gchar* _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp0_ = string_substring (value, (glong) string_index_of_nth_char (value, (glong) 1), (glong) -1);
	new_value = _tmp0_;
	_tmp1_ = g_unichar_to_string (g_unichar_totitle (string_get_char (value, (glong) 0)));
	_tmp2_ = _tmp1_;
	_tmp3_ = new_value;
	_tmp4_ = g_strconcat (_tmp2_, _tmp3_, NULL);
	_g_free0 (new_value);
	new_value = _tmp4_;
	_g_free0 (_tmp2_);
	_tmp5_ = self->priv->label;
	_tmp6_ = new_value;
	gtk_label_set_label (_tmp5_, _tmp6_);
	_g_free0 (new_value);
	g_object_notify_by_pspec ((GObject *) self, calendar_widgets_date_switcher_properties[CALENDAR_WIDGETS_DATE_SWITCHER_TEXT_PROPERTY]);
}

static void
_calendar_widgets_date_switcher___lambda5_ (CalendarWidgetsDateSwitcher* self)
{
	g_signal_emit (self, calendar_widgets_date_switcher_signals[CALENDAR_WIDGETS_DATE_SWITCHER_LEFT_CLICKED_SIGNAL], 0);
}

static void
__calendar_widgets_date_switcher___lambda5__gtk_button_clicked (GtkButton* _sender,
                                                                gpointer self)
{
	_calendar_widgets_date_switcher___lambda5_ ((CalendarWidgetsDateSwitcher*) self);
}

static void
_calendar_widgets_date_switcher___lambda6_ (CalendarWidgetsDateSwitcher* self)
{
	g_signal_emit (self, calendar_widgets_date_switcher_signals[CALENDAR_WIDGETS_DATE_SWITCHER_RIGHT_CLICKED_SIGNAL], 0);
}

static void
__calendar_widgets_date_switcher___lambda6__gtk_button_clicked (GtkButton* _sender,
                                                                gpointer self)
{
	_calendar_widgets_date_switcher___lambda6_ ((CalendarWidgetsDateSwitcher*) self);
}

static GObject *
calendar_widgets_date_switcher_constructor (GType type,
                                            guint n_construct_properties,
                                            GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	CalendarWidgetsDateSwitcher * self;
	GtkButton* start_button = NULL;
	GtkButton* _tmp0_;
	GtkButton* end_button = NULL;
	GtkButton* _tmp1_;
	gint _tmp2_;
	GtkLabel* _tmp3_ = NULL;
	GtkButton* center_button = NULL;
	GtkButton* _tmp4_;
	GtkButton* _tmp5_;
	GtkLabel* _tmp6_;
	GtkStyleContext* _tmp7_;
	GtkButton* _tmp8_;
	GtkButton* _tmp9_;
	GtkButton* _tmp10_;
	GtkButton* _tmp11_;
	GtkButton* _tmp12_;
	parent_class = G_OBJECT_CLASS (calendar_widgets_date_switcher_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CALENDAR_WIDGETS_TYPE_DATE_SWITCHER, CalendarWidgetsDateSwitcher);
	_tmp0_ = (GtkButton*) gtk_button_new_from_icon_name ("pan-start-symbolic", (GtkIconSize) GTK_ICON_SIZE_MENU);
	g_object_ref_sink (_tmp0_);
	start_button = _tmp0_;
	_tmp1_ = (GtkButton*) gtk_button_new_from_icon_name ("pan-end-symbolic", (GtkIconSize) GTK_ICON_SIZE_MENU);
	g_object_ref_sink (_tmp1_);
	end_button = _tmp1_;
	_tmp2_ = self->priv->_width_chars;
	_tmp3_ = (GtkLabel*) gtk_label_new (NULL);
	gtk_label_set_width_chars (_tmp3_, _tmp2_);
	g_object_ref_sink (_tmp3_);
	_g_object_unref0 (self->priv->label);
	self->priv->label = _tmp3_;
	_tmp4_ = (GtkButton*) gtk_button_new ();
	g_object_ref_sink (_tmp4_);
	center_button = _tmp4_;
	_tmp5_ = center_button;
	_tmp6_ = self->priv->label;
	gtk_container_add ((GtkContainer*) _tmp5_, (GtkWidget*) _tmp6_);
	_tmp7_ = gtk_widget_get_style_context ((GtkWidget*) self);
	gtk_style_context_add_class (_tmp7_, GTK_STYLE_CLASS_LINKED);
	_tmp8_ = start_button;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp8_);
	_tmp9_ = center_button;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp9_);
	_tmp10_ = end_button;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp10_);
	_tmp11_ = start_button;
	g_signal_connect_object (_tmp11_, "clicked", (GCallback) __calendar_widgets_date_switcher___lambda5__gtk_button_clicked, self, 0);
	_tmp12_ = end_button;
	g_signal_connect_object (_tmp12_, "clicked", (GCallback) __calendar_widgets_date_switcher___lambda6__gtk_button_clicked, self, 0);
	_g_object_unref0 (center_button);
	_g_object_unref0 (end_button);
	_g_object_unref0 (start_button);
	return obj;
}

static void
calendar_widgets_date_switcher_class_init (CalendarWidgetsDateSwitcherClass * klass,
                                           gpointer klass_data)
{
	calendar_widgets_date_switcher_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &CalendarWidgetsDateSwitcher_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_calendar_widgets_date_switcher_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_calendar_widgets_date_switcher_set_property;
	G_OBJECT_CLASS (klass)->constructor = calendar_widgets_date_switcher_constructor;
	G_OBJECT_CLASS (klass)->finalize = calendar_widgets_date_switcher_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), CALENDAR_WIDGETS_DATE_SWITCHER_WIDTH_CHARS_PROPERTY, calendar_widgets_date_switcher_properties[CALENDAR_WIDGETS_DATE_SWITCHER_WIDTH_CHARS_PROPERTY] = g_param_spec_int ("width-chars", "width-chars", "width-chars", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), CALENDAR_WIDGETS_DATE_SWITCHER_TEXT_PROPERTY, calendar_widgets_date_switcher_properties[CALENDAR_WIDGETS_DATE_SWITCHER_TEXT_PROPERTY] = g_param_spec_string ("text", "text", "text", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	calendar_widgets_date_switcher_signals[CALENDAR_WIDGETS_DATE_SWITCHER_LEFT_CLICKED_SIGNAL] = g_signal_new ("left-clicked", CALENDAR_WIDGETS_TYPE_DATE_SWITCHER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	calendar_widgets_date_switcher_signals[CALENDAR_WIDGETS_DATE_SWITCHER_RIGHT_CLICKED_SIGNAL] = g_signal_new ("right-clicked", CALENDAR_WIDGETS_TYPE_DATE_SWITCHER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
calendar_widgets_date_switcher_instance_init (CalendarWidgetsDateSwitcher * self,
                                              gpointer klass)
{
	self->priv = calendar_widgets_date_switcher_get_instance_private (self);
}

static void
calendar_widgets_date_switcher_finalize (GObject * obj)
{
	CalendarWidgetsDateSwitcher * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CALENDAR_WIDGETS_TYPE_DATE_SWITCHER, CalendarWidgetsDateSwitcher);
	_g_object_unref0 (self->priv->label);
	G_OBJECT_CLASS (calendar_widgets_date_switcher_parent_class)->finalize (obj);
}

static GType
calendar_widgets_date_switcher_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (CalendarWidgetsDateSwitcherClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) calendar_widgets_date_switcher_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (CalendarWidgetsDateSwitcher), 0, (GInstanceInitFunc) calendar_widgets_date_switcher_instance_init, NULL };
	GType calendar_widgets_date_switcher_type_id;
	calendar_widgets_date_switcher_type_id = g_type_register_static (gtk_grid_get_type (), "CalendarWidgetsDateSwitcher", &g_define_type_info, 0);
	CalendarWidgetsDateSwitcher_private_offset = g_type_add_instance_private (calendar_widgets_date_switcher_type_id, sizeof (CalendarWidgetsDateSwitcherPrivate));
	return calendar_widgets_date_switcher_type_id;
}

GType
calendar_widgets_date_switcher_get_type (void)
{
	static volatile gsize calendar_widgets_date_switcher_type_id__once = 0;
	if (g_once_init_enter (&calendar_widgets_date_switcher_type_id__once)) {
		GType calendar_widgets_date_switcher_type_id;
		calendar_widgets_date_switcher_type_id = calendar_widgets_date_switcher_get_type_once ();
		g_once_init_leave (&calendar_widgets_date_switcher_type_id__once, calendar_widgets_date_switcher_type_id);
	}
	return calendar_widgets_date_switcher_type_id__once;
}

static void
_vala_calendar_widgets_date_switcher_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec)
{
	CalendarWidgetsDateSwitcher * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, CALENDAR_WIDGETS_TYPE_DATE_SWITCHER, CalendarWidgetsDateSwitcher);
	switch (property_id) {
		case CALENDAR_WIDGETS_DATE_SWITCHER_WIDTH_CHARS_PROPERTY:
		g_value_set_int (value, calendar_widgets_date_switcher_get_width_chars (self));
		break;
		case CALENDAR_WIDGETS_DATE_SWITCHER_TEXT_PROPERTY:
		g_value_set_string (value, calendar_widgets_date_switcher_get_text (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_calendar_widgets_date_switcher_set_property (GObject * object,
                                                   guint property_id,
                                                   const GValue * value,
                                                   GParamSpec * pspec)
{
	CalendarWidgetsDateSwitcher * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, CALENDAR_WIDGETS_TYPE_DATE_SWITCHER, CalendarWidgetsDateSwitcher);
	switch (property_id) {
		case CALENDAR_WIDGETS_DATE_SWITCHER_WIDTH_CHARS_PROPERTY:
		calendar_widgets_date_switcher_set_width_chars (self, g_value_get_int (value));
		break;
		case CALENDAR_WIDGETS_DATE_SWITCHER_TEXT_PROPERTY:
		calendar_widgets_date_switcher_set_text (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

