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

/*
* Copyright (c) 2020-2026 (https://github.com/phase1geo/Outliner)
*
* 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., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* Authored by: Trevor Williams <phase1geo@gmail.com>
*/

#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.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 TYPE_TEXT_PARSER (text_parser_get_type ())
#define TEXT_PARSER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEXT_PARSER, TextParser))
#define TEXT_PARSER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEXT_PARSER, TextParserClass))
#define IS_TEXT_PARSER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEXT_PARSER))
#define IS_TEXT_PARSER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEXT_PARSER))
#define TEXT_PARSER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEXT_PARSER, TextParserClass))

typedef struct _TextParser TextParser;
typedef struct _TextParserClass TextParserClass;
typedef struct _TextParserPrivate TextParserPrivate;
typedef enum  {
	FORMAT_TAG_BOLD = 0,
	FORMAT_TAG_ITALICS,
	FORMAT_TAG_UNDERLINE,
	FORMAT_TAG_STRIKETHRU,
	FORMAT_TAG_CODE,
	FORMAT_TAG_SUB,
	FORMAT_TAG_SUPER,
	FORMAT_TAG_HEADER,
	FORMAT_TAG_COLOR,
	FORMAT_TAG_HILITE,
	FORMAT_TAG_URL,
	FORMAT_TAG_SYNTAX,
	FORMAT_TAG_TAG,
	FORMAT_TAG_MATCH,
	FORMAT_TAG_SELECT,
	FORMAT_TAG_LENGTH
} FormatTag;

#define TYPE_FORMAT_TAG (format_tag_get_type ())

#define TYPE_CANVAS_TEXT (canvas_text_get_type ())
#define CANVAS_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CANVAS_TEXT, CanvasText))
#define CANVAS_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CANVAS_TEXT, CanvasTextClass))
#define IS_CANVAS_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CANVAS_TEXT))
#define IS_CANVAS_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CANVAS_TEXT))
#define CANVAS_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CANVAS_TEXT, CanvasTextClass))

typedef struct _CanvasText CanvasText;
typedef struct _CanvasTextClass CanvasTextClass;

#define TYPE_UNDO_BUFFER (undo_buffer_get_type ())
#define UNDO_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_UNDO_BUFFER, UndoBuffer))
#define UNDO_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_UNDO_BUFFER, UndoBufferClass))
#define IS_UNDO_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_UNDO_BUFFER))
#define IS_UNDO_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_UNDO_BUFFER))
#define UNDO_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_UNDO_BUFFER, UndoBufferClass))

typedef struct _UndoBuffer UndoBuffer;
typedef struct _UndoBufferClass UndoBufferClass;

#define TYPE_UNDO_TEXT_BUFFER (undo_text_buffer_get_type ())
#define UNDO_TEXT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_UNDO_TEXT_BUFFER, UndoTextBuffer))
#define UNDO_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_UNDO_TEXT_BUFFER, UndoTextBufferClass))
#define IS_UNDO_TEXT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_UNDO_TEXT_BUFFER))
#define IS_UNDO_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_UNDO_TEXT_BUFFER))
#define UNDO_TEXT_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_UNDO_TEXT_BUFFER, UndoTextBufferClass))

typedef struct _UndoTextBuffer UndoTextBuffer;
typedef struct _UndoTextBufferClass UndoTextBufferClass;

#define TYPE_UNICODE_PARSER (unicode_parser_get_type ())
#define UNICODE_PARSER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_UNICODE_PARSER, UnicodeParser))
#define UNICODE_PARSER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_UNICODE_PARSER, UnicodeParserClass))
#define IS_UNICODE_PARSER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_UNICODE_PARSER))
#define IS_UNICODE_PARSER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_UNICODE_PARSER))
#define UNICODE_PARSER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_UNICODE_PARSER, UnicodeParserClass))

typedef struct _UnicodeParser UnicodeParser;
typedef struct _UnicodeParserClass UnicodeParserClass;
typedef struct _UnicodeParserPrivate UnicodeParserPrivate;

