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

/*
* Copyright (c) 2017 Felipe Escoto (https://github.com/Philip-Scott/Notes-up)
*
* 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 2 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Authored by: Felipe Escoto <felescoto95@hotmail.com>
*/

#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib.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 ENOTES_TYPE_HELP_BOX (enotes_help_box_get_type ())
#define ENOTES_HELP_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ENOTES_TYPE_HELP_BOX, ENotesHelpBox))
#define ENOTES_HELP_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ENOTES_TYPE_HELP_BOX, ENotesHelpBoxClass))
#define ENOTES_IS_HELP_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ENOTES_TYPE_HELP_BOX))
#define ENOTES_IS_HELP_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ENOTES_TYPE_HELP_BOX))
#define ENOTES_HELP_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ENOTES_TYPE_HELP_BOX, ENotesHelpBoxClass))

typedef struct _ENotesHelpBox ENotesHelpBox;
typedef struct _ENotesHelpBoxClass ENotesHelpBoxClass;
typedef struct _ENotesHelpBoxPrivate ENotesHelpBoxPrivate;
enum  {
	ENOTES_HELP_BOX_0_PROPERTY,
	ENOTES_HELP_BOX_NUM_PROPERTIES
};
static GParamSpec* enotes_help_box_properties[ENOTES_HELP_BOX_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))
typedef struct _Block3Data Block3Data;
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
enum  {
	ENOTES_HELP_BOX_INSERT_REQUESTED_SIGNAL,
	ENOTES_HELP_BOX_NUM_SIGNALS
};
static guint enotes_help_box_signals[ENOTES_HELP_BOX_NUM_SIGNALS] = {0};

struct _ENotesHelpBox {
	GtkRevealer parent_instance;
	ENotesHelpBoxPrivate * priv;
};

struct _ENotesHelpBoxClass {
	GtkRevealerClass parent_class;
};

struct _ENotesHelpBoxPrivate {
	GtkGrid* grid;
	gint row;
};

struct _Block3Data {
	int _ref_count_;
	ENotesHelpBox* self;
	gchar* _code;
};

static gint ENotesHelpBox_private_offset;
static gpointer enotes_help_box_parent_class = NULL;

VALA_EXTERN GType enotes_help_box_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesHelpBox, g_object_unref)
VALA_EXTERN ENotesHelpBox* enotes_help_box_new (void);
VALA_EXTERN ENotesHelpBox* enotes_help_box_construct (GType object_type);
static void enotes_help_box_add_item (ENotesHelpBox* self,
                               const gchar* _name,
                               const gchar* _style_class,
                               const gchar* _code);
static Block3Data* block3_data_ref (Block3Data* _data3_);
static void block3_data_unref (void * _userdata_);
static void __lambda9_ (Block3Data* _data3_);
static void ___lambda9__gtk_button_clicked (GtkButton* _sender,
                                     gpointer self);
static void enotes_help_box_finalize (GObject * obj);
static GType enotes_help_box_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
enotes_help_box_get_instance_private (ENotesHelpBox* self)
{
	return G_STRUCT_MEMBER_P (self, ENotesHelpBox_private_offset);
}

