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

#include <glib-object.h>
#include <gtk/gtk.h>
#include "libdino.h"
#include <glib.h>
#include <gee.h>
#include "xmpp-vala.h"
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include <gdk/gdk.h>
#include <pango/pango.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 DINO_UI_TYPE_CHAT_TEXT_VIEW_CONTROLLER (dino_ui_chat_text_view_controller_get_type ())
#define DINO_UI_CHAT_TEXT_VIEW_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DINO_UI_TYPE_CHAT_TEXT_VIEW_CONTROLLER, DinoUiChatTextViewController))
#define DINO_UI_CHAT_TEXT_VIEW_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DINO_UI_TYPE_CHAT_TEXT_VIEW_CONTROLLER, DinoUiChatTextViewControllerClass))
#define DINO_UI_IS_CHAT_TEXT_VIEW_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DINO_UI_TYPE_CHAT_TEXT_VIEW_CONTROLLER))
#define DINO_UI_IS_CHAT_TEXT_VIEW_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DINO_UI_TYPE_CHAT_TEXT_VIEW_CONTROLLER))
#define DINO_UI_CHAT_TEXT_VIEW_CONTROLLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DINO_UI_TYPE_CHAT_TEXT_VIEW_CONTROLLER, DinoUiChatTextViewControllerClass))

typedef struct _DinoUiChatTextViewController DinoUiChatTextViewController;
typedef struct _DinoUiChatTextViewControllerClass DinoUiChatTextViewControllerClass;
typedef struct _DinoUiChatTextViewControllerPrivate DinoUiChatTextViewControllerPrivate;

#define DINO_UI_TYPE_OCCUPANTS_TAB_COMPLETOR (dino_ui_occupants_tab_completor_get_type ())
#define DINO_UI_OCCUPANTS_TAB_COMPLETOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DINO_UI_TYPE_OCCUPANTS_TAB_COMPLETOR, DinoUiOccupantsTabCompletor))
#define DINO_UI_OCCUPANTS_TAB_COMPLETOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DINO_UI_TYPE_OCCUPANTS_TAB_COMPLETOR, DinoUiOccupantsTabCompletorClass))
#define DINO_UI_IS_OCCUPANTS_TAB_COMPLETOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DINO_UI_TYPE_OCCUPANTS_TAB_COMPLETOR))
#define DINO_UI_IS_OCCUPANTS_TAB_COMPLETOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DINO_UI_TYPE_OCCUPANTS_TAB_COMPLETOR))
#define DINO_UI_OCCUPANTS_TAB_COMPLETOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DINO_UI_TYPE_OCCUPANTS_TAB_COMPLETOR, DinoUiOccupantsTabCompletorClass))

typedef struct _DinoUiOccupantsTabCompletor DinoUiOccupantsTabCompletor;
typedef struct _DinoUiOccupantsTabCompletorClass DinoUiOccupantsTabCompletorClass;

#define DINO_UI_TYPE_CHAT_TEXT_VIEW (dino_ui_chat_text_view_get_type ())
#define DINO_UI_CHAT_TEXT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DINO_UI_TYPE_CHAT_TEXT_VIEW, DinoUiChatTextView))
#define DINO_UI_CHAT_TEXT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DINO_UI_TYPE_CHAT_TEXT_VIEW, DinoUiChatTextViewClass))
#define DINO_UI_IS_CHAT_TEXT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DINO_UI_TYPE_CHAT_TEXT_VIEW))
#define DINO_UI_IS_CHAT_TEXT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DINO_UI_TYPE_CHAT_TEXT_VIEW))
#define DINO_UI_CHAT_TEXT_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DINO_UI_TYPE_CHAT_TEXT_VIEW, DinoUiChatTextViewClass))

typedef struct _DinoUiChatTextView DinoUiChatTextView;
typedef struct _DinoUiChatTextViewClass DinoUiChatTextViewClass;
enum  {
	DINO_UI_CHAT_TEXT_VIEW_CONTROLLER_0_PROPERTY,
	DINO_UI_CHAT_TEXT_VIEW_CONTROLLER_NUM_PROPERTIES
};
static GParamSpec* dino_ui_chat_text_view_controller_properties[DINO_UI_CHAT_TEXT_VIEW_CONTROLLER_NUM_PROPERTIES];
#define _dino_ui_occupants_tab_completor_unref0(var) ((var == NULL) ? NULL : (var = (dino_ui_occupants_tab_completor_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _DinoUiChatTextViewPrivate DinoUiChatTextViewPrivate;
enum  {
	DINO_UI_CHAT_TEXT_VIEW_CONTROLLER_SEND_TEXT_SIGNAL,
	DINO_UI_CHAT_TEXT_VIEW_CONTROLLER_NUM_SIGNALS
};
static guint dino_ui_chat_text_view_controller_signals[DINO_UI_CHAT_TEXT_VIEW_CONTROLLER_NUM_SIGNALS] = {0};

#define DINO_UI_TYPE_SMILEY_CONVERTER (dino_ui_smiley_converter_get_type ())
#define DINO_UI_SMILEY_CONVERTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DINO_UI_TYPE_SMILEY_CONVERTER, DinoUiSmileyConverter))
#define DINO_UI_SMILEY_CONVERTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DINO_UI_TYPE_SMILEY_CONVERTER, DinoUiSmileyConverterClass))
#define DINO_UI_IS_SMILEY_CONVERTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DINO_UI_TYPE_SMILEY_CONVERTER))
#define DINO_UI_IS_SMILEY_CONVERTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DINO_UI_TYPE_SMILEY_CONVERTER))
#define DINO_UI_SMILEY_CONVERTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DINO_UI_TYPE_SMILEY_CONVERTER, DinoUiSmileyConverterClass))

typedef struct _DinoUiSmileyConverter DinoUiSmileyConverter;
typedef struct _DinoUiSmileyConverterClass DinoUiSmileyConverterClass;
enum  {
	DINO_UI_CHAT_TEXT_VIEW_0_PROPERTY,
	DINO_UI_CHAT_TEXT_VIEW_NUM_PROPERTIES
};
static GParamSpec* dino_ui_chat_text_view_properties[DINO_UI_CHAT_TEXT_VIEW_NUM_PROPERTIES];
#define _dino_ui_smiley_converter_unref0(var) ((var == NULL) ? NULL : (var = (dino_ui_smiley_converter_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	DINO_UI_CHAT_TEXT_VIEW_SEND_TEXT_SIGNAL,
	DINO_UI_CHAT_TEXT_VIEW_CANCEL_INPUT_SIGNAL,
	DINO_UI_CHAT_TEXT_VIEW_NUM_SIGNALS
};
static guint dino_ui_chat_text_view_signals[DINO_UI_CHAT_TEXT_VIEW_NUM_SIGNALS] = {0};

struct _DinoUiChatTextViewController {
	GObject parent_instance;
	DinoUiChatTextViewControllerPrivate * priv;
	DinoUiOccupantsTabCompletor* occupants_tab_completor;
};

struct _DinoUiChatTextViewControllerClass {
	GObjectClass parent_class;
};

struct _DinoUiChatTextViewControllerPrivate {
	DinoUiChatTextView* widget;
};

struct _DinoUiChatTextView {
	GtkBox parent_instance;
	DinoUiChatTextViewPrivate * priv;
	GtkScrolledWindow* scrolled_window;
	GtkTextView* text_view;
};

struct _DinoUiChatTextViewClass {
	GtkBoxClass parent_class;
};

struct _DinoUiChatTextViewPrivate {
	gint vscrollbar_min_height;
	guint wait_queue_resize;
	DinoUiSmileyConverter* smiley_converter;
	GtkTextTag* italic_tag;
	GtkTextTag* bold_tag;
	GtkTextTag* strikethrough_tag;
};

static gint DinoUiChatTextViewController_private_offset;
static gpointer dino_ui_chat_text_view_controller_parent_class = NULL;
static gint DinoUiChatTextView_private_offset;
static gpointer dino_ui_chat_text_view_parent_class = NULL;

VALA_EXTERN GType dino_ui_chat_text_view_controller_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DinoUiChatTextViewController, g_object_unref)
VALA_EXTERN gpointer dino_ui_occupants_tab_completor_ref (gpointer instance);
VALA_EXTERN void dino_ui_occupants_tab_completor_unref (gpointer instance);
VALA_EXTERN GParamSpec* dino_ui_param_spec_occupants_tab_completor (const gchar* name,
                                                        const gchar* nick,
                                                        const gchar* blurb,
                                                        GType object_type,
                                                        GParamFlags flags);