#define TYPE_MIND_MAP (mind_map_get_type ())
#define MIND_MAP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MIND_MAP, MindMap))
#define MIND_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MIND_MAP, MindMapClass))
#define IS_MIND_MAP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MIND_MAP))
#define IS_MIND_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MIND_MAP))
#define MIND_MAP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MIND_MAP, MindMapClass))

typedef struct _MindMap MindMap;
typedef struct _MindMapClass MindMapClass;
#define _mind_map_unref0(var) ((var == NULL) ? NULL : (var = (mind_map_unref (var), NULL)))

#define TYPE_FORMATTED_TEXT (formatted_text_get_type ())
#define FORMATTED_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FORMATTED_TEXT, FormattedText))
#define FORMATTED_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FORMATTED_TEXT, FormattedTextClass))
#define IS_FORMATTED_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FORMATTED_TEXT))
#define IS_FORMATTED_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FORMATTED_TEXT))
#define FORMATTED_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FORMATTED_TEXT, FormattedTextClass))

typedef struct _FormattedText FormattedText;
typedef struct _FormattedTextClass FormattedTextClass;
typedef void (*TextParserTextMatchCallback) (FormattedText* text, GMatchInfo* match_info, gpointer user_data);

#define TYPE_NODE (node_get_type ())
#define NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_NODE, Node))
#define NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_NODE, NodeClass))
#define IS_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_NODE))
#define IS_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_NODE))
#define NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_NODE, NodeClass))

typedef struct _Node Node;
typedef struct _NodeClass NodeClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define TYPE_CALLOUT (callout_get_type ())
#define CALLOUT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CALLOUT, Callout))
#define CALLOUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CALLOUT, CalloutClass))
#define IS_CALLOUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CALLOUT))
#define IS_CALLOUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CALLOUT))
#define CALLOUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CALLOUT, CalloutClass))

typedef struct _Callout Callout;
typedef struct _CalloutClass CalloutClass;
#define _g_free0(var) (var = (g_free (var), NULL))

#define TYPE_DRAW_AREA (draw_area_get_type ())
#define DRAW_AREA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DRAW_AREA, DrawArea))
#define DRAW_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DRAW_AREA, DrawAreaClass))
#define IS_DRAW_AREA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DRAW_AREA))
#define IS_DRAW_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DRAW_AREA))
#define DRAW_AREA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DRAW_AREA, DrawAreaClass))

typedef struct _DrawArea DrawArea;
typedef struct _DrawAreaClass DrawAreaClass;

#define TYPE_TEXT_COMPLETION_ITEM (text_completion_item_get_type ())
#define TEXT_COMPLETION_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEXT_COMPLETION_ITEM, TextCompletionItem))
#define TEXT_COMPLETION_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEXT_COMPLETION_ITEM, TextCompletionItemClass))
#define IS_TEXT_COMPLETION_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEXT_COMPLETION_ITEM))
#define IS_TEXT_COMPLETION_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEXT_COMPLETION_ITEM))
#define TEXT_COMPLETION_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEXT_COMPLETION_ITEM, TextCompletionItemClass))

typedef struct _TextCompletionItem TextCompletionItem;
typedef struct _TextCompletionItemClass TextCompletionItemClass;

#define TYPE_MAIN_WINDOW (main_window_get_type ())
#define MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MAIN_WINDOW, MainWindow))
#define MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MAIN_WINDOW, MainWindowClass))
#define IS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MAIN_WINDOW))
#define IS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MAIN_WINDOW))
#define MAIN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MAIN_WINDOW, MainWindowClass))

typedef struct _MainWindow MainWindow;
typedef struct _MainWindowClass MainWindowClass;

#define TYPE_UNICODE_INSERT (unicode_insert_get_type ())
#define UNICODE_INSERT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_UNICODE_INSERT, UnicodeInsert))
#define UNICODE_INSERT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_UNICODE_INSERT, UnicodeInsertClass))
#define IS_UNICODE_INSERT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_UNICODE_INSERT))
#define IS_UNICODE_INSERT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_UNICODE_INSERT))
#define UNICODE_INSERT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_UNICODE_INSERT, UnicodeInsertClass))