ENotesHelpBox*
enotes_help_box_construct (GType object_type)
{
	ENotesHelpBox * self = NULL;
	GtkGrid* _tmp0_;
	GtkGrid* _tmp1_;
	GtkGrid* _tmp2_;
	GtkScrolledWindow* scroll_box = NULL;
	GtkScrolledWindow* _tmp3_;
	GtkStyleContext* _tmp4_;
	GtkGrid* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	self = (ENotesHelpBox*) g_object_new (object_type, NULL);
	gtk_revealer_set_transition_type ((GtkRevealer*) self, GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT);
	_tmp0_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->grid);
	self->priv->grid = _tmp0_;
	_tmp1_ = self->priv->grid;
	g_object_set ((GtkWidget*) _tmp1_, "margin", 12, NULL);
	_tmp2_ = self->priv->grid;
	g_object_set ((GtkWidget*) _tmp2_, "expand", FALSE, NULL);
	_tmp3_ = (GtkScrolledWindow*) gtk_scrolled_window_new (NULL, NULL);
	g_object_ref_sink (_tmp3_);
	scroll_box = _tmp3_;
	_tmp4_ = gtk_widget_get_style_context ((GtkWidget*) scroll_box);
	gtk_style_context_add_class (_tmp4_, "list");
	g_object_set (scroll_box, "hscrollbar-policy", GTK_POLICY_NEVER, NULL);
	_tmp5_ = self->priv->grid;
	gtk_container_add ((GtkContainer*) scroll_box, (GtkWidget*) _tmp5_);
	enotes_help_box_add_item (self, _ ("Large Header"), "h1", "\n# ");
	enotes_help_box_add_item (self, _ ("Medium Header"), "h2", "\n## ");
	enotes_help_box_add_item (self, _ ("Small Header"), "h3", "\n### ");
	enotes_help_box_add_item (self, _ ("<i>Italic</i>"), "", _ ("_italic_"));
	enotes_help_box_add_item (self, _ ("<b>Bold</b>"), "", _ ("**bold**"));
	enotes_help_box_add_item (self, _ ("<s>Strike</s>"), "", _ ("~~strike~~"));
	enotes_help_box_add_item (self, _ ("|  <i>quote</i>"), "", "> ");
	enotes_help_box_add_item (self, _ ("1. Numbered list"), "", "\n1. ");
	enotes_help_box_add_item (self, _ ("⚫ Bulleted list"), "", "\n- ");
	enotes_help_box_add_item (self, _ ("Divider"), "", "\n\n-----\n");
	enotes_help_box_add_item (self, _ ("Code"), "", "` code ` ");
	enotes_help_box_add_item (self, _ ("Code Block"), "", "\n\n```\n code \n```");
	enotes_help_box_add_item (self, _ ("Link"), "", _ ("[Text](www...) "));
	enotes_help_box_add_item (self, _ ("Citation Anchor"), "", "[^1]");
	_tmp6_ = g_strconcat ("\n", _ ("[^1]: text"), NULL);
	_tmp7_ = _tmp6_;
	enotes_help_box_add_item (self, _ ("Citation Text"), "", _tmp7_);
	_g_free0 (_tmp7_);
	enotes_help_box_add_item (self, _ ("Youtube Video"), "", _ ("<youtube [link]>"));
	enotes_help_box_add_item (self, _ ("Page Break (when exporting)"), "", "<break>");
	enotes_help_box_add_item (self, _ ("Enable Syntax Highlighting"), "", "<highlight>");
	enotes_help_box_add_item (self, _ ("Set Color"), "", "<color #0099FF>");
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) scroll_box);
	gtk_widget_show_all ((GtkWidget*) self);
	_g_object_unref0 (scroll_box);
	return self;
}

ENotesHelpBox*
enotes_help_box_new (void)
{
	return enotes_help_box_construct (ENOTES_TYPE_HELP_BOX);
}

static Block3Data*
block3_data_ref (Block3Data* _data3_)
{
	g_atomic_int_inc (&_data3_->_ref_count_);
	return _data3_;
}

static void
block3_data_unref (void * _userdata_)
{
	Block3Data* _data3_;
	_data3_ = (Block3Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data3_->_ref_count_)) {
		ENotesHelpBox* self;
		self = _data3_->self;
		_g_free0 (_data3_->_code);
		_g_object_unref0 (self);
		g_slice_free (Block3Data, _data3_);
	}
}