VALA_EXTERN void dino_ui_value_set_occupants_tab_completor (GValue* value,
                                                gpointer v_object);
VALA_EXTERN void dino_ui_value_take_occupants_tab_completor (GValue* value,
                                                 gpointer v_object);
VALA_EXTERN gpointer dino_ui_value_get_occupants_tab_completor (const GValue* value);
VALA_EXTERN GType dino_ui_occupants_tab_completor_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DinoUiOccupantsTabCompletor, dino_ui_occupants_tab_completor_unref)
VALA_EXTERN GType dino_ui_chat_text_view_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DinoUiChatTextView, g_object_unref)
VALA_EXTERN DinoUiChatTextViewController* dino_ui_chat_text_view_controller_new (DinoUiChatTextView* widget,
                                                                     DinoStreamInteractor* stream_interactor);
VALA_EXTERN DinoUiChatTextViewController* dino_ui_chat_text_view_controller_construct (GType object_type,
                                                                           DinoUiChatTextView* widget,
                                                                           DinoStreamInteractor* stream_interactor);
VALA_EXTERN DinoUiOccupantsTabCompletor* dino_ui_occupants_tab_completor_new (DinoStreamInteractor* stream_interactor,
                                                                  GtkTextView* text_input);
VALA_EXTERN DinoUiOccupantsTabCompletor* dino_ui_occupants_tab_completor_construct (GType object_type,
                                                                        DinoStreamInteractor* stream_interactor,
                                                                        GtkTextView* text_input);
static void __lambda27_ (DinoUiChatTextViewController* self);
static void ___lambda27__dino_ui_chat_text_view_send_text (DinoUiChatTextView* _sender,
                                                    gpointer self);
VALA_EXTERN void dino_ui_chat_text_view_controller_initialize_for_conversation (DinoUiChatTextViewController* self,
                                                                    DinoEntitiesConversation* conversation);
VALA_EXTERN void dino_ui_occupants_tab_completor_initialize_for_conversation (DinoUiOccupantsTabCompletor* self,
                                                                  DinoEntitiesConversation* conversation);
static void dino_ui_chat_text_view_controller_finalize (GObject * obj);
static GType dino_ui_chat_text_view_controller_get_type_once (void);
VALA_EXTERN gpointer dino_ui_smiley_converter_ref (gpointer instance);
VALA_EXTERN void dino_ui_smiley_converter_unref (gpointer instance);
VALA_EXTERN GParamSpec* dino_ui_param_spec_smiley_converter (const gchar* name,
                                                 const gchar* nick,
                                                 const gchar* blurb,
                                                 GType object_type,
                                                 GParamFlags flags);
VALA_EXTERN void dino_ui_value_set_smiley_converter (GValue* value,
                                         gpointer v_object);
VALA_EXTERN void dino_ui_value_take_smiley_converter (GValue* value,
                                          gpointer v_object);
VALA_EXTERN gpointer dino_ui_value_get_smiley_converter (const GValue* value);
VALA_EXTERN GType dino_ui_smiley_converter_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DinoUiSmileyConverter, dino_ui_smiley_converter_unref)
VALA_EXTERN void dino_ui_chat_text_view_set_text (DinoUiChatTextView* self,
                                      DinoEntitiesMessage* message);
VALA_EXTERN gchar* dino_ui_util_remove_fallbacks_adjust_markups (const gchar* text,
                                                     gboolean contains_quote,
                                                     GeeList* fallbacks,
                                                     GeeList* markups);
static void dino_ui_chat_text_view_real_dispose (GObject* base);
static void dino_ui_chat_text_view_on_upper_notify (DinoUiChatTextView* self);
static void dino_ui_chat_text_view_start_queue_resize_if_needed (DinoUiChatTextView* self);
static gboolean dino_ui_chat_text_view_queue_resize_if_needed (DinoUiChatTextView* self);
static gboolean _dino_ui_chat_text_view_queue_resize_if_needed_gsource_func (gpointer self);
static gboolean dino_ui_chat_text_view_on_text_input_key_press (DinoUiChatTextView* self,
                                                         GtkEventControllerKey* controller,
                                                         guint keyval,
                                                         guint keycode,
                                                         GdkModifierType state);
static gboolean _vala_uint_array_contains (guint * stack,
                                    gssize stack_length,
                                    const guint needle);
static GeeList* dino_ui_chat_text_view_get_markup_types_from_iter (DinoUiChatTextView* self,
                                                            GtkTextIter* iter);
VALA_EXTERN GeeList* dino_ui_chat_text_view_get_markups (DinoUiChatTextView* self);
VALA_EXTERN DinoUiChatTextView* dino_ui_chat_text_view_new (void);
VALA_EXTERN DinoUiChatTextView* dino_ui_chat_text_view_construct (GType object_type);
static GObject * dino_ui_chat_text_view_constructor (GType type,
                                              guint n_construct_properties,
                                              GObjectConstructParam * construct_properties);
static gboolean _dino_ui_chat_text_view_on_text_input_key_press_gtk_event_controller_key_key_pressed (GtkEventControllerKey* _sender,
                                                                                               guint keyval,
                                                                                               guint keycode,
                                                                                               GdkModifierType state,
                                                                                               gpointer self);
VALA_EXTERN DinoUiSmileyConverter* dino_ui_smiley_converter_new (GtkTextView* text_input);
VALA_EXTERN DinoUiSmileyConverter* dino_ui_smiley_converter_construct (GType object_type,
                                                           GtkTextView* text_input);
static void _dino_ui_chat_text_view_on_upper_notify_gtk_adjustment_changed (GtkAdjustment* _sender,
                                                                     gpointer self);
static void _dino_ui_chat_text_view___lambda4_ (DinoUiChatTextView* self);
static void __dino_ui_chat_text_view___lambda4__gtk_widget_realize (GtkWidget* _sender,
                                                             gpointer self);
static void dino_ui_chat_text_view_finalize (GObject * obj);
static GType dino_ui_chat_text_view_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dino_ui_chat_text_view_controller_get_instance_private (DinoUiChatTextViewController* self)
{
	return G_STRUCT_MEMBER_P (self, DinoUiChatTextViewController_private_offset);
}

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

static void
__lambda27_ (DinoUiChatTextViewController* self)
{
	g_signal_emit (self, dino_ui_chat_text_view_controller_signals[DINO_UI_CHAT_TEXT_VIEW_CONTROLLER_SEND_TEXT_SIGNAL], 0);
}

static void
___lambda27__dino_ui_chat_text_view_send_text (DinoUiChatTextView* _sender,
                                               gpointer self)
{
	__lambda27_ ((DinoUiChatTextViewController*) self);
}