typedef struct _UnicodeInsert UnicodeInsert;
typedef struct _UnicodeInsertClass UnicodeInsertClass;

struct _TextParser {
	GTypeInstance parent_instance;
	volatile int ref_count;
	TextParserPrivate * priv;
};

struct _TextParserClass {
	GTypeClass parent_class;
	void (*finalize) (TextParser *self);
	gboolean (*tag_handled) (TextParser* self, FormatTag tag);
	void (*insert_tag) (TextParser* self, CanvasText* ct, FormatTag tag, gint start_pos, gint end_pos, UndoTextBuffer* undo_buffer, const gchar* extra);
	void (*remove_all_tags) (TextParser* self, CanvasText* ct, gint start_pos, gint end_pos, UndoTextBuffer* undo_buffer);
};

struct _UnicodeParser {
	TextParser parent_instance;
	UnicodeParserPrivate * priv;
};

struct _UnicodeParserClass {
	TextParserClass parent_class;
};

struct _UnicodeParserPrivate {
	MindMap* _map;
};

static gint UnicodeParser_private_offset;
static gpointer unicode_parser_parent_class = NULL;

VALA_EXTERN gpointer text_parser_ref (gpointer instance);
VALA_EXTERN void text_parser_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_text_parser (const gchar* name,
                                    const gchar* nick,
                                    const gchar* blurb,
                                    GType object_type,
                                    GParamFlags flags);
VALA_EXTERN void value_set_text_parser (GValue* value,
                            gpointer v_object);
VALA_EXTERN void value_take_text_parser (GValue* value,
                             gpointer v_object);
VALA_EXTERN gpointer value_get_text_parser (const GValue* value);
VALA_EXTERN GType text_parser_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TextParser, text_parser_unref)
VALA_EXTERN GType format_tag_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType canvas_text_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (CanvasText, g_object_unref)
VALA_EXTERN GType undo_buffer_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UndoBuffer, g_object_unref)
VALA_EXTERN GType undo_text_buffer_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UndoTextBuffer, g_object_unref)
VALA_EXTERN GType unicode_parser_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UnicodeParser, text_parser_unref)
VALA_EXTERN gpointer mind_map_ref (gpointer instance);
VALA_EXTERN void mind_map_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_mind_map (const gchar* name,
                                 const gchar* nick,
                                 const gchar* blurb,
                                 GType object_type,
                                 GParamFlags flags);
VALA_EXTERN void value_set_mind_map (GValue* value,
                         gpointer v_object);
VALA_EXTERN void value_take_mind_map (GValue* value,
                          gpointer v_object);
VALA_EXTERN gpointer value_get_mind_map (const GValue* value);
VALA_EXTERN GType mind_map_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MindMap, mind_map_unref)
VALA_EXTERN gboolean text_parser_tag_handled (TextParser* self,
                                  FormatTag tag);
VALA_EXTERN UnicodeParser* unicode_parser_new (MindMap* map);
VALA_EXTERN UnicodeParser* unicode_parser_construct (GType object_type,
                                         MindMap* map);
VALA_EXTERN TextParser* text_parser_new (const gchar* name);
VALA_EXTERN TextParser* text_parser_construct (GType object_type,
                                   const gchar* name);
VALA_EXTERN gpointer formatted_text_ref (gpointer instance);
VALA_EXTERN void formatted_text_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_formatted_text (const gchar* name,
                                       const gchar* nick,
                                       const gchar* blurb,
                                       GType object_type,
                                       GParamFlags flags);
VALA_EXTERN void value_set_formatted_text (GValue* value,
                               gpointer v_object);
VALA_EXTERN void value_take_formatted_text (GValue* value,
                                gpointer v_object);
VALA_EXTERN gpointer value_get_formatted_text (const GValue* value);
VALA_EXTERN GType formatted_text_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (FormattedText, formatted_text_unref)
VALA_EXTERN void text_parser_add_regex (TextParser* self,
                            const gchar* re,
                            TextParserTextMatchCallback func,
                            gpointer func_target);