static gchar*
string_replace (const gchar* self,
                const gchar* old,
                const gchar* replacement)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	if ((*((gchar*) self)) == '\0') {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = (*((gchar*) old)) == '\0';
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_strcmp0 (old, replacement) == 0;
	}
	if (_tmp0_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (self);
		result = _tmp2_;
		return result;
	}
	{
		GRegex* regex = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_;
		GRegex* _tmp5_;
		GRegex* _tmp6_;
		gchar* _tmp7_ = NULL;
		GRegex* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp3_ = g_regex_escape_string (old, -1);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_regex_new (_tmp4_, 0, 0, &_inner_error0_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		regex = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp8_ = regex;
		_tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error0_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		result = _tmp10_;
		_g_free0 (_tmp7_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		g_assert_not_reached ();
	}
	__finally0:
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
	g_clear_error (&_inner_error0_);
	return NULL;
}

static void
__lambda9_ (Block3Data* _data3_)
{
	ENotesHelpBox* self;
	self = _data3_->self;
	g_signal_emit (self, enotes_help_box_signals[ENOTES_HELP_BOX_INSERT_REQUESTED_SIGNAL], 0, _data3_->_code);
}

static void
___lambda9__gtk_button_clicked (GtkButton* _sender,
                                gpointer self)
{
	__lambda9_ (self);
}

static void
enotes_help_box_add_item (ENotesHelpBox* self,
                          const gchar* _name,
                          const gchar* _style_class,
                          const gchar* _code)
{
	Block3Data* _data3_;
	gchar* _tmp0_;
	GtkLabel* title = NULL;
	GtkLabel* _tmp1_;
	GtkLabel* _tmp2_;
	GtkLabel* _tmp3_;
	GtkLabel* code = NULL;
	gchar* _tmp6_;
	gchar* _tmp7_;
	GtkLabel* _tmp8_;
	GtkLabel* _tmp9_;
	GtkStyleContext* _tmp10_;
	GtkStyleContext* _tmp11_;
	GtkButton* item_button = NULL;
	GtkButton* _tmp12_;
	GtkStyleContext* _tmp13_;
	GtkGrid* item_grid = NULL;
	GtkGrid* _tmp14_;
	GtkLabel* _tmp15_;
	GtkGrid* _tmp16_;
	GtkButton* _tmp17_;
	gint _tmp18_;
	GtkGrid* _tmp19_;
	GtkSeparator* _tmp20_;
	GtkSeparator* _tmp21_;
	gint _tmp22_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (_name != NULL);
	g_return_if_fail (_style_class != NULL);
	g_return_if_fail (_code != NULL);
	_data3_ = g_slice_new0 (Block3Data);
	_data3_->_ref_count_ = 1;
	_data3_->self = g_object_ref (self);
	_tmp0_ = g_strdup (_code);
	_g_free0 (_data3_->_code);
	_data3_->_code = _tmp0_;
	_tmp1_ = (GtkLabel*) gtk_label_new (_name);
	g_object_ref_sink (_tmp1_);
	title = _tmp1_;
	_tmp2_ = title;
	gtk_widget_set_halign ((GtkWidget*) _tmp2_, GTK_ALIGN_START);
	_tmp3_ = title;
	gtk_label_set_use_markup (_tmp3_, TRUE);
	if (g_strcmp0 (_style_class, "") != 0) {
		GtkLabel* _tmp4_;
		GtkStyleContext* _tmp5_;
		_tmp4_ = title;
		_tmp5_ = gtk_widget_get_style_context ((GtkWidget*) _tmp4_);
		gtk_style_context_add_class (_tmp5_, _style_class);
	}
	_tmp6_ = string_replace (_data3_->_code, "\n", "");
	_tmp7_ = _tmp6_;
	_tmp8_ = (GtkLabel*) gtk_label_new (_tmp7_);
	g_object_ref_sink (_tmp8_);
	_tmp9_ = _tmp8_;
	_g_free0 (_tmp7_);
	code = _tmp9_;
	gtk_widget_set_hexpand ((GtkWidget*) code, TRUE);
	gtk_widget_set_halign ((GtkWidget*) code, GTK_ALIGN_END);
	gtk_widget_set_valign ((GtkWidget*) code, GTK_ALIGN_CENTER);
	_tmp10_ = gtk_widget_get_style_context ((GtkWidget*) code);
	gtk_style_context_add_class (_tmp10_, "overlay-bar");
	_tmp11_ = gtk_widget_get_style_context ((GtkWidget*) code);
	gtk_style_context_add_class (_tmp11_, "h3");
	_tmp12_ = (GtkButton*) gtk_button_new ();
	g_object_ref_sink (_tmp12_);
	item_button = _tmp12_;
	_tmp13_ = gtk_widget_get_style_context ((GtkWidget*) item_button);
	gtk_style_context_add_class (_tmp13_, "flat");
	g_signal_connect_data (item_button, "clicked", (GCallback) ___lambda9__gtk_button_clicked, block3_data_ref (_data3_), (GClosureNotify) block3_data_unref, 0);
	_tmp14_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp14_);
	item_grid = _tmp14_;
	gtk_orientable_set_orientation ((GtkOrientable*) item_grid, GTK_ORIENTATION_HORIZONTAL);
	gtk_grid_set_column_spacing (item_grid, 6);
	_tmp15_ = title;
	gtk_container_add ((GtkContainer*) item_grid, (GtkWidget*) _tmp15_);
	gtk_container_add ((GtkContainer*) item_grid, (GtkWidget*) code);
	gtk_container_add ((GtkContainer*) item_button, (GtkWidget*) item_grid);
	_tmp16_ = self->priv->grid;
	_tmp17_ = item_button;
	_tmp18_ = self->priv->row;
	self->priv->row = _tmp18_ + 1;
	gtk_grid_attach (_tmp16_, (GtkWidget*) _tmp17_, 0, _tmp18_, 1, 1);
	_tmp19_ = self->priv->grid;
	_tmp20_ = (GtkSeparator*) gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
	g_object_ref_sink (_tmp20_);
	_tmp21_ = _tmp20_;
	_tmp22_ = self->priv->row;
	self->priv->row = _tmp22_ + 1;
	gtk_grid_attach (_tmp19_, (GtkWidget*) _tmp21_, 0, _tmp22_, 1, 1);
	_g_object_unref0 (_tmp21_);
	_g_object_unref0 (item_grid);
	_g_object_unref0 (item_button);
	_g_object_unref0 (code);
	_g_object_unref0 (title);
	block3_data_unref (_data3_);
	_data3_ = NULL;
}