DinoUiChatTextViewController*
dino_ui_chat_text_view_controller_construct (GType object_type,
                                             DinoUiChatTextView* widget,
                                             DinoStreamInteractor* stream_interactor)
{
	DinoUiChatTextViewController * self = NULL;
	DinoUiChatTextView* _tmp0_;
	GtkTextView* _tmp1_;
	DinoUiOccupantsTabCompletor* _tmp2_;
	g_return_val_if_fail (widget != NULL, NULL);
	g_return_val_if_fail (stream_interactor != NULL, NULL);
	self = (DinoUiChatTextViewController*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (widget);
	_g_object_unref0 (self->priv->widget);
	self->priv->widget = _tmp0_;
	_tmp1_ = widget->text_view;
	_tmp2_ = dino_ui_occupants_tab_completor_new (stream_interactor, _tmp1_);
	_dino_ui_occupants_tab_completor_unref0 (self->occupants_tab_completor);
	self->occupants_tab_completor = _tmp2_;
	g_signal_connect_object (widget, "send-text", (GCallback) ___lambda27__dino_ui_chat_text_view_send_text, self, 0);
	return self;
}

DinoUiChatTextViewController*
dino_ui_chat_text_view_controller_new (DinoUiChatTextView* widget,
                                       DinoStreamInteractor* stream_interactor)
{
	return dino_ui_chat_text_view_controller_construct (DINO_UI_TYPE_CHAT_TEXT_VIEW_CONTROLLER, widget, stream_interactor);
}

void
dino_ui_chat_text_view_controller_initialize_for_conversation (DinoUiChatTextViewController* self,
                                                               DinoEntitiesConversation* conversation)
{
	DinoUiOccupantsTabCompletor* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (conversation != NULL);
	_tmp0_ = self->occupants_tab_completor;
	dino_ui_occupants_tab_completor_initialize_for_conversation (_tmp0_, conversation);
}

static void
dino_ui_chat_text_view_controller_class_init (DinoUiChatTextViewControllerClass * klass,
                                              gpointer klass_data)
{
	dino_ui_chat_text_view_controller_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoUiChatTextViewController_private_offset);
	G_OBJECT_CLASS (klass)->finalize = dino_ui_chat_text_view_controller_finalize;
	dino_ui_chat_text_view_controller_signals[DINO_UI_CHAT_TEXT_VIEW_CONTROLLER_SEND_TEXT_SIGNAL] = g_signal_new ("send-text", DINO_UI_TYPE_CHAT_TEXT_VIEW_CONTROLLER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
dino_ui_chat_text_view_controller_instance_init (DinoUiChatTextViewController * self,
                                                 gpointer klass)
{
	self->priv = dino_ui_chat_text_view_controller_get_instance_private (self);
}

static void
dino_ui_chat_text_view_controller_finalize (GObject * obj)
{
	DinoUiChatTextViewController * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_UI_TYPE_CHAT_TEXT_VIEW_CONTROLLER, DinoUiChatTextViewController);
	_dino_ui_occupants_tab_completor_unref0 (self->occupants_tab_completor);
	_g_object_unref0 (self->priv->widget);
	G_OBJECT_CLASS (dino_ui_chat_text_view_controller_parent_class)->finalize (obj);
}

static GType
dino_ui_chat_text_view_controller_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoUiChatTextViewControllerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_ui_chat_text_view_controller_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoUiChatTextViewController), 0, (GInstanceInitFunc) dino_ui_chat_text_view_controller_instance_init, NULL };
	GType dino_ui_chat_text_view_controller_type_id;
	dino_ui_chat_text_view_controller_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoUiChatTextViewController", &g_define_type_info, 0);
	DinoUiChatTextViewController_private_offset = g_type_add_instance_private (dino_ui_chat_text_view_controller_type_id, sizeof (DinoUiChatTextViewControllerPrivate));
	return dino_ui_chat_text_view_controller_type_id;
}

GType
dino_ui_chat_text_view_controller_get_type (void)
{
	static volatile gsize dino_ui_chat_text_view_controller_type_id__once = 0;
	if (g_once_init_enter (&dino_ui_chat_text_view_controller_type_id__once)) {
		GType dino_ui_chat_text_view_controller_type_id;
		dino_ui_chat_text_view_controller_type_id = dino_ui_chat_text_view_controller_get_type_once ();
		g_once_init_leave (&dino_ui_chat_text_view_controller_type_id__once, dino_ui_chat_text_view_controller_type_id);
	}
	return dino_ui_chat_text_view_controller_type_id__once;
}

static inline gpointer
dino_ui_chat_text_view_get_instance_private (DinoUiChatTextView* self)
{
	return G_STRUCT_MEMBER_P (self, DinoUiChatTextView_private_offset);
}