static void unicode_parser_handle_code (UnicodeParser* self,
                                 FormattedText* text,
                                 GMatchInfo* match);
static void _unicode_parser_handle_code_text_parser_text_match_callback (FormattedText* text,
                                                                  GMatchInfo* match_info,
                                                                  gpointer self);
static void unicode_parser_handle_nocode (UnicodeParser* self,
                                   FormattedText* text,
                                   GMatchInfo* match);
static void _unicode_parser_handle_nocode_text_parser_text_match_callback (FormattedText* text,
                                                                    GMatchInfo* match_info,
                                                                    gpointer self);
VALA_EXTERN gchar* text_parser_get_text (TextParser* self,
                             GMatchInfo* matches,
                             gint paren);
VALA_EXTERN void text_parser_add_tag (TextParser* self,
                          FormattedText* text,
                          GMatchInfo* matches,
                          gint paren,
                          FormatTag tag,
                          const gchar* extra);
VALA_EXTERN gboolean mind_map_is_node_selected (MindMap* self);
static void unicode_parser_handle_code_for_ct (UnicodeParser* self,
                                        CanvasText* ct,
                                        FormattedText* text,
                                        GMatchInfo* match,
                                        const gchar* tag);
VALA_EXTERN GType node_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Node, g_object_unref)
VALA_EXTERN Node* mind_map_get_current_node (MindMap* self);
VALA_EXTERN CanvasText* node_get_name (Node* self);
VALA_EXTERN gboolean mind_map_is_callout_selected (MindMap* self);
VALA_EXTERN GType callout_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Callout, g_object_unref)
VALA_EXTERN Callout* mind_map_get_current_callout (MindMap* self);
VALA_EXTERN CanvasText* callout_get_text (Callout* self);
VALA_EXTERN FormattedText* canvas_text_get_text (CanvasText* self);
VALA_EXTERN gint canvas_text_get_cursor (CanvasText* self);
VALA_EXTERN GType draw_area_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DrawArea, g_object_unref)
VALA_EXTERN DrawArea* mind_map_get_canvas (MindMap* self);
VALA_EXTERN gpointer text_completion_item_ref (gpointer instance);
VALA_EXTERN void text_completion_item_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_text_completion_item (const gchar* name,
                                             const gchar* nick,
                                             const gchar* blurb,
                                             GType object_type,
                                             GParamFlags flags);
VALA_EXTERN void value_set_text_completion_item (GValue* value,
                                     gpointer v_object);
VALA_EXTERN void value_take_text_completion_item (GValue* value,
                                      gpointer v_object);
VALA_EXTERN gpointer value_get_text_completion_item (const GValue* value);
VALA_EXTERN GType text_completion_item_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TextCompletionItem, text_completion_item_unref)
VALA_EXTERN void draw_area_show_auto_completion (DrawArea* self,
                                     GList* values,
                                     gint start_pos,
                                     gint end_pos);
VALA_EXTERN GType main_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MainWindow, g_object_unref)
VALA_EXTERN MainWindow* mind_map_get_win (MindMap* self);
VALA_EXTERN gpointer unicode_insert_ref (gpointer instance);
VALA_EXTERN void unicode_insert_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_unicode_insert (const gchar* name,
                                       const gchar* nick,
                                       const gchar* blurb,
                                       GType object_type,
                                       GParamFlags flags);
VALA_EXTERN void value_set_unicode_insert (GValue* value,
                               gpointer v_object);
VALA_EXTERN void value_take_unicode_insert (GValue* value,
                                gpointer v_object);
VALA_EXTERN gpointer value_get_unicode_insert (const GValue* value);
VALA_EXTERN GType unicode_insert_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UnicodeInsert, unicode_insert_unref)
VALA_EXTERN UnicodeInsert* main_window_get_unicoder (MainWindow* self);
VALA_EXTERN GList* unicode_insert_get_matches (UnicodeInsert* self,
                                   const gchar* partial);