static void
enotes_help_box_class_init (ENotesHelpBoxClass * klass,
                            gpointer klass_data)
{
	enotes_help_box_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ENotesHelpBox_private_offset);
	G_OBJECT_CLASS (klass)->finalize = enotes_help_box_finalize;
	enotes_help_box_signals[ENOTES_HELP_BOX_INSERT_REQUESTED_SIGNAL] = g_signal_new ("insert-requested", ENOTES_TYPE_HELP_BOX, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
}

static void
enotes_help_box_instance_init (ENotesHelpBox * self,
                               gpointer klass)
{
	self->priv = enotes_help_box_get_instance_private (self);
	self->priv->row = 0;
}

static void
enotes_help_box_finalize (GObject * obj)
{
	ENotesHelpBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, ENOTES_TYPE_HELP_BOX, ENotesHelpBox);
	_g_object_unref0 (self->priv->grid);
	G_OBJECT_CLASS (enotes_help_box_parent_class)->finalize (obj);
}

static GType
enotes_help_box_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ENotesHelpBoxClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) enotes_help_box_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ENotesHelpBox), 0, (GInstanceInitFunc) enotes_help_box_instance_init, NULL };
	GType enotes_help_box_type_id;
	enotes_help_box_type_id = g_type_register_static (gtk_revealer_get_type (), "ENotesHelpBox", &g_define_type_info, 0);
	ENotesHelpBox_private_offset = g_type_add_instance_private (enotes_help_box_type_id, sizeof (ENotesHelpBoxPrivate));
	return enotes_help_box_type_id;
}

GType
enotes_help_box_get_type (void)
{
	static volatile gsize enotes_help_box_type_id__once = 0;
	if (g_once_init_enter (&enotes_help_box_type_id__once)) {
		GType enotes_help_box_type_id;
		enotes_help_box_type_id = enotes_help_box_get_type_once ();
		g_once_init_leave (&enotes_help_box_type_id__once, enotes_help_box_type_id);
	}
	return enotes_help_box_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;
}