void
dino_ui_chat_text_view_set_text (DinoUiChatTextView* self,
                                 DinoEntitiesMessage* message)
{
	GeeArrayList* markups = NULL;
	GeeArrayList* _tmp0_;
	GtkTextView* _tmp22_;
	GtkTextBuffer* _tmp23_;
	GtkTextBuffer* _tmp24_;
	const gchar* _tmp25_;
	const gchar* _tmp26_;
	gint _tmp27_;
	gint _tmp28_;
	GeeList* _tmp29_;
	GeeList* _tmp30_;
	GeeArrayList* _tmp31_;
	gchar* _tmp32_;
	gchar* _tmp33_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (message != NULL);
	_tmp0_ = gee_array_list_new (XMPP_XEP_MESSAGE_MARKUP_TYPE_SPAN, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	markups = _tmp0_;
	{
		GeeList* _markup_list = NULL;
		GeeList* _tmp1_;
		gint _markup_size = 0;
		GeeList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _markup_index = 0;
		_tmp1_ = dino_entities_message_get_markups (message);
		_markup_list = _tmp1_;
		_tmp2_ = _markup_list;
		_tmp3_ = gee_collection_get_size ((GeeCollection*) _tmp2_);
		_tmp4_ = _tmp3_;
		_markup_size = _tmp4_;
		_markup_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			XmppXepMessageMarkupSpan* markup = NULL;
			GeeList* _tmp7_;
			gpointer _tmp8_;
			GeeArrayList* _tmp9_;
			XmppXepMessageMarkupSpan* _tmp10_;
			GeeList* _tmp11_;
			GeeList* _tmp12_;
			GeeList* _tmp13_;
			XmppXepMessageMarkupSpan* _tmp14_;
			gint _tmp15_;
			gint _tmp16_;
			XmppXepMessageMarkupSpan* _tmp17_;
			gint _tmp18_;
			gint _tmp19_;
			XmppXepMessageMarkupSpan* _tmp20_ = NULL;
			XmppXepMessageMarkupSpan* _tmp21_;
			_markup_index = _markup_index + 1;
			_tmp5_ = _markup_index;
			_tmp6_ = _markup_size;
			if (!(_tmp5_ < _tmp6_)) {
				break;
			}
			_tmp7_ = _markup_list;
			_tmp8_ = gee_list_get (_tmp7_, _markup_index);
			markup = (XmppXepMessageMarkupSpan*) _tmp8_;
			_tmp9_ = markups;
			_tmp10_ = markup;
			_tmp11_ = xmpp_xep_message_markup_span_get_types (_tmp10_);
			_tmp12_ = _tmp11_;
			_tmp13_ = _g_object_ref0 (_tmp12_);
			_tmp14_ = markup;
			_tmp15_ = xmpp_xep_message_markup_span_get_start_char (_tmp14_);
			_tmp16_ = _tmp15_;
			_tmp17_ = markup;
			_tmp18_ = xmpp_xep_message_markup_span_get_end_char (_tmp17_);
			_tmp19_ = _tmp18_;
			_tmp20_ = xmpp_xep_message_markup_span_new ();
			xmpp_xep_message_markup_span_set_types (_tmp20_, _tmp13_);
			_g_object_unref0 (_tmp13_);
			xmpp_xep_message_markup_span_set_start_char (_tmp20_, _tmp16_);
			xmpp_xep_message_markup_span_set_end_char (_tmp20_, _tmp19_);
			_tmp21_ = _tmp20_;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp9_, _tmp21_);
			_g_object_unref0 (_tmp21_);
			_g_object_unref0 (markup);
		}
		_g_object_unref0 (_markup_list);
	}
	_tmp22_ = self->text_view;
	_tmp23_ = gtk_text_view_get_buffer (_tmp22_);
	_tmp24_ = _tmp23_;
	_tmp25_ = dino_entities_message_get_body (message);
	_tmp26_ = _tmp25_;
	_tmp27_ = dino_entities_message_get_quoted_item_id (message);
	_tmp28_ = _tmp27_;
	_tmp29_ = dino_entities_message_get_fallbacks (message);
	_tmp30_ = _tmp29_;
	_tmp31_ = markups;
	_tmp32_ = dino_ui_util_remove_fallbacks_adjust_markups (_tmp26_, _tmp28_ > 0, _tmp30_, (GeeList*) _tmp31_);
	_tmp33_ = _tmp32_;
	g_object_set (_tmp24_, "text", _tmp33_, NULL);
	_g_free0 (_tmp33_);
	_g_object_unref0 (_tmp30_);
	{
		GeeArrayList* _markup_list = NULL;
		GeeArrayList* _tmp34_;
		gint _markup_size = 0;
		GeeArrayList* _tmp35_;
		gint _tmp36_;
		gint _tmp37_;
		gint _markup_index = 0;
		_tmp34_ = markups;
		_markup_list = _tmp34_;
		_tmp35_ = _markup_list;
		_tmp36_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp35_);
		_tmp37_ = _tmp36_;
		_markup_size = _tmp37_;
		_markup_index = -1;
		while (TRUE) {
			gint _tmp38_;
			gint _tmp39_;
			XmppXepMessageMarkupSpan* markup = NULL;
			GeeArrayList* _tmp40_;
			gpointer _tmp41_;
			_markup_index = _markup_index + 1;
			_tmp38_ = _markup_index;
			_tmp39_ = _markup_size;
			if (!(_tmp38_ < _tmp39_)) {
				break;
			}
			_tmp40_ = _markup_list;
			_tmp41_ = gee_abstract_list_get ((GeeAbstractList*) _tmp40_, _markup_index);
			markup = (XmppXepMessageMarkupSpan*) _tmp41_;
			{
				GeeList* _ty_list = NULL;
				XmppXepMessageMarkupSpan* _tmp42_;
				GeeList* _tmp43_;
				GeeList* _tmp44_;
				gint _ty_size = 0;
				GeeList* _tmp45_;
				gint _tmp46_;
				gint _tmp47_;
				gint _ty_index = 0;
				_tmp42_ = markup;
				_tmp43_ = xmpp_xep_message_markup_span_get_types (_tmp42_);
				_tmp44_ = _tmp43_;
				_ty_list = _tmp44_;
				_tmp45_ = _ty_list;
				_tmp46_ = gee_collection_get_size ((GeeCollection*) _tmp45_);
				_tmp47_ = _tmp46_;
				_ty_size = _tmp47_;
				_ty_index = -1;
				while (TRUE) {
					gint _tmp48_;
					gint _tmp49_;
					XmppXepMessageMarkupSpanType ty = 0;
					GeeList* _tmp50_;
					gpointer _tmp51_;
					GtkTextTag* tag = NULL;
					GtkTextIter start_selection = {0};
					GtkTextIter end_selection = {0};
					GtkTextView* _tmp58_;
					GtkTextBuffer* _tmp59_;
					GtkTextBuffer* _tmp60_;
					XmppXepMessageMarkupSpan* _tmp61_;
					gint _tmp62_;
					gint _tmp63_;
					GtkTextIter _tmp64_ = {0};
					GtkTextView* _tmp65_;
					GtkTextBuffer* _tmp66_;
					GtkTextBuffer* _tmp67_;
					XmppXepMessageMarkupSpan* _tmp68_;
					gint _tmp69_;
					gint _tmp70_;
					GtkTextIter _tmp71_ = {0};
					GtkTextView* _tmp72_;
					GtkTextBuffer* _tmp73_;
					GtkTextBuffer* _tmp74_;
					GtkTextTag* _tmp75_;
					GtkTextIter _tmp76_;
					GtkTextIter _tmp77_;
					_ty_index = _ty_index + 1;
					_tmp48_ = _ty_index;
					_tmp49_ = _ty_size;
					if (!(_tmp48_ < _tmp49_)) {
						break;
					}
					_tmp50_ = _ty_list;
					_tmp51_ = gee_list_get (_tmp50_, _ty_index);
					ty = (XmppXepMessageMarkupSpanType) ((gintptr) _tmp51_);
					tag = NULL;
					switch (ty) {
						case XMPP_XEP_MESSAGE_MARKUP_SPAN_TYPE_EMPHASIS:
						{
							GtkTextTag* _tmp52_;
							GtkTextTag* _tmp53_;
							_tmp52_ = self->priv->italic_tag;
							_tmp53_ = _g_object_ref0 (_tmp52_);
							_g_object_unref0 (tag);
							tag = _tmp53_;
							break;
						}
						case XMPP_XEP_MESSAGE_MARKUP_SPAN_TYPE_STRONG_EMPHASIS:
						{
							GtkTextTag* _tmp54_;
							GtkTextTag* _tmp55_;
							_tmp54_ = self->priv->bold_tag;
							_tmp55_ = _g_object_ref0 (_tmp54_);
							_g_object_unref0 (tag);
							tag = _tmp55_;
							break;
						}
						case XMPP_XEP_MESSAGE_MARKUP_SPAN_TYPE_DELETED:
						{
							GtkTextTag* _tmp56_;
							GtkTextTag* _tmp57_;
							_tmp56_ = self->priv->strikethrough_tag;
							_tmp57_ = _g_object_ref0 (_tmp56_);
							_g_object_unref0 (tag);
							tag = _tmp57_;
							break;
						}
						default:
						break;
					}
					_tmp58_ = self->text_view;
					_tmp59_ = gtk_text_view_get_buffer (_tmp58_);
					_tmp60_ = _tmp59_;
					_tmp61_ = markup;
					_tmp62_ = xmpp_xep_message_markup_span_get_start_char (_tmp61_);
					_tmp63_ = _tmp62_;
					gtk_text_buffer_get_iter_at_offset (_tmp60_, &_tmp64_, _tmp63_);
					start_selection = _tmp64_;
					_tmp65_ = self->text_view;
					_tmp66_ = gtk_text_view_get_buffer (_tmp65_);
					_tmp67_ = _tmp66_;
					_tmp68_ = markup;
					_tmp69_ = xmpp_xep_message_markup_span_get_end_char (_tmp68_);
					_tmp70_ = _tmp69_;
					gtk_text_buffer_get_iter_at_offset (_tmp67_, &_tmp71_, _tmp70_);
					end_selection = _tmp71_;
					_tmp72_ = self->text_view;
					_tmp73_ = gtk_text_view_get_buffer (_tmp72_);
					_tmp74_ = _tmp73_;
					_tmp75_ = tag;
					_tmp76_ = start_selection;
					_tmp77_ = end_selection;
					gtk_text_buffer_apply_tag (_tmp74_, _tmp75_, &_tmp76_, &_tmp77_);
					_g_object_unref0 (tag);
				}
			}
			_g_object_unref0 (markup);
		}
	}
	_g_object_unref0 (markups);
}

static void
dino_ui_chat_text_view_real_dispose (GObject* base)
{
	DinoUiChatTextView * self;
	self = (DinoUiChatTextView*) base;
	G_OBJECT_CLASS (dino_ui_chat_text_view_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_box_get_type (), GtkBox));
	if (self->priv->wait_queue_resize != ((guint) 0)) {
		g_source_remove (self->priv->wait_queue_resize);
		self->priv->wait_queue_resize = (guint) 0;
	}
}