static void _text_completion_item_unref0_ (gpointer var);
static inline void _g_list_free__text_completion_item_unref0_ (GList* self);
static void unicode_parser_handle_nocode_for_ct (UnicodeParser* self,
                                          CanvasText* ct,
                                          FormattedText* text,
                                          GMatchInfo* match);
VALA_EXTERN void draw_area_hide_auto_completion (DrawArea* self);
static gboolean unicode_parser_real_tag_handled (TextParser* base,
                                          FormatTag tag);
static void unicode_parser_finalize (TextParser * obj);
static GType unicode_parser_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
unicode_parser_get_instance_private (UnicodeParser* self)
{
	return G_STRUCT_MEMBER_P (self, UnicodeParser_private_offset);
}

static gpointer
_mind_map_ref0 (gpointer self)
{
	return self ? mind_map_ref (self) : NULL;
}

static void
_unicode_parser_handle_code_text_parser_text_match_callback (FormattedText* text,
                                                             GMatchInfo* match_info,
                                                             gpointer self)
{
	unicode_parser_handle_code ((UnicodeParser*) self, text, match_info);
}

static void
_unicode_parser_handle_nocode_text_parser_text_match_callback (FormattedText* text,
                                                               GMatchInfo* match_info,
                                                               gpointer self)
{
	unicode_parser_handle_nocode ((UnicodeParser*) self, text, match_info);
}

UnicodeParser*
unicode_parser_construct (GType object_type,
                          MindMap* map)
{
	UnicodeParser* self = NULL;
	MindMap* _tmp0_;
	g_return_val_if_fail (map != NULL, NULL);
	self = (UnicodeParser*) text_parser_construct (object_type, "Unicode");
	_tmp0_ = _mind_map_ref0 (map);
	_mind_map_unref0 (self->priv->_map);
	self->priv->_map = _tmp0_;
	text_parser_add_regex ((TextParser*) self, "\\\\([a-zA-Z0-9_\\^\\(\\){}!+-=~:\\`'\".<>-]*)", _unicode_parser_handle_code_text_parser_text_match_callback, self);
	text_parser_add_regex ((TextParser*) self, "\\s", _unicode_parser_handle_nocode_text_parser_text_match_callback, self);
	return self;
}

UnicodeParser*
unicode_parser_new (MindMap* map)
{
	return unicode_parser_construct (TYPE_UNICODE_PARSER, map);
}

static void
unicode_parser_handle_code (UnicodeParser* self,
                            FormattedText* text,
                            GMatchInfo* match)
{
	gchar* tag = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	MindMap* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (text != NULL);
	g_return_if_fail (match != NULL);
	_tmp0_ = text_parser_get_text ((TextParser*) self, match, 0);
	tag = _tmp0_;
	_tmp1_ = tag;
	text_parser_add_tag ((TextParser*) self, text, match, 0, FORMAT_TAG_TAG, _tmp1_);
	_tmp2_ = self->priv->_map;
	if (mind_map_is_node_selected (_tmp2_)) {
		MindMap* _tmp3_;
		Node* _tmp4_;
		Node* _tmp5_;
		CanvasText* _tmp6_;
		CanvasText* _tmp7_;
		const gchar* _tmp8_;
		_tmp3_ = self->priv->_map;
		_tmp4_ = mind_map_get_current_node (_tmp3_);
		_tmp5_ = _tmp4_;
		_tmp6_ = node_get_name (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = tag;
		unicode_parser_handle_code_for_ct (self, _tmp7_, text, match, _tmp8_);
		_g_object_unref0 (_tmp5_);
	} else {
		MindMap* _tmp9_;
		_tmp9_ = self->priv->_map;
		if (mind_map_is_callout_selected (_tmp9_)) {
			MindMap* _tmp10_;
			Callout* _tmp11_;
			Callout* _tmp12_;
			CanvasText* _tmp13_;
			CanvasText* _tmp14_;
			const gchar* _tmp15_;
			_tmp10_ = self->priv->_map;
			_tmp11_ = mind_map_get_current_callout (_tmp10_);
			_tmp12_ = _tmp11_;
			_tmp13_ = callout_get_text (_tmp12_);
			_tmp14_ = _tmp13_;
			_tmp15_ = tag;
			unicode_parser_handle_code_for_ct (self, _tmp14_, text, match, _tmp15_);
			_g_object_unref0 (_tmp12_);
		}
	}
	_g_free0 (tag);
}

static void
_text_completion_item_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (text_completion_item_unref (var), NULL));
}

