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

/*
Copyright (C) 2012 Johan Mattsson

This library is free software; you can redistribute it and/or modify 
it under the terms of the GNU Lesser General Public License as 
published by the Free Software Foundation; either version 3 of the 
License, or (at your option) any later version.

This library 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 
Lesser General Public License for more details.
*/

#include "birdfont.h"
#include <glib.h>
#include <float.h>
#include <math.h>
#include <cairo-gobject.h>
#include <glib-object.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

enum  {
	BIRD_FONT_MENU_ACTION_0_PROPERTY,
	BIRD_FONT_MENU_ACTION_NUM_PROPERTIES
};
static GParamSpec* bird_font_menu_action_properties[BIRD_FONT_MENU_ACTION_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	BIRD_FONT_MENU_ACTION_ACTION_SIGNAL,
	BIRD_FONT_MENU_ACTION_NUM_SIGNALS
};
static guint bird_font_menu_action_signals[BIRD_FONT_MENU_ACTION_NUM_SIGNALS] = {0};

struct _BirdFontMenuActionPrivate {
	gboolean selected;
};

static gint BirdFontMenuAction_private_offset;
static gpointer bird_font_menu_action_parent_class = NULL;

static void bird_font_menu_action_real_draw (BirdFontMenuAction* self,
                                      gdouble x,
                                      gdouble y,
                                      cairo_t* cr);
static void bird_font_menu_action_finalize (GObject * obj);
static GType bird_font_menu_action_get_type_once (void);

static inline gpointer
bird_font_menu_action_get_instance_private (BirdFontMenuAction* self)
{
	return G_STRUCT_MEMBER_P (self, BirdFontMenuAction_private_offset);
}

BirdFontMenuAction*
bird_font_menu_action_construct (GType object_type,
                                 const gchar* label)
{
	BirdFontMenuAction * self = NULL;
	gchar* _tmp0_;
	g_return_val_if_fail (label != NULL, NULL);
	self = (BirdFontMenuAction*) g_object_new (object_type, NULL);
	_tmp0_ = g_strdup (label);
	_g_free0 (self->label);
	self->label = _tmp0_;
	return self;
}

BirdFontMenuAction*
bird_font_menu_action_new (const gchar* label)
{
	return bird_font_menu_action_construct (BIRD_FONT_TYPE_MENU_ACTION, label);
}

void
bird_font_menu_action_set_selected (BirdFontMenuAction* self,
                                    gboolean s)
{
	g_return_if_fail (self != NULL);
	self->priv->selected = s;
}

static void
bird_font_menu_action_real_draw (BirdFontMenuAction* self,
                                 gdouble x,
                                 gdouble y,
                                 cairo_t* cr)
{
	const gchar* _tmp0_;
	BirdFontText* _tmp1_;
	BirdFontText* _tmp2_;
	BirdFontText* _tmp3_;
	g_return_if_fail (cr != NULL);
	if (self->priv->selected) {
		cairo_save (cr);
		bird_font_theme_color (cr, "Highlighted 1");
		cairo_rectangle (cr, x - 2, y - 12, self->width, (gdouble) 15);
		cairo_fill_preserve (cr);
		cairo_stroke (cr);
		cairo_restore (cr);
	}
	if (self->has_delete_button) {
		cairo_save (cr);
		bird_font_theme_color (cr, "Foreground 1");
		cairo_move_to (cr, (x + self->width) - 10, y - 2);
		cairo_line_to (cr, ((x + self->width) - 10) - 5, (y - 2) - 5);
		cairo_move_to (cr, ((x + self->width) - 10) - 5, y - 2);
		cairo_line_to (cr, (x + self->width) - 10, (y - 2) - 5);
		cairo_set_line_width (cr, (gdouble) 1);
		cairo_stroke (cr);
		cairo_restore (cr);
	}
	_tmp0_ = self->label;
	_tmp1_ = bird_font_text_new (_tmp0_, (gdouble) 17, (gdouble) 0);
	_g_object_unref0 (self->text);
	self->text = _tmp1_;
	_tmp2_ = self->text;
	bird_font_theme_text_color (_tmp2_, "Foreground 1");
	_tmp3_ = self->text;
	bird_font_text_draw_at_baseline (_tmp3_, cr, x, y, "");
}

void
bird_font_menu_action_draw (BirdFontMenuAction* self,
                            gdouble x,
                            gdouble y,
                            cairo_t* cr)
{
	BirdFontMenuActionClass* _klass_;
	g_return_if_fail (self != NULL);
	_klass_ = BIRD_FONT_MENU_ACTION_GET_CLASS (self);
	if (_klass_->draw) {
		_klass_->draw (self, x, y, cr);
	}
}

static void
bird_font_menu_action_class_init (BirdFontMenuActionClass * klass,
                                  gpointer klass_data)
{
	bird_font_menu_action_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BirdFontMenuAction_private_offset);
	((BirdFontMenuActionClass *) klass)->draw = (void (*) (BirdFontMenuAction*, gdouble, gdouble, cairo_t*)) bird_font_menu_action_real_draw;
	G_OBJECT_CLASS (klass)->finalize = bird_font_menu_action_finalize;
	bird_font_menu_action_signals[BIRD_FONT_MENU_ACTION_ACTION_SIGNAL] = g_signal_new ("action", BIRD_FONT_TYPE_MENU_ACTION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, BIRD_FONT_TYPE_MENU_ACTION);
}

static void
bird_font_menu_action_instance_init (BirdFontMenuAction * self,
                                     gpointer klass)
{
	self->priv = bird_font_menu_action_get_instance_private (self);
	self->index = -1;
	self->has_delete_button = TRUE;
	self->width = (gdouble) 100;
	self->priv->selected = FALSE;
}

static void
bird_font_menu_action_finalize (GObject * obj)
{
	BirdFontMenuAction * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_MENU_ACTION, BirdFontMenuAction);
	_g_free0 (self->label);
	_g_object_unref0 (self->text);
	G_OBJECT_CLASS (bird_font_menu_action_parent_class)->finalize (obj);
}

static GType
bird_font_menu_action_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontMenuActionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_menu_action_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontMenuAction), 0, (GInstanceInitFunc) bird_font_menu_action_instance_init, NULL };
	GType bird_font_menu_action_type_id;
	bird_font_menu_action_type_id = g_type_register_static (G_TYPE_OBJECT, "BirdFontMenuAction", &g_define_type_info, 0);
	BirdFontMenuAction_private_offset = g_type_add_instance_private (bird_font_menu_action_type_id, sizeof (BirdFontMenuActionPrivate));
	return bird_font_menu_action_type_id;
}

GType
bird_font_menu_action_get_type (void)
{
	static volatile gsize bird_font_menu_action_type_id__once = 0;
	if (g_once_init_enter (&bird_font_menu_action_type_id__once)) {
		GType bird_font_menu_action_type_id;
		bird_font_menu_action_type_id = bird_font_menu_action_get_type_once ();
		g_once_init_leave (&bird_font_menu_action_type_id__once, bird_font_menu_action_type_id);
	}
	return bird_font_menu_action_type_id__once;
}