static void
dino_ui_chat_text_view_on_upper_notify (DinoUiChatTextView* self)
{
	GtkScrolledWindow* _tmp0_;
	GtkScrolledWindow* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	GtkScrolledWindow* _tmp4_;
	GtkAdjustment* _tmp5_;
	GtkAdjustment* _tmp6_;
	gdouble _tmp7_;
	gdouble _tmp8_;
	GtkTextView* _tmp9_;
	gint _tmp10_;
	gint _tmp11_;
	GtkTextView* _tmp12_;
	gint _tmp13_;
	gint _tmp14_;
	GtkScrolledWindow* _tmp15_;
	GtkAdjustment* _tmp16_;
	GtkAdjustment* _tmp17_;
	GtkScrolledWindow* _tmp18_;
	gint _tmp19_;
	gint _tmp20_;
	GtkTextView* _tmp21_;
	gint _tmp22_;
	gint _tmp23_;
	GtkTextView* _tmp24_;
	gint _tmp25_;
	gint _tmp26_;
	GtkScrolledWindow* _tmp27_;
	GtkAdjustment* _tmp28_;
	GtkAdjustment* _tmp29_;
	gdouble _tmp30_;
	gdouble _tmp31_;
	GtkScrolledWindow* _tmp32_;
	GtkWidget* _tmp33_;
	GtkScrolledWindow* _tmp34_;
	GtkAdjustment* _tmp35_;
	GtkAdjustment* _tmp36_;
	gdouble _tmp37_;
	gdouble _tmp38_;
	GtkScrolledWindow* _tmp39_;
	gint _tmp40_;
	gint _tmp41_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->scrolled_window;
	_tmp1_ = self->scrolled_window;
	_tmp2_ = gtk_scrolled_window_get_max_content_height (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = self->scrolled_window;
	_tmp5_ = gtk_scrolled_window_get_vadjustment (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = gtk_adjustment_get_upper (_tmp6_);
	_tmp8_ = _tmp7_;
	_tmp9_ = self->text_view;
	_tmp10_ = gtk_widget_get_margin_top ((GtkWidget*) _tmp9_);
	_tmp11_ = _tmp10_;
	_tmp12_ = self->text_view;
	_tmp13_ = gtk_widget_get_margin_bottom ((GtkWidget*) _tmp12_);
	_tmp14_ = _tmp13_;
	g_object_set ((GtkWidget*) _tmp0_, "height-request", MIN (_tmp3_, (((gint) _tmp8_) + _tmp11_) + _tmp14_), NULL);
	_tmp15_ = self->scrolled_window;
	_tmp16_ = gtk_scrolled_window_get_vadjustment (_tmp15_);
	_tmp17_ = _tmp16_;
	_tmp18_ = self->scrolled_window;
	g_object_get ((GtkWidget*) _tmp18_, "height-request", &_tmp19_, NULL);
	_tmp20_ = _tmp19_;
	_tmp21_ = self->text_view;
	_tmp22_ = gtk_widget_get_margin_top ((GtkWidget*) _tmp21_);
	_tmp23_ = _tmp22_;
	_tmp24_ = self->text_view;
	_tmp25_ = gtk_widget_get_margin_bottom ((GtkWidget*) _tmp24_);
	_tmp26_ = _tmp25_;
	_tmp27_ = self->scrolled_window;
	_tmp28_ = gtk_scrolled_window_get_vadjustment (_tmp27_);
	_tmp29_ = _tmp28_;
	_tmp30_ = gtk_adjustment_get_upper (_tmp29_);
	_tmp31_ = _tmp30_;
	gtk_adjustment_set_page_size (_tmp17_, MIN ((gdouble) (_tmp20_ - (_tmp23_ + _tmp26_)), _tmp31_));
	_tmp32_ = self->scrolled_window;
	_tmp33_ = gtk_scrolled_window_get_vscrollbar (_tmp32_);
	_tmp34_ = self->scrolled_window;
	_tmp35_ = gtk_scrolled_window_get_vadjustment (_tmp34_);
	_tmp36_ = _tmp35_;
	_tmp37_ = gtk_adjustment_get_upper (_tmp36_);
	_tmp38_ = _tmp37_;
	_tmp39_ = self->scrolled_window;
	_tmp40_ = gtk_scrolled_window_get_max_content_height (_tmp39_);
	_tmp41_ = _tmp40_;
	gtk_widget_set_visible (_tmp33_, _tmp38_ > ((gdouble) (_tmp41_ - (2 * self->priv->vscrollbar_min_height))));
	dino_ui_chat_text_view_start_queue_resize_if_needed (self);
}

static gboolean
_dino_ui_chat_text_view_queue_resize_if_needed_gsource_func (gpointer self)
{
	gboolean result;
	result = dino_ui_chat_text_view_queue_resize_if_needed ((DinoUiChatTextView*) self);
	return result;
}

static void
dino_ui_chat_text_view_start_queue_resize_if_needed (DinoUiChatTextView* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->wait_queue_resize == ((guint) 0)) {
		self->priv->wait_queue_resize = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 100, _dino_ui_chat_text_view_queue_resize_if_needed_gsource_func, g_object_ref (self), g_object_unref);
	}
}

static gboolean
dino_ui_chat_text_view_queue_resize_if_needed (DinoUiChatTextView* self)
{
	GtkScrolledWindow* _tmp0_;
	GtkScrolledWindow* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->scrolled_window;
	_tmp1_ = self->scrolled_window;
	g_object_get ((GtkWidget*) _tmp1_, "height-request", &_tmp2_, NULL);
	_tmp3_ = _tmp2_;
	if (gtk_widget_get_height ((GtkWidget*) _tmp0_) == _tmp3_) {
		self->priv->wait_queue_resize = (guint) 0;
		result = FALSE;
		return result;
	} else {
		gtk_widget_queue_resize ((GtkWidget*) self);
		result = TRUE;
		return result;
	}
}

static gboolean
_vala_uint_array_contains (guint * stack,
                           gssize stack_length,
                           const guint needle)
{
	gssize i;
	for (i = 0; i < stack_length; i++) {
		if (needle == stack[i]) {
			return TRUE;
		}
	}
	return FALSE;
}

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

static gboolean
dino_ui_chat_text_view_on_text_input_key_press (DinoUiChatTextView* self,
                                                GtkEventControllerKey* controller,
                                                guint keyval,
                                                guint keycode,
                                                GdkModifierType state)
{
	guint* _tmp0_;
	guint* _tmp1_;
	gint _tmp1__length1;
	gboolean _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (controller != NULL, FALSE);
	_tmp0_ = g_new0 (guint, 2);
	_tmp0_[0] = GDK_KEY_Return;
	_tmp0_[1] = GDK_KEY_KP_Enter;
	_tmp1_ = _tmp0_;
	_tmp1__length1 = 2;
	_tmp2_ = _vala_uint_array_contains (_tmp1_, 2, keyval);
	_tmp1_ = (g_free (_tmp1_), NULL);
	if (_tmp2_) {
		GtkTextView* _tmp3_;
		GdkEvent* _tmp4_;
		_tmp3_ = self->text_view;
		_tmp4_ = gtk_event_controller_get_current_event ((GtkEventController*) controller);
		if (gtk_text_view_im_context_filter_keypress (_tmp3_, _tmp4_)) {
			result = TRUE;
			return result;
		}
		if ((state & GDK_SHIFT_MASK) > 0) {
			result = FALSE;
			return result;
		} else {
			GtkTextView* _tmp5_;
			GtkTextBuffer* _tmp6_;
			GtkTextBuffer* _tmp7_;
			gchar* _tmp8_;
			gchar* _tmp9_;
			gchar* _tmp10_;
			gchar* _tmp11_;
			gchar* _tmp12_;
			gboolean _tmp13_;
			_tmp5_ = self->text_view;
			_tmp6_ = gtk_text_view_get_buffer (_tmp5_);
			_tmp7_ = _tmp6_;
			g_object_get (_tmp7_, "text", &_tmp8_, NULL);
			_tmp9_ = _tmp8_;
			_tmp10_ = _tmp9_;
			_tmp11_ = string_strip (_tmp10_);
			_tmp12_ = _tmp11_;
			_tmp13_ = g_strcmp0 (_tmp12_, "") != 0;
			_g_free0 (_tmp12_);
			_g_free0 (_tmp10_);
			if (_tmp13_) {
				g_signal_emit (self, dino_ui_chat_text_view_signals[DINO_UI_CHAT_TEXT_VIEW_SEND_TEXT_SIGNAL], 0);
			}
		}
		result = TRUE;
		return result;
	}
	if (keyval == GDK_KEY_Escape) {
		g_signal_emit (self, dino_ui_chat_text_view_signals[DINO_UI_CHAT_TEXT_VIEW_CANCEL_INPUT_SIGNAL], 0);
	}
	if ((state & GDK_CONTROL_MASK) > 0) {
		guint* _tmp14_;
		guint* _tmp15_;
		gint _tmp15__length1;
		gboolean _tmp16_;
		_tmp14_ = g_new0 (guint, 2);
		_tmp14_[0] = GDK_KEY_i;
		_tmp14_[1] = GDK_KEY_b;
		_tmp15_ = _tmp14_;
		_tmp15__length1 = 2;
		_tmp16_ = _vala_uint_array_contains (_tmp15_, 2, keyval);
		_tmp15_ = (g_free (_tmp15_), NULL);
		if (_tmp16_) {
			GtkTextIter start_selection = {0};
			GtkTextIter end_selection = {0};
			GtkTextView* _tmp17_;
			GtkTextBuffer* _tmp18_;
			GtkTextBuffer* _tmp19_;
			GtkTextIter _tmp20_ = {0};
			GtkTextIter _tmp21_ = {0};
			GtkTextTag* tag = NULL;
			gboolean already_formatted = FALSE;
			GeeList* markup_types = NULL;
			GtkTextIter _tmp22_;
			GeeList* _tmp23_;
			GtkTextTag* _tmp33_;
			_tmp17_ = self->text_view;
			_tmp18_ = gtk_text_view_get_buffer (_tmp17_);
			_tmp19_ = _tmp18_;
			gtk_text_buffer_get_selection_bounds (_tmp19_, &_tmp20_, &_tmp21_);
			start_selection = _tmp20_;
			end_selection = _tmp21_;
			tag = NULL;
			already_formatted = FALSE;
			_tmp22_ = start_selection;
			_tmp23_ = dino_ui_chat_text_view_get_markup_types_from_iter (self, &_tmp22_);
			markup_types = _tmp23_;
			if (keyval == GDK_KEY_i) {
				GtkTextTag* _tmp24_;
				GtkTextTag* _tmp25_;
				GeeList* _tmp26_;
				_tmp24_ = self->priv->italic_tag;
				_tmp25_ = _g_object_ref0 (_tmp24_);
				_g_object_unref0 (tag);
				tag = _tmp25_;
				_tmp26_ = markup_types;
				already_formatted = gee_collection_contains ((GeeCollection*) _tmp26_, (gpointer) ((gintptr) XMPP_XEP_MESSAGE_MARKUP_SPAN_TYPE_EMPHASIS));
			} else {
				if (keyval == GDK_KEY_b) {
					GtkTextTag* _tmp27_;
					GtkTextTag* _tmp28_;
					GeeList* _tmp29_;
					_tmp27_ = self->priv->bold_tag;
					_tmp28_ = _g_object_ref0 (_tmp27_);
					_g_object_unref0 (tag);
					tag = _tmp28_;
					_tmp29_ = markup_types;
					already_formatted = gee_collection_contains ((GeeCollection*) _tmp29_, (gpointer) ((gintptr) XMPP_XEP_MESSAGE_MARKUP_SPAN_TYPE_STRONG_EMPHASIS));
				} else {
					if (keyval == GDK_KEY_s) {
						GtkTextTag* _tmp30_;
						GtkTextTag* _tmp31_;
						GeeList* _tmp32_;
						_tmp30_ = self->priv->strikethrough_tag;
						_tmp31_ = _g_object_ref0 (_tmp30_);
						_g_object_unref0 (tag);
						tag = _tmp31_;
						_tmp32_ = markup_types;
						already_formatted = gee_collection_contains ((GeeCollection*) _tmp32_, (gpointer) ((gintptr) XMPP_XEP_MESSAGE_MARKUP_SPAN_TYPE_DELETED));
					}
				}
			}
			_tmp33_ = tag;
			if (_tmp33_ != NULL) {
				if (already_formatted) {
					GtkTextView* _tmp34_;
					GtkTextBuffer* _tmp35_;
					GtkTextBuffer* _tmp36_;
					GtkTextTag* _tmp37_;
					GtkTextIter _tmp38_;
					GtkTextIter _tmp39_;
					_tmp34_ = self->text_view;
					_tmp35_ = gtk_text_view_get_buffer (_tmp34_);
					_tmp36_ = _tmp35_;
					_tmp37_ = tag;
					_tmp38_ = start_selection;
					_tmp39_ = end_selection;
					gtk_text_buffer_remove_tag (_tmp36_, _tmp37_, &_tmp38_, &_tmp39_);
				} else {
					GtkTextView* _tmp40_;
					GtkTextBuffer* _tmp41_;
					GtkTextBuffer* _tmp42_;
					GtkTextTag* _tmp43_;
					GtkTextIter _tmp44_;
					GtkTextIter _tmp45_;
					_tmp40_ = self->text_view;
					_tmp41_ = gtk_text_view_get_buffer (_tmp40_);
					_tmp42_ = _tmp41_;
					_tmp43_ = tag;
					_tmp44_ = start_selection;
					_tmp45_ = end_selection;
					gtk_text_buffer_apply_tag (_tmp42_, _tmp43_, &_tmp44_, &_tmp45_);
				}
			}
			_g_object_unref0 (markup_types);
			_g_object_unref0 (tag);
		}
	}
	result = FALSE;
	return result;
}