static inline void
_g_list_free__text_completion_item_unref0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _text_completion_item_unref0_);
}

static void
unicode_parser_handle_code_for_ct (UnicodeParser* self,
                                   CanvasText* ct,
                                   FormattedText* text,
                                   GMatchInfo* match,
                                   const gchar* tag)
{
	FormattedText* _tmp0_;
	FormattedText* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (ct != NULL);
	g_return_if_fail (text != NULL);
	g_return_if_fail (match != NULL);
	g_return_if_fail (tag != NULL);
	_tmp0_ = canvas_text_get_text (ct);
	_tmp1_ = _tmp0_;
	if (_tmp1_ == text) {
		gint start = 0;
		gint end = 0;
		gint _tmp2_ = 0;
		gint _tmp3_ = 0;
		gint cursor = 0;
		gint _tmp4_;
		gint _tmp5_;
		gboolean _tmp6_ = FALSE;
		g_match_info_fetch_pos (match, 0, &_tmp2_, &_tmp3_);
		start = _tmp2_;
		end = _tmp3_;
		_tmp4_ = canvas_text_get_cursor (ct);
		_tmp5_ = _tmp4_;
		cursor = _tmp5_;
		if (start <= cursor) {
			_tmp6_ = cursor <= end;
		} else {
			_tmp6_ = FALSE;
		}
		if (_tmp6_) {
			MindMap* _tmp7_;
			DrawArea* _tmp8_;
			DrawArea* _tmp9_;
			MindMap* _tmp10_;
			MainWindow* _tmp11_;
			MainWindow* _tmp12_;
			UnicodeInsert* _tmp13_;
			UnicodeInsert* _tmp14_;
			GList* _tmp15_;
			GList* _tmp16_;
			_tmp7_ = self->priv->_map;
			_tmp8_ = mind_map_get_canvas (_tmp7_);
			_tmp9_ = _tmp8_;
			_tmp10_ = self->priv->_map;
			_tmp11_ = mind_map_get_win (_tmp10_);
			_tmp12_ = _tmp11_;
			_tmp13_ = main_window_get_unicoder (_tmp12_);
			_tmp14_ = _tmp13_;
			_tmp15_ = unicode_insert_get_matches (_tmp14_, tag);
			_tmp16_ = _tmp15_;
			draw_area_show_auto_completion (_tmp9_, _tmp16_, start, end);
			(_tmp16_ == NULL) ? NULL : (_tmp16_ = (_g_list_free__text_completion_item_unref0_ (_tmp16_), NULL));
		}
	}
}

static void
unicode_parser_handle_nocode (UnicodeParser* self,
                              FormattedText* text,
                              GMatchInfo* match)
{
	MindMap* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (text != NULL);
	g_return_if_fail (match != NULL);
	_tmp0_ = self->priv->_map;
	if (mind_map_is_node_selected (_tmp0_)) {
		MindMap* _tmp1_;
		Node* _tmp2_;
		Node* _tmp3_;
		CanvasText* _tmp4_;
		CanvasText* _tmp5_;
		_tmp1_ = self->priv->_map;
		_tmp2_ = mind_map_get_current_node (_tmp1_);
		_tmp3_ = _tmp2_;
		_tmp4_ = node_get_name (_tmp3_);
		_tmp5_ = _tmp4_;
		unicode_parser_handle_nocode_for_ct (self, _tmp5_, text, match);
		_g_object_unref0 (_tmp3_);
	} else {
		MindMap* _tmp6_;
		_tmp6_ = self->priv->_map;
		if (mind_map_is_callout_selected (_tmp6_)) {
			MindMap* _tmp7_;
			Callout* _tmp8_;
			Callout* _tmp9_;
			CanvasText* _tmp10_;
			CanvasText* _tmp11_;
			_tmp7_ = self->priv->_map;
			_tmp8_ = mind_map_get_current_callout (_tmp7_);
			_tmp9_ = _tmp8_;
			_tmp10_ = callout_get_text (_tmp9_);
			_tmp11_ = _tmp10_;
			unicode_parser_handle_nocode_for_ct (self, _tmp11_, text, match);
			_g_object_unref0 (_tmp9_);
		}
	}
}