GeeList*
dino_ui_chat_text_view_get_markups (DinoUiChatTextView* self)
{
	GeeHashMap* markups = NULL;
	GeeHashMap* _tmp0_;
	GeeHashMap* _tmp1_;
	GeeHashMap* _tmp2_;
	GeeHashMap* _tmp3_;
	GeeArrayList* ended_groups = NULL;
	GeeArrayList* _tmp4_;
	XmppXepMessageMarkupSpan* current_span = NULL;
	GtkTextIter iter = {0};
	GtkTextView* _tmp5_;
	GtkTextBuffer* _tmp6_;
	GtkTextBuffer* _tmp7_;
	GtkTextIter _tmp8_ = {0};
	gint i = 0;
	XmppXepMessageMarkupSpan* _tmp34_;
	GeeList* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = gee_hash_map_new (XMPP_XEP_MESSAGE_MARKUP_TYPE_SPAN_TYPE, NULL, NULL, XMPP_XEP_MESSAGE_MARKUP_TYPE_SPAN_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	markups = _tmp0_;
	_tmp1_ = markups;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp1_, (gpointer) ((gintptr) XMPP_XEP_MESSAGE_MARKUP_SPAN_TYPE_EMPHASIS), (gpointer) ((gintptr) XMPP_XEP_MESSAGE_MARKUP_SPAN_TYPE_EMPHASIS));
	_tmp2_ = markups;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp2_, (gpointer) ((gintptr) XMPP_XEP_MESSAGE_MARKUP_SPAN_TYPE_STRONG_EMPHASIS), (gpointer) ((gintptr) XMPP_XEP_MESSAGE_MARKUP_SPAN_TYPE_STRONG_EMPHASIS));
	_tmp3_ = markups;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp3_, (gpointer) ((gintptr) XMPP_XEP_MESSAGE_MARKUP_SPAN_TYPE_DELETED), (gpointer) ((gintptr) XMPP_XEP_MESSAGE_MARKUP_SPAN_TYPE_DELETED));
	_tmp4_ = gee_array_list_new (XMPP_XEP_MESSAGE_MARKUP_TYPE_SPAN, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	ended_groups = _tmp4_;
	current_span = NULL;
	_tmp5_ = self->text_view;
	_tmp6_ = gtk_text_view_get_buffer (_tmp5_);
	_tmp7_ = _tmp6_;
	gtk_text_buffer_get_start_iter (_tmp7_, &_tmp8_);
	iter = _tmp8_;
	i = 0;
	{
		gboolean _tmp9_ = FALSE;
		_tmp9_ = TRUE;
		while (TRUE) {
			GeeList* char_markups = NULL;
			GtkTextIter _tmp10_;
			GeeList* _tmp11_;
			gboolean _tmp12_ = FALSE;
			XmppXepMessageMarkupSpan* _tmp13_;
			GeeList* _tmp25_;
			gint _tmp26_;
			gint _tmp27_;
			gint _tmp33_;
			if (!_tmp9_) {
				if (!gtk_text_iter_forward_char (&iter)) {
					break;
				}
			}
			_tmp9_ = FALSE;
			_tmp10_ = iter;
			_tmp11_ = dino_ui_chat_text_view_get_markup_types_from_iter (self, &_tmp10_);
			char_markups = _tmp11_;
			_tmp13_ = current_span;
			if (_tmp13_ != NULL) {
				gboolean _tmp14_ = FALSE;
				GeeList* _tmp15_;
				XmppXepMessageMarkupSpan* _tmp16_;
				GeeList* _tmp17_;
				GeeList* _tmp18_;
				_tmp15_ = char_markups;
				_tmp16_ = current_span;
				_tmp17_ = xmpp_xep_message_markup_span_get_types (_tmp16_);
				_tmp18_ = _tmp17_;
				if (!gee_collection_contains_all ((GeeCollection*) _tmp15_, (GeeCollection*) _tmp18_)) {
					_tmp14_ = TRUE;
				} else {
					XmppXepMessageMarkupSpan* _tmp19_;
					GeeList* _tmp20_;
					GeeList* _tmp21_;
					GeeList* _tmp22_;
					_tmp19_ = current_span;
					_tmp20_ = xmpp_xep_message_markup_span_get_types (_tmp19_);
					_tmp21_ = _tmp20_;
					_tmp22_ = char_markups;
					_tmp14_ = !gee_collection_contains_all ((GeeCollection*) _tmp21_, (GeeCollection*) _tmp22_);
				}
				_tmp12_ = _tmp14_;
			} else {
				_tmp12_ = FALSE;
			}
			if (_tmp12_) {
				GeeArrayList* _tmp23_;
				XmppXepMessageMarkupSpan* _tmp24_;
				_tmp23_ = ended_groups;
				_tmp24_ = current_span;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp23_, _tmp24_);
				_g_object_unref0 (current_span);
				current_span = NULL;
			}
			_tmp25_ = char_markups;
			_tmp26_ = gee_collection_get_size ((GeeCollection*) _tmp25_);
			_tmp27_ = _tmp26_;
			if (_tmp27_ > 0) {
				XmppXepMessageMarkupSpan* _tmp28_;
				_tmp28_ = current_span;
				if (_tmp28_ == NULL) {
					GeeList* _tmp29_;
					GeeList* _tmp30_;
					XmppXepMessageMarkupSpan* _tmp31_ = NULL;
					_tmp29_ = char_markups;
					_tmp30_ = _g_object_ref0 (_tmp29_);
					_tmp31_ = xmpp_xep_message_markup_span_new ();
					xmpp_xep_message_markup_span_set_types (_tmp31_, _tmp30_);
					_g_object_unref0 (_tmp30_);
					xmpp_xep_message_markup_span_set_start_char (_tmp31_, i);
					xmpp_xep_message_markup_span_set_end_char (_tmp31_, i + 1);
					_g_object_unref0 (current_span);
					current_span = _tmp31_;
				} else {
					XmppXepMessageMarkupSpan* _tmp32_;
					_tmp32_ = current_span;
					xmpp_xep_message_markup_span_set_end_char (_tmp32_, i + 1);
				}
			}
			_tmp33_ = i;
			i = _tmp33_ + 1;
			_g_object_unref0 (char_markups);
		}
	}
	_tmp34_ = current_span;
	if (_tmp34_ != NULL) {
		GeeArrayList* _tmp35_;
		XmppXepMessageMarkupSpan* _tmp36_;
		_tmp35_ = ended_groups;
		_tmp36_ = current_span;
		gee_abstract_collection_add ((GeeAbstractCollection*) _tmp35_, _tmp36_);
	}
	result = (GeeList*) ended_groups;
	_g_object_unref0 (current_span);
	_g_object_unref0 (markups);
	return result;
}

static GeeList*
dino_ui_chat_text_view_get_markup_types_from_iter (DinoUiChatTextView* self,
                                                   GtkTextIter* iter)
{
	GeeArrayList* ret = NULL;
	GeeArrayList* _tmp0_;
	GSList* _tmp1_;
	GeeList* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (iter != NULL, NULL);
	_tmp0_ = gee_array_list_new (XMPP_XEP_MESSAGE_MARKUP_TYPE_SPAN_TYPE, NULL, NULL, NULL, NULL, NULL);
	ret = _tmp0_;
	_tmp1_ = gtk_text_iter_get_tags (iter);
	{
		GSList* tag_collection = NULL;
		GSList* tag_it = NULL;
		tag_collection = _tmp1_;
		for (tag_it = tag_collection; tag_it != NULL; tag_it = tag_it->next) {
			GtkTextTag* _tmp2_;
			GtkTextTag* tag = NULL;
			_tmp2_ = _g_object_ref0 ((GtkTextTag*) tag_it->data);
			tag = _tmp2_;
			{
				GtkTextTag* _tmp3_;
				PangoStyle _tmp4_;
				PangoStyle _tmp5_;
				_tmp3_ = tag;
				g_object_get (_tmp3_, "style", &_tmp4_, NULL);
				_tmp5_ = _tmp4_;
				if (_tmp5_ == PANGO_STYLE_ITALIC) {
					GeeArrayList* _tmp6_;
					_tmp6_ = ret;
					gee_abstract_collection_add ((GeeAbstractCollection*) _tmp6_, (gpointer) ((gintptr) XMPP_XEP_MESSAGE_MARKUP_SPAN_TYPE_EMPHASIS));
				} else {
					GtkTextTag* _tmp7_;
					gint _tmp8_;
					gint _tmp9_;
					_tmp7_ = tag;
					g_object_get (_tmp7_, "weight", &_tmp8_, NULL);
					_tmp9_ = _tmp8_;
					if (_tmp9_ == ((gint) PANGO_WEIGHT_BOLD)) {
						GeeArrayList* _tmp10_;
						_tmp10_ = ret;
						gee_abstract_collection_add ((GeeAbstractCollection*) _tmp10_, (gpointer) ((gintptr) XMPP_XEP_MESSAGE_MARKUP_SPAN_TYPE_STRONG_EMPHASIS));
					} else {
						GtkTextTag* _tmp11_;
						gboolean _tmp12_;
						gboolean _tmp13_;
						_tmp11_ = tag;
						g_object_get (_tmp11_, "strikethrough", &_tmp12_, NULL);
						_tmp13_ = _tmp12_;
						if (_tmp13_) {
							GeeArrayList* _tmp14_;
							_tmp14_ = ret;
							gee_abstract_collection_add ((GeeAbstractCollection*) _tmp14_, (gpointer) ((gintptr) XMPP_XEP_MESSAGE_MARKUP_SPAN_TYPE_DELETED));
						}
					}
				}
				_g_object_unref0 (tag);
			}
		}
		(tag_collection == NULL) ? NULL : (tag_collection = (g_slist_free (tag_collection), NULL));
	}
	result = (GeeList*) ret;
	return result;
}

DinoUiChatTextView*
dino_ui_chat_text_view_construct (GType object_type)
{
	DinoUiChatTextView * self = NULL;
	self = (DinoUiChatTextView*) g_object_new (object_type, NULL);
	return self;
}

DinoUiChatTextView*
dino_ui_chat_text_view_new (void)
{
	return dino_ui_chat_text_view_construct (DINO_UI_TYPE_CHAT_TEXT_VIEW);
}

static gboolean
_dino_ui_chat_text_view_on_text_input_key_press_gtk_event_controller_key_key_pressed (GtkEventControllerKey* _sender,
                                                                                      guint keyval,
                                                                                      guint keycode,
                                                                                      GdkModifierType state,
                                                                                      gpointer self)
{
	gboolean result;
	result = dino_ui_chat_text_view_on_text_input_key_press ((DinoUiChatTextView*) self, _sender, keyval, keycode, state);
	return result;
}

static void
_dino_ui_chat_text_view_on_upper_notify_gtk_adjustment_changed (GtkAdjustment* _sender,
                                                                gpointer self)
{
	dino_ui_chat_text_view_on_upper_notify ((DinoUiChatTextView*) self);
}

static void
_dino_ui_chat_text_view___lambda4_ (DinoUiChatTextView* self)
{
	GtkRequisition minimum_size = {0};
	GtkScrolledWindow* _tmp0_;
	GtkRequisition _tmp1_ = {0};
	GtkRequisition _tmp2_;
	memset (&minimum_size, 0, sizeof (GtkRequisition));
	_tmp0_ = self->scrolled_window;
	gtk_widget_get_preferred_size ((GtkWidget*) _tmp0_, &_tmp1_, NULL);
	minimum_size = _tmp1_;
	_tmp2_ = minimum_size;
	self->priv->vscrollbar_min_height = _tmp2_.height;
}

static void
__dino_ui_chat_text_view___lambda4__gtk_widget_realize (GtkWidget* _sender,
                                                        gpointer self)
{
	_dino_ui_chat_text_view___lambda4_ ((DinoUiChatTextView*) self);
}