static void
unicode_parser_handle_nocode_for_ct (UnicodeParser* self,
                                     CanvasText* ct,
                                     FormattedText* text,
                                     GMatchInfo* match)
{
	FormattedText* _tmp0_;
	FormattedText* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (ct != NULL);
	g_return_if_fail (text != NULL);
	g_return_if_fail (match != NULL);
	_tmp0_ = canvas_text_get_text (ct);
	_tmp1_ = _tmp0_;
	if (_tmp1_ == text) {
		gint start = 0;
		gint end = 0;
		gint _tmp2_ = 0;
		gint _tmp3_ = 0;
		gint _tmp4_;
		gint _tmp5_;
		g_match_info_fetch_pos (match, 0, &_tmp2_, &_tmp3_);
		start = _tmp2_;
		end = _tmp3_;
		_tmp4_ = canvas_text_get_cursor (ct);
		_tmp5_ = _tmp4_;
		if (_tmp5_ == start) {
			MindMap* _tmp6_;
			DrawArea* _tmp7_;
			DrawArea* _tmp8_;
			_tmp6_ = self->priv->_map;
			_tmp7_ = mind_map_get_canvas (_tmp6_);
			_tmp8_ = _tmp7_;
			draw_area_hide_auto_completion (_tmp8_);
		}
	}
}

static gboolean
unicode_parser_real_tag_handled (TextParser* base,
                                 FormatTag tag)
{
	UnicodeParser * self;
	gboolean result;
	self = (UnicodeParser*) base;
	result = tag == FORMAT_TAG_TAG;
	return result;
}

static void
unicode_parser_class_init (UnicodeParserClass * klass,
                           gpointer klass_data)
{
	unicode_parser_parent_class = g_type_class_peek_parent (klass);
	((TextParserClass *) klass)->finalize = unicode_parser_finalize;
	g_type_class_adjust_private_offset (klass, &UnicodeParser_private_offset);
	((TextParserClass *) klass)->tag_handled = (gboolean (*) (TextParser*, FormatTag)) unicode_parser_real_tag_handled;
}

static void
unicode_parser_instance_init (UnicodeParser * self,
                              gpointer klass)
{
	self->priv = unicode_parser_get_instance_private (self);
}

static void
unicode_parser_finalize (TextParser * obj)
{
	UnicodeParser * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_UNICODE_PARSER, UnicodeParser);
	_mind_map_unref0 (self->priv->_map);
	TEXT_PARSER_CLASS (unicode_parser_parent_class)->finalize (obj);
}

static GType
unicode_parser_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (UnicodeParserClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) unicode_parser_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UnicodeParser), 0, (GInstanceInitFunc) unicode_parser_instance_init, NULL };
	GType unicode_parser_type_id;
	unicode_parser_type_id = g_type_register_static (TYPE_TEXT_PARSER, "UnicodeParser", &g_define_type_info, 0);
	UnicodeParser_private_offset = g_type_add_instance_private (unicode_parser_type_id, sizeof (UnicodeParserPrivate));
	return unicode_parser_type_id;
}

GType
unicode_parser_get_type (void)
{
	static volatile gsize unicode_parser_type_id__once = 0;
	if (g_once_init_enter (&unicode_parser_type_id__once)) {
		GType unicode_parser_type_id;
		unicode_parser_type_id = unicode_parser_get_type_once ();
		g_once_init_leave (&unicode_parser_type_id__once, unicode_parser_type_id);
	}
	return unicode_parser_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;
}