static GObject *
dino_ui_chat_text_view_constructor (GType type,
                                    guint n_construct_properties,
                                    GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	DinoUiChatTextView * self;
	GtkScrolledWindow* _tmp0_;
	GtkTextView* _tmp1_;
	GtkScrolledWindow* _tmp2_;
	GtkEventControllerKey* text_input_key_events = NULL;
	gchar* _tmp3_;
	GtkEventControllerKey* _tmp4_ = NULL;
	GtkEventControllerKey* _tmp5_;
	GtkTextView* _tmp6_;
	GtkEventControllerKey* _tmp7_;
	GtkEventController* _tmp8_;
	GtkTextView* _tmp9_;
	GtkTextBuffer* _tmp10_;
	GtkTextBuffer* _tmp11_;
	GtkTextTag* _tmp12_;
	GtkTextTag* _tmp13_;
	GtkTextTag* _tmp14_;
	GtkTextView* _tmp15_;
	GtkTextBuffer* _tmp16_;
	GtkTextBuffer* _tmp17_;
	GtkTextTag* _tmp18_;
	GtkTextTag* _tmp19_;
	GtkTextTag* _tmp20_;
	GtkTextView* _tmp21_;
	GtkTextBuffer* _tmp22_;
	GtkTextBuffer* _tmp23_;
	GtkTextTag* _tmp24_;
	GtkTextTag* _tmp25_;
	GtkTextTag* _tmp26_;
	GtkTextView* _tmp27_;
	DinoUiSmileyConverter* _tmp28_;
	GtkScrolledWindow* _tmp29_;
	GtkAdjustment* _tmp30_;
	GtkAdjustment* _tmp31_;
	GtkTextView* _tmp32_;
	parent_class = G_OBJECT_CLASS (dino_ui_chat_text_view_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_UI_TYPE_CHAT_TEXT_VIEW, DinoUiChatTextView);
	gtk_widget_set_valign ((GtkWidget*) self, GTK_ALIGN_CENTER);
	_tmp0_ = self->scrolled_window;
	_tmp1_ = self->text_view;
	gtk_scrolled_window_set_child (_tmp0_, (GtkWidget*) _tmp1_);
	_tmp2_ = self->scrolled_window;
	gtk_box_append ((GtkBox*) self, (GtkWidget*) _tmp2_);
	_tmp3_ = g_strdup ("dino-text-input-view-key-events");
	_tmp4_ = (GtkEventControllerKey*) gtk_event_controller_key_new ();
	gtk_event_controller_set_name ((GtkEventController*) _tmp4_, _tmp3_);
	_g_free0 (_tmp3_);
	text_input_key_events = _tmp4_;
	_tmp5_ = text_input_key_events;
	g_signal_connect_object (_tmp5_, "key-pressed", (GCallback) _dino_ui_chat_text_view_on_text_input_key_press_gtk_event_controller_key_key_pressed, self, 0);
	_tmp6_ = self->text_view;
	_tmp7_ = text_input_key_events;
	_tmp8_ = _g_object_ref0 ((GtkEventController*) _tmp7_);
	gtk_widget_add_controller ((GtkWidget*) _tmp6_, _tmp8_);
	_tmp9_ = self->text_view;
	_tmp10_ = gtk_text_view_get_buffer (_tmp9_);
	_tmp11_ = _tmp10_;
	_tmp12_ = gtk_text_buffer_create_tag (_tmp11_, "italic", NULL);
	_tmp13_ = _g_object_ref0 (_tmp12_);
	_g_object_unref0 (self->priv->italic_tag);
	self->priv->italic_tag = _tmp13_;
	_tmp14_ = self->priv->italic_tag;
	g_object_set (_tmp14_, "style", PANGO_STYLE_ITALIC, NULL);
	_tmp15_ = self->text_view;
	_tmp16_ = gtk_text_view_get_buffer (_tmp15_);
	_tmp17_ = _tmp16_;
	_tmp18_ = gtk_text_buffer_create_tag (_tmp17_, "bold", NULL);
	_tmp19_ = _g_object_ref0 (_tmp18_);
	_g_object_unref0 (self->priv->bold_tag);
	self->priv->bold_tag = _tmp19_;
	_tmp20_ = self->priv->bold_tag;
	g_object_set (_tmp20_, "weight", (gint) PANGO_WEIGHT_BOLD, NULL);
	_tmp21_ = self->text_view;
	_tmp22_ = gtk_text_view_get_buffer (_tmp21_);
	_tmp23_ = _tmp22_;
	_tmp24_ = gtk_text_buffer_create_tag (_tmp23_, "strikethrough", NULL);
	_tmp25_ = _g_object_ref0 (_tmp24_);
	_g_object_unref0 (self->priv->strikethrough_tag);
	self->priv->strikethrough_tag = _tmp25_;
	_tmp26_ = self->priv->strikethrough_tag;
	g_object_set (_tmp26_, "strikethrough", TRUE, NULL);
	_tmp27_ = self->text_view;
	_tmp28_ = dino_ui_smiley_converter_new (_tmp27_);
	_dino_ui_smiley_converter_unref0 (self->priv->smiley_converter);
	self->priv->smiley_converter = _tmp28_;
	_tmp29_ = self->scrolled_window;
	_tmp30_ = gtk_scrolled_window_get_vadjustment (_tmp29_);
	_tmp31_ = _tmp30_;
	g_signal_connect_object (_tmp31_, "changed", (GCallback) _dino_ui_chat_text_view_on_upper_notify_gtk_adjustment_changed, self, 0);
	_tmp32_ = self->text_view;
	g_signal_connect_object ((GtkWidget*) _tmp32_, "realize", (GCallback) __dino_ui_chat_text_view___lambda4__gtk_widget_realize, self, 0);
	_g_object_unref0 (text_input_key_events);
	return obj;
}

static void
dino_ui_chat_text_view_class_init (DinoUiChatTextViewClass * klass,
                                   gpointer klass_data)
{
	dino_ui_chat_text_view_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoUiChatTextView_private_offset);
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) dino_ui_chat_text_view_real_dispose;
	G_OBJECT_CLASS (klass)->constructor = dino_ui_chat_text_view_constructor;
	G_OBJECT_CLASS (klass)->finalize = dino_ui_chat_text_view_finalize;
	dino_ui_chat_text_view_signals[DINO_UI_CHAT_TEXT_VIEW_SEND_TEXT_SIGNAL] = g_signal_new ("send-text", DINO_UI_TYPE_CHAT_TEXT_VIEW, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	dino_ui_chat_text_view_signals[DINO_UI_CHAT_TEXT_VIEW_CANCEL_INPUT_SIGNAL] = g_signal_new ("cancel-input", DINO_UI_TYPE_CHAT_TEXT_VIEW, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
dino_ui_chat_text_view_instance_init (DinoUiChatTextView * self,
                                      gpointer klass)
{
	GtkScrolledWindow* _tmp0_ = NULL;
	GtkTextView* _tmp1_ = NULL;
	self->priv = dino_ui_chat_text_view_get_instance_private (self);
	_tmp0_ = (GtkScrolledWindow*) gtk_scrolled_window_new ();
	gtk_scrolled_window_set_propagate_natural_height (_tmp0_, TRUE);
	gtk_scrolled_window_set_max_content_height (_tmp0_, 300);
	gtk_widget_set_hexpand ((GtkWidget*) _tmp0_, TRUE);
	g_object_ref_sink (_tmp0_);
	self->scrolled_window = _tmp0_;
	_tmp1_ = (GtkTextView*) gtk_text_view_new ();
	gtk_widget_set_hexpand ((GtkWidget*) _tmp1_, TRUE);
	gtk_text_view_set_wrap_mode (_tmp1_, GTK_WRAP_WORD_CHAR);
	gtk_widget_set_valign ((GtkWidget*) _tmp1_, GTK_ALIGN_CENTER);
	gtk_widget_set_margin_top ((GtkWidget*) _tmp1_, 7);
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp1_, 7);
	g_object_ref_sink (_tmp1_);
	self->text_view = _tmp1_;
}

static void
dino_ui_chat_text_view_finalize (GObject * obj)
{
	DinoUiChatTextView * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_UI_TYPE_CHAT_TEXT_VIEW, DinoUiChatTextView);
	_g_object_unref0 (self->scrolled_window);
	_g_object_unref0 (self->text_view);
	_dino_ui_smiley_converter_unref0 (self->priv->smiley_converter);
	_g_object_unref0 (self->priv->italic_tag);
	_g_object_unref0 (self->priv->bold_tag);
	_g_object_unref0 (self->priv->strikethrough_tag);
	G_OBJECT_CLASS (dino_ui_chat_text_view_parent_class)->finalize (obj);
}

static GType
dino_ui_chat_text_view_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoUiChatTextViewClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_ui_chat_text_view_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoUiChatTextView), 0, (GInstanceInitFunc) dino_ui_chat_text_view_instance_init, NULL };
	GType dino_ui_chat_text_view_type_id;
	dino_ui_chat_text_view_type_id = g_type_register_static (gtk_box_get_type (), "DinoUiChatTextView", &g_define_type_info, 0);
	DinoUiChatTextView_private_offset = g_type_add_instance_private (dino_ui_chat_text_view_type_id, sizeof (DinoUiChatTextViewPrivate));
	return dino_ui_chat_text_view_type_id;
}

GType
dino_ui_chat_text_view_get_type (void)
{
	static volatile gsize dino_ui_chat_text_view_type_id__once = 0;
	if (g_once_init_enter (&dino_ui_chat_text_view_type_id__once)) {
		GType dino_ui_chat_text_view_type_id;
		dino_ui_chat_text_view_type_id = dino_ui_chat_text_view_get_type_once ();
		g_once_init_leave (&dino_ui_chat_text_view_type_id__once, dino_ui_chat_text_view_type_id);
	}
	return dino_ui_chat_text_view_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;
}

