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

/*
 * Copyright © 2023 Alain M. (https://github.com/alainm23/planify)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 *
 * Authored by: Alain M. <alainmh23@gmail.com>
 */

#include <adwaita.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gtk/gtk.h>
#include "planify.h"
#include <gee.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 WIDGETS_TYPE_EDITABLE_TEXT_VIEW (widgets_editable_text_view_get_type ())
#define WIDGETS_EDITABLE_TEXT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WIDGETS_TYPE_EDITABLE_TEXT_VIEW, WidgetsEditableTextView))
#define WIDGETS_EDITABLE_TEXT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WIDGETS_TYPE_EDITABLE_TEXT_VIEW, WidgetsEditableTextViewClass))
#define WIDGETS_IS_EDITABLE_TEXT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WIDGETS_TYPE_EDITABLE_TEXT_VIEW))
#define WIDGETS_IS_EDITABLE_TEXT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WIDGETS_TYPE_EDITABLE_TEXT_VIEW))
#define WIDGETS_EDITABLE_TEXT_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WIDGETS_TYPE_EDITABLE_TEXT_VIEW, WidgetsEditableTextViewClass))

typedef struct _WidgetsEditableTextView WidgetsEditableTextView;
typedef struct _WidgetsEditableTextViewClass WidgetsEditableTextViewClass;
typedef struct _WidgetsEditableTextViewPrivate WidgetsEditableTextViewPrivate;
enum  {
	WIDGETS_EDITABLE_TEXT_VIEW_0_PROPERTY,
	WIDGETS_EDITABLE_TEXT_VIEW_PLACEHOLDER_TEXT_PROPERTY,
	WIDGETS_EDITABLE_TEXT_VIEW_MAX_CHARS_PROPERTY,
	WIDGETS_EDITABLE_TEXT_VIEW_TEXT_PROPERTY,
	WIDGETS_EDITABLE_TEXT_VIEW_IS_EDITING_PROPERTY,
	WIDGETS_EDITABLE_TEXT_VIEW_EDITABLE_PROPERTY,
	WIDGETS_EDITABLE_TEXT_VIEW_NUM_PROPERTIES
};
static GParamSpec* widgets_editable_text_view_properties[WIDGETS_EDITABLE_TEXT_VIEW_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	WIDGETS_EDITABLE_TEXT_VIEW_FOCUS_CHANGED_SIGNAL,
	WIDGETS_EDITABLE_TEXT_VIEW_CHANGED_SIGNAL,
	WIDGETS_EDITABLE_TEXT_VIEW_NUM_SIGNALS
};
static guint widgets_editable_text_view_signals[WIDGETS_EDITABLE_TEXT_VIEW_NUM_SIGNALS] = {0};

struct _WidgetsEditableTextView {
	AdwBin parent_instance;
	WidgetsEditableTextViewPrivate * priv;
};

struct _WidgetsEditableTextViewClass {
	AdwBinClass parent_class;
};

struct _WidgetsEditableTextViewPrivate {
	gchar* _placeholder_text;
	gint _max_chars;
	GtkBox* main_box;
	WidgetsTextView* textview;
	GtkButton* show_more_button;
	gboolean is_expanded;
	gboolean updating;
	gboolean _is_editing;
	guint timeout_id;
	gchar* _text;
	GeeHashMap* signal_map;
};

static gint WidgetsEditableTextView_private_offset;
static gpointer widgets_editable_text_view_parent_class = NULL;

VALA_EXTERN GType widgets_editable_text_view_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WidgetsEditableTextView, g_object_unref)
VALA_EXTERN void widgets_editable_text_view_editing (WidgetsEditableTextView* self,
                                         gboolean value);
VALA_EXTERN WidgetsEditableTextView* widgets_editable_text_view_new (const gchar* placeholder_text,
                                                         gint max_chars);
VALA_EXTERN WidgetsEditableTextView* widgets_editable_text_view_construct (GType object_type,
                                                               const gchar* placeholder_text,
                                                               gint max_chars);
static void widgets_editable_text_view_update_display (WidgetsEditableTextView* self);
VALA_EXTERN gboolean widgets_editable_text_view_get_is_editing (WidgetsEditableTextView* self);
VALA_EXTERN const gchar* widgets_editable_text_view_get_text (WidgetsEditableTextView* self);
VALA_EXTERN gint widgets_editable_text_view_get_max_chars (WidgetsEditableTextView* self);
static void widgets_editable_text_view_start_timeout (WidgetsEditableTextView* self);
static void widgets_editable_text_view_stop_timeout (WidgetsEditableTextView* self);
static gboolean __lambda554_ (WidgetsEditableTextView* self);
static gboolean ___lambda554__gsource_func (gpointer self);
static void widgets_editable_text_view_reset_timeout (WidgetsEditableTextView* self);
VALA_EXTERN const gchar* widgets_editable_text_view_get_placeholder_text (WidgetsEditableTextView* self);
static void widgets_editable_text_view_set_placeholder_text (WidgetsEditableTextView* self,
                                                      const gchar* value);
static void widgets_editable_text_view_set_max_chars (WidgetsEditableTextView* self,
                                               gint value);
VALA_EXTERN void widgets_editable_text_view_set_text (WidgetsEditableTextView* self,
                                          const gchar* value);
VALA_EXTERN void widgets_editable_text_view_set_editable (WidgetsEditableTextView* self,
                                              gboolean value);
static GObject * widgets_editable_text_view_constructor (GType type,
                                                  guint n_construct_properties,
                                                  GObjectConstructParam * construct_properties);
static void _widgets_editable_text_view___lambda555_ (WidgetsEditableTextView* self);
static void __widgets_editable_text_view___lambda555__g_object_notify (GObject* _sender,
                                                                GParamSpec* pspec,
                                                                gpointer self);
static void _widgets_editable_text_view_update_display_services_event_bus_mobile_mode_change (ServicesEventBus* _sender,
                                                                                       gpointer self);
static void _widgets_editable_text_view___lambda556_ (WidgetsEditableTextView* self);
static void __widgets_editable_text_view___lambda556__gtk_button_clicked (GtkButton* _sender,
                                                                   gpointer self);
static void _widgets_editable_text_view___lambda557_ (WidgetsEditableTextView* self);
static void __widgets_editable_text_view___lambda557__gtk_event_controller_focus_enter (GtkEventControllerFocus* _sender,
                                                                                 gpointer self);
static void _widgets_editable_text_view___lambda558_ (WidgetsEditableTextView* self);
static void __widgets_editable_text_view___lambda558__gtk_event_controller_focus_leave (GtkEventControllerFocus* _sender,
                                                                                 gpointer self);
static void _widgets_editable_text_view___lambda559_ (WidgetsEditableTextView* self);
static void __widgets_editable_text_view___lambda559__gtk_text_buffer_changed (GtkTextBuffer* _sender,
                                                                        gpointer self);
static void _widgets_editable_text_view___lambda560_ (WidgetsEditableTextView* self);
static void __widgets_editable_text_view___lambda560__gtk_widget_destroy (GtkWidget* _sender,
                                                                   gpointer self);
static void widgets_editable_text_view_finalize (GObject * obj);
static GType widgets_editable_text_view_get_type_once (void);
static void _vala_widgets_editable_text_view_get_property (GObject * object,
                                                    guint property_id,
                                                    GValue * value,
                                                    GParamSpec * pspec);
static void _vala_widgets_editable_text_view_set_property (GObject * object,
                                                    guint property_id,
                                                    const GValue * value,
                                                    GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

static inline gpointer
widgets_editable_text_view_get_instance_private (WidgetsEditableTextView* self)
{
	return G_STRUCT_MEMBER_P (self, WidgetsEditableTextView_private_offset);
}

void
widgets_editable_text_view_editing (WidgetsEditableTextView* self,
                                    gboolean value)
{
	g_return_if_fail (self != NULL);
	g_signal_emit (self, widgets_editable_text_view_signals[WIDGETS_EDITABLE_TEXT_VIEW_FOCUS_CHANGED_SIGNAL], 0, value);
	if (value) {
		WidgetsTextView* _tmp0_;
		_tmp0_ = self->priv->textview;
		gtk_widget_grab_focus ((GtkWidget*) _tmp0_);
	}
}

WidgetsEditableTextView*
widgets_editable_text_view_construct (GType object_type,
                                      const gchar* placeholder_text,
                                      gint max_chars)
{
	WidgetsEditableTextView * self = NULL;
	g_return_val_if_fail (placeholder_text != NULL, NULL);
	self = (WidgetsEditableTextView*) g_object_new (object_type, "placeholder-text", placeholder_text, "max-chars", max_chars, NULL);
	return self;
}

WidgetsEditableTextView*
widgets_editable_text_view_new (const gchar* placeholder_text,
                                gint max_chars)
{
	return widgets_editable_text_view_construct (WIDGETS_TYPE_EDITABLE_TEXT_VIEW, placeholder_text, max_chars);
}

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

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

static 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 void
widgets_editable_text_view_update_display (WidgetsEditableTextView* self)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_;
	gboolean _tmp3_;
	g_return_if_fail (self != NULL);
	self->priv->updating = TRUE;
	_tmp2_ = widgets_editable_text_view_get_is_editing (self);
	_tmp3_ = _tmp2_;
	if (_tmp3_) {
		_tmp1_ = TRUE;
	} else {
		ServicesEventBus* _tmp4_;
		ServicesEventBus* _tmp5_;
		gboolean _tmp6_;
		gboolean _tmp7_;
		_tmp4_ = services_event_bus_get_default ();
		_tmp5_ = _tmp4_;
		_tmp6_ = services_event_bus_get_mobile_mode (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp1_ = !_tmp7_;
		_g_object_unref0 (_tmp5_);
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		const gchar* _tmp8_;
		gint _tmp9_;
		gint _tmp10_;
		gint _tmp11_;
		_tmp8_ = self->priv->_text;
		_tmp9_ = strlen (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp11_ = self->priv->_max_chars;
		_tmp0_ = _tmp10_ <= _tmp11_;
	}
	if (_tmp0_) {
		WidgetsTextView* _tmp12_;
		const gchar* _tmp13_;
		GtkButton* _tmp14_;
		_tmp12_ = self->priv->textview;
		_tmp13_ = self->priv->_text;
		widgets_text_view_set_text (_tmp12_, _tmp13_);
		_tmp14_ = self->priv->show_more_button;
		gtk_widget_set_visible ((GtkWidget*) _tmp14_, FALSE);
	} else {
		if (!self->priv->is_expanded) {
			gchar* truncated = NULL;
			const gchar* _tmp15_;
			gint _tmp16_;
			gchar* _tmp17_;
			gchar* _tmp18_;
			gchar* _tmp19_;
			gchar* _tmp20_;
			gchar* _tmp21_;
			gchar* _tmp22_;
			WidgetsTextView* _tmp23_;
			const gchar* _tmp24_;
			GtkButton* _tmp25_;
			GtkButton* _tmp26_;
			_tmp15_ = self->priv->_text;
			_tmp16_ = self->priv->_max_chars;
			_tmp17_ = string_substring (_tmp15_, (glong) 0, (glong) _tmp16_);
			_tmp18_ = _tmp17_;
			_tmp19_ = string_strip (_tmp18_);
			_tmp20_ = _tmp19_;
			_tmp21_ = g_strconcat (_tmp20_, "…", NULL);
			_tmp22_ = _tmp21_;
			_g_free0 (_tmp20_);
			_g_free0 (_tmp18_);
			truncated = _tmp22_;
			_tmp23_ = self->priv->textview;
			_tmp24_ = truncated;
			widgets_text_view_set_text (_tmp23_, _tmp24_);
			_tmp25_ = self->priv->show_more_button;
			gtk_button_set_label (_tmp25_, _ ("Show more"));
			_tmp26_ = self->priv->show_more_button;
			gtk_widget_set_visible ((GtkWidget*) _tmp26_, TRUE);
			_g_free0 (truncated);
		} else {
			WidgetsTextView* _tmp27_;
			const gchar* _tmp28_;
			GtkButton* _tmp29_;
			GtkButton* _tmp30_;
			_tmp27_ = self->priv->textview;
			_tmp28_ = self->priv->_text;
			widgets_text_view_set_text (_tmp27_, _tmp28_);
			_tmp29_ = self->priv->show_more_button;
			gtk_button_set_label (_tmp29_, _ ("Show less"));
			_tmp30_ = self->priv->show_more_button;
			gtk_widget_set_visible ((GtkWidget*) _tmp30_, TRUE);
		}
	}
	self->priv->updating = FALSE;
}

static gboolean
__lambda554_ (WidgetsEditableTextView* self)
{
	gboolean result;
	if (self->priv->_is_editing) {
		WidgetsTextView* _tmp0_;
		GtkRoot* _tmp1_;
		_tmp0_ = self->priv->textview;
		_tmp1_ = gtk_widget_get_root ((GtkWidget*) _tmp0_);
		gtk_root_set_focus (_tmp1_, NULL);
	}
	self->priv->timeout_id = (guint) 0;
	result = FALSE;
	return result;
}

static gboolean
___lambda554__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda554_ ((WidgetsEditableTextView*) self);
	return result;
}

static void
widgets_editable_text_view_start_timeout (WidgetsEditableTextView* self)
{
	g_return_if_fail (self != NULL);
	widgets_editable_text_view_stop_timeout (self);
	self->priv->timeout_id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) 6, ___lambda554__gsource_func, g_object_ref (self), g_object_unref);
}

static void
widgets_editable_text_view_stop_timeout (WidgetsEditableTextView* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->timeout_id > ((guint) 0)) {
		g_source_remove (self->priv->timeout_id);
		self->priv->timeout_id = (guint) 0;
	}
}

static void
widgets_editable_text_view_reset_timeout (WidgetsEditableTextView* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->_is_editing) {
		widgets_editable_text_view_start_timeout (self);
	}
}

const gchar*
widgets_editable_text_view_get_placeholder_text (WidgetsEditableTextView* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_placeholder_text;
	result = _tmp0_;
	return result;
}

static void
widgets_editable_text_view_set_placeholder_text (WidgetsEditableTextView* self,
                                                 const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = widgets_editable_text_view_get_placeholder_text (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_placeholder_text);
		self->priv->_placeholder_text = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, widgets_editable_text_view_properties[WIDGETS_EDITABLE_TEXT_VIEW_PLACEHOLDER_TEXT_PROPERTY]);
	}
}

gint
widgets_editable_text_view_get_max_chars (WidgetsEditableTextView* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	result = self->priv->_max_chars;
	return result;
}

static void
widgets_editable_text_view_set_max_chars (WidgetsEditableTextView* self,
                                          gint value)
{
	gint old_value;
	g_return_if_fail (self != NULL);
	old_value = widgets_editable_text_view_get_max_chars (self);
	if (old_value != value) {
		self->priv->_max_chars = value;
		g_object_notify_by_pspec ((GObject *) self, widgets_editable_text_view_properties[WIDGETS_EDITABLE_TEXT_VIEW_MAX_CHARS_PROPERTY]);
	}
}

const gchar*
widgets_editable_text_view_get_text (WidgetsEditableTextView* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_text;
	result = _tmp0_;
	return result;
}

void
widgets_editable_text_view_set_text (WidgetsEditableTextView* self,
                                     const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = widgets_editable_text_view_get_text (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_text);
		self->priv->_text = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, widgets_editable_text_view_properties[WIDGETS_EDITABLE_TEXT_VIEW_TEXT_PROPERTY]);
	}
}

gboolean
widgets_editable_text_view_get_is_editing (WidgetsEditableTextView* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_is_editing;
	return result;
}

void
widgets_editable_text_view_set_editable (WidgetsEditableTextView* self,
                                         gboolean value)
{
	WidgetsTextView* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->textview;
	gtk_text_view_set_editable ((GtkTextView*) _tmp0_, value);
	g_object_notify_by_pspec ((GObject *) self, widgets_editable_text_view_properties[WIDGETS_EDITABLE_TEXT_VIEW_EDITABLE_PROPERTY]);
}

static void
_widgets_editable_text_view___lambda555_ (WidgetsEditableTextView* self)
{
	gboolean _tmp0_;
	gboolean _tmp1_;
	_tmp0_ = widgets_editable_text_view_get_is_editing (self);
	_tmp1_ = _tmp0_;
	if (!_tmp1_) {
		widgets_editable_text_view_update_display (self);
	}
}

static void
__widgets_editable_text_view___lambda555__g_object_notify (GObject* _sender,
                                                           GParamSpec* pspec,
                                                           gpointer self)
{
	_widgets_editable_text_view___lambda555_ ((WidgetsEditableTextView*) self);
}

static void
_widgets_editable_text_view_update_display_services_event_bus_mobile_mode_change (ServicesEventBus* _sender,
                                                                                  gpointer self)
{
	widgets_editable_text_view_update_display ((WidgetsEditableTextView*) self);
}

static void
_widgets_editable_text_view___lambda556_ (WidgetsEditableTextView* self)
{
	self->priv->is_expanded = !self->priv->is_expanded;
	widgets_editable_text_view_update_display (self);
}

static void
__widgets_editable_text_view___lambda556__gtk_button_clicked (GtkButton* _sender,
                                                              gpointer self)
{
	_widgets_editable_text_view___lambda556_ ((WidgetsEditableTextView*) self);
}

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

static void
_widgets_editable_text_view___lambda557_ (WidgetsEditableTextView* self)
{
	ServicesEventBus* _tmp0_;
	ServicesEventBus* _tmp1_;
	self->priv->_is_editing = TRUE;
	g_signal_emit (self, widgets_editable_text_view_signals[WIDGETS_EDITABLE_TEXT_VIEW_FOCUS_CHANGED_SIGNAL], 0, TRUE);
	widgets_editable_text_view_update_display (self);
	_tmp0_ = services_event_bus_get_default ();
	_tmp1_ = _tmp0_;
	g_signal_emit_by_name (_tmp1_, "disconnect-typing-accel");
	_g_object_unref0 (_tmp1_);
	widgets_editable_text_view_start_timeout (self);
}

static void
__widgets_editable_text_view___lambda557__gtk_event_controller_focus_enter (GtkEventControllerFocus* _sender,
                                                                            gpointer self)
{
	_widgets_editable_text_view___lambda557_ ((WidgetsEditableTextView*) self);
}

static void
_widgets_editable_text_view___lambda558_ (WidgetsEditableTextView* self)
{
	ServicesEventBus* _tmp0_;
	ServicesEventBus* _tmp1_;
	self->priv->_is_editing = FALSE;
	g_signal_emit (self, widgets_editable_text_view_signals[WIDGETS_EDITABLE_TEXT_VIEW_FOCUS_CHANGED_SIGNAL], 0, FALSE);
	widgets_editable_text_view_update_display (self);
	_tmp0_ = services_event_bus_get_default ();
	_tmp1_ = _tmp0_;
	g_signal_emit_by_name (_tmp1_, "connect-typing-accel");
	_g_object_unref0 (_tmp1_);
	widgets_editable_text_view_stop_timeout (self);
}

static void
__widgets_editable_text_view___lambda558__gtk_event_controller_focus_leave (GtkEventControllerFocus* _sender,
                                                                            gpointer self)
{
	_widgets_editable_text_view___lambda558_ ((WidgetsEditableTextView*) self);
}

static void
_widgets_editable_text_view___lambda559_ (WidgetsEditableTextView* self)
{
	if (!self->priv->updating) {
		WidgetsTextView* _tmp0_;
		gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp0_ = self->priv->textview;
		_tmp1_ = widgets_text_view_get_text (_tmp0_);
		_tmp2_ = _tmp1_;
		widgets_editable_text_view_set_text (self, _tmp2_);
		_g_free0 (_tmp2_);
		g_signal_emit (self, widgets_editable_text_view_signals[WIDGETS_EDITABLE_TEXT_VIEW_CHANGED_SIGNAL], 0);
		widgets_editable_text_view_reset_timeout (self);
	}
}

static void
__widgets_editable_text_view___lambda559__gtk_text_buffer_changed (GtkTextBuffer* _sender,
                                                                   gpointer self)
{
	_widgets_editable_text_view___lambda559_ ((WidgetsEditableTextView*) self);
}

static void
_widgets_editable_text_view___lambda560_ (WidgetsEditableTextView* self)
{
	GeeHashMap* _tmp15_;
	{
		GeeIterator* _entry_it = NULL;
		GeeHashMap* _tmp0_;
		GeeSet* _tmp1_;
		GeeSet* _tmp2_;
		GeeSet* _tmp3_;
		GeeIterator* _tmp4_;
		GeeIterator* _tmp5_;
		_tmp0_ = self->priv->signal_map;
		_tmp1_ = gee_abstract_map_get_entries ((GeeAbstractMap*) _tmp0_);
		_tmp2_ = _tmp1_;
		_tmp3_ = _tmp2_;
		_tmp4_ = gee_iterable_iterator ((GeeIterable*) _tmp3_);
		_tmp5_ = _tmp4_;
		_g_object_unref0 (_tmp3_);
		_entry_it = _tmp5_;
		while (TRUE) {
			GeeIterator* _tmp6_;
			GeeMapEntry* entry = NULL;
			GeeIterator* _tmp7_;
			gpointer _tmp8_;
			GeeMapEntry* _tmp9_;
			gconstpointer _tmp10_;
			gconstpointer _tmp11_;
			GeeMapEntry* _tmp12_;
			gconstpointer _tmp13_;
			gconstpointer _tmp14_;
			_tmp6_ = _entry_it;
			if (!gee_iterator_next (_tmp6_)) {
				break;
			}
			_tmp7_ = _entry_it;
			_tmp8_ = gee_iterator_get (_tmp7_);
			entry = (GeeMapEntry*) _tmp8_;
			_tmp9_ = entry;
			_tmp10_ = gee_map_entry_get_value (_tmp9_);
			_tmp11_ = _tmp10_;
			_tmp12_ = entry;
			_tmp13_ = gee_map_entry_get_key (_tmp12_);
			_tmp14_ = _tmp13_;
			g_signal_handler_disconnect ((GObject*) _tmp11_, (gulong) ((guintptr) _tmp14_));
			_g_object_unref0 (entry);
		}
		_g_object_unref0 (_entry_it);
	}
	_tmp15_ = self->priv->signal_map;
	gee_abstract_map_clear ((GeeAbstractMap*) _tmp15_);
}

static void
__widgets_editable_text_view___lambda560__gtk_widget_destroy (GtkWidget* _sender,
                                                              gpointer self)
{
	_widgets_editable_text_view___lambda560_ ((WidgetsEditableTextView*) self);
}

static GObject *
widgets_editable_text_view_constructor (GType type,
                                        guint n_construct_properties,
                                        GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	WidgetsEditableTextView * self;
	gchar* _tmp0_;
	gchar** _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	WidgetsTextView* _tmp4_ = NULL;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar** _tmp7_;
	GtkButton* _tmp8_ = NULL;
	GtkBox* _tmp9_;
	GtkBox* _tmp10_;
	WidgetsTextView* _tmp11_;
	GtkBox* _tmp12_;
	GtkButton* _tmp13_;
	GtkBox* _tmp14_;
	GeeHashMap* _tmp15_;
	gulong _tmp16_;
	GeeHashMap* _tmp17_;
	ServicesEventBus* _tmp18_;
	ServicesEventBus* _tmp19_;
	gulong _tmp20_;
	ServicesEventBus* _tmp21_;
	ServicesEventBus* _tmp22_;
	GeeHashMap* _tmp23_;
	GtkButton* _tmp24_;
	gulong _tmp25_;
	GtkButton* _tmp26_;
	GtkEventControllerFocus* gesture_focus = NULL;
	GtkEventControllerFocus* _tmp27_;
	WidgetsTextView* _tmp28_;
	GtkEventControllerFocus* _tmp29_;
	GtkEventController* _tmp30_;
	GeeHashMap* _tmp31_;
	GtkEventControllerFocus* _tmp32_;
	gulong _tmp33_;
	GtkEventControllerFocus* _tmp34_;
	GeeHashMap* _tmp35_;
	GtkEventControllerFocus* _tmp36_;
	gulong _tmp37_;
	GtkEventControllerFocus* _tmp38_;
	GeeHashMap* _tmp39_;
	WidgetsTextView* _tmp40_;
	GtkTextBuffer* _tmp41_;
	GtkTextBuffer* _tmp42_;
	gulong _tmp43_;
	WidgetsTextView* _tmp44_;
	GtkTextBuffer* _tmp45_;
	GtkTextBuffer* _tmp46_;
	parent_class = G_OBJECT_CLASS (widgets_editable_text_view_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_EDITABLE_TEXT_VIEW, WidgetsEditableTextView);
	_tmp0_ = g_strdup ("flat");
	_tmp1_ = g_new0 (gchar*, 1 + 1);
	_tmp1_[0] = _tmp0_;
	_tmp2_ = self->priv->_placeholder_text;
	_tmp3_ = g_strdup (_tmp2_);
	_tmp4_ = widgets_text_view_new ();
	gtk_text_view_set_wrap_mode ((GtkTextView*) _tmp4_, GTK_WRAP_WORD_CHAR);
	gtk_widget_set_css_classes ((GtkWidget*) _tmp4_, _tmp1_);
	_tmp1_ = (_vala_array_free (_tmp1_, 1, (GDestroyNotify) g_free), NULL);
	widgets_text_view_set_placeholder_text (_tmp4_, _tmp3_);
	_g_free0 (_tmp3_);
	gtk_text_view_set_accepts_tab ((GtkTextView*) _tmp4_, FALSE);
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->priv->textview);
	self->priv->textview = _tmp4_;
	_tmp5_ = g_strdup ("flat");
	_tmp6_ = g_strdup ("caption");
	_tmp7_ = g_new0 (gchar*, 2 + 1);
	_tmp7_[0] = _tmp5_;
	_tmp7_[1] = _tmp6_;
	_tmp8_ = (GtkButton*) gtk_button_new_with_label (_ ("Show more"));
	gtk_widget_set_css_classes ((GtkWidget*) _tmp8_, _tmp7_);
	_tmp7_ = (_vala_array_free (_tmp7_, 2, (GDestroyNotify) g_free), NULL);
	gtk_widget_set_halign ((GtkWidget*) _tmp8_, GTK_ALIGN_CENTER);
	gtk_widget_set_visible ((GtkWidget*) _tmp8_, FALSE);
	g_object_ref_sink (_tmp8_);
	_g_object_unref0 (self->priv->show_more_button);
	self->priv->show_more_button = _tmp8_;
	_tmp9_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
	g_object_ref_sink (_tmp9_);
	_g_object_unref0 (self->priv->main_box);
	self->priv->main_box = _tmp9_;
	_tmp10_ = self->priv->main_box;
	_tmp11_ = self->priv->textview;
	gtk_box_append (_tmp10_, (GtkWidget*) _tmp11_);
	_tmp12_ = self->priv->main_box;
	_tmp13_ = self->priv->show_more_button;
	gtk_box_append (_tmp12_, (GtkWidget*) _tmp13_);
	_tmp14_ = self->priv->main_box;
	adw_bin_set_child ((AdwBin*) self, (GtkWidget*) _tmp14_);
	_tmp15_ = self->priv->signal_map;
	_tmp16_ = g_signal_connect_object ((GObject*) self, "notify::text", (GCallback) __widgets_editable_text_view___lambda555__g_object_notify, self, 0);
	gee_abstract_map_set ((GeeAbstractMap*) _tmp15_, (gpointer) ((guintptr) _tmp16_), (GObject*) self);
	_tmp17_ = self->priv->signal_map;
	_tmp18_ = services_event_bus_get_default ();
	_tmp19_ = _tmp18_;
	_tmp20_ = g_signal_connect_object (_tmp19_, "mobile-mode-change", (GCallback) _widgets_editable_text_view_update_display_services_event_bus_mobile_mode_change, self, 0);
	_tmp21_ = services_event_bus_get_default ();
	_tmp22_ = _tmp21_;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp17_, (gpointer) ((guintptr) _tmp20_), (GObject*) _tmp22_);
	_g_object_unref0 (_tmp22_);
	_g_object_unref0 (_tmp19_);
	_tmp23_ = self->priv->signal_map;
	_tmp24_ = self->priv->show_more_button;
	_tmp25_ = g_signal_connect_object (_tmp24_, "clicked", (GCallback) __widgets_editable_text_view___lambda556__gtk_button_clicked, self, 0);
	_tmp26_ = self->priv->show_more_button;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp23_, (gpointer) ((guintptr) _tmp25_), (GObject*) _tmp26_);
	_tmp27_ = (GtkEventControllerFocus*) gtk_event_controller_focus_new ();
	gesture_focus = _tmp27_;
	_tmp28_ = self->priv->textview;
	_tmp29_ = gesture_focus;
	_tmp30_ = _g_object_ref0 ((GtkEventController*) _tmp29_);
	gtk_widget_add_controller ((GtkWidget*) _tmp28_, _tmp30_);
	_tmp31_ = self->priv->signal_map;
	_tmp32_ = gesture_focus;
	_tmp33_ = g_signal_connect_object (_tmp32_, "enter", (GCallback) __widgets_editable_text_view___lambda557__gtk_event_controller_focus_enter, self, 0);
	_tmp34_ = gesture_focus;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp31_, (gpointer) ((guintptr) _tmp33_), (GObject*) _tmp34_);
	_tmp35_ = self->priv->signal_map;
	_tmp36_ = gesture_focus;
	_tmp37_ = g_signal_connect_object (_tmp36_, "leave", (GCallback) __widgets_editable_text_view___lambda558__gtk_event_controller_focus_leave, self, 0);
	_tmp38_ = gesture_focus;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp35_, (gpointer) ((guintptr) _tmp37_), (GObject*) _tmp38_);
	_tmp39_ = self->priv->signal_map;
	_tmp40_ = self->priv->textview;
	_tmp41_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp40_);
	_tmp42_ = _tmp41_;
	_tmp43_ = g_signal_connect_object (_tmp42_, "changed", (GCallback) __widgets_editable_text_view___lambda559__gtk_text_buffer_changed, self, 0);
	_tmp44_ = self->priv->textview;
	_tmp45_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp44_);
	_tmp46_ = _tmp45_;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp39_, (gpointer) ((guintptr) _tmp43_), (GObject*) _tmp46_);
	g_signal_connect_object ((GtkWidget*) self, "destroy", (GCallback) __widgets_editable_text_view___lambda560__gtk_widget_destroy, self, 0);
	_g_object_unref0 (gesture_focus);
	return obj;
}

static void
widgets_editable_text_view_class_init (WidgetsEditableTextViewClass * klass,
                                       gpointer klass_data)
{
	widgets_editable_text_view_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WidgetsEditableTextView_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_widgets_editable_text_view_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_widgets_editable_text_view_set_property;
	G_OBJECT_CLASS (klass)->constructor = widgets_editable_text_view_constructor;
	G_OBJECT_CLASS (klass)->finalize = widgets_editable_text_view_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_EDITABLE_TEXT_VIEW_PLACEHOLDER_TEXT_PROPERTY, widgets_editable_text_view_properties[WIDGETS_EDITABLE_TEXT_VIEW_PLACEHOLDER_TEXT_PROPERTY] = g_param_spec_string ("placeholder-text", "placeholder-text", "placeholder-text", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_EDITABLE_TEXT_VIEW_MAX_CHARS_PROPERTY, widgets_editable_text_view_properties[WIDGETS_EDITABLE_TEXT_VIEW_MAX_CHARS_PROPERTY] = g_param_spec_int ("max-chars", "max-chars", "max-chars", G_MININT, G_MAXINT, 150, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_EDITABLE_TEXT_VIEW_TEXT_PROPERTY, widgets_editable_text_view_properties[WIDGETS_EDITABLE_TEXT_VIEW_TEXT_PROPERTY] = g_param_spec_string ("text", "text", "text", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_EDITABLE_TEXT_VIEW_IS_EDITING_PROPERTY, widgets_editable_text_view_properties[WIDGETS_EDITABLE_TEXT_VIEW_IS_EDITING_PROPERTY] = g_param_spec_boolean ("is-editing", "is-editing", "is-editing", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_EDITABLE_TEXT_VIEW_EDITABLE_PROPERTY, widgets_editable_text_view_properties[WIDGETS_EDITABLE_TEXT_VIEW_EDITABLE_PROPERTY] = g_param_spec_boolean ("editable", "editable", "editable", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE));
	widgets_editable_text_view_signals[WIDGETS_EDITABLE_TEXT_VIEW_FOCUS_CHANGED_SIGNAL] = g_signal_new ("focus-changed", WIDGETS_TYPE_EDITABLE_TEXT_VIEW, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
	widgets_editable_text_view_signals[WIDGETS_EDITABLE_TEXT_VIEW_CHANGED_SIGNAL] = g_signal_new ("changed", WIDGETS_TYPE_EDITABLE_TEXT_VIEW, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
widgets_editable_text_view_instance_init (WidgetsEditableTextView * self,
                                          gpointer klass)
{
	GeeHashMap* _tmp0_;
	self->priv = widgets_editable_text_view_get_instance_private (self);
	self->priv->_max_chars = 150;
	self->priv->is_expanded = FALSE;
	self->priv->updating = FALSE;
	self->priv->_is_editing = FALSE;
	self->priv->timeout_id = (guint) 0;
	_tmp0_ = gee_hash_map_new (G_TYPE_ULONG, NULL, NULL, G_TYPE_OBJECT, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->signal_map = _tmp0_;
}

static void
widgets_editable_text_view_finalize (GObject * obj)
{
	WidgetsEditableTextView * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_EDITABLE_TEXT_VIEW, WidgetsEditableTextView);
	g_debug ("EditableTextView.vala:68: Destroying Widgets.EditableTextView\n");
	_g_free0 (self->priv->_placeholder_text);
	_g_object_unref0 (self->priv->main_box);
	_g_object_unref0 (self->priv->textview);
	_g_object_unref0 (self->priv->show_more_button);
	_g_free0 (self->priv->_text);
	_g_object_unref0 (self->priv->signal_map);
	G_OBJECT_CLASS (widgets_editable_text_view_parent_class)->finalize (obj);
}

static GType
widgets_editable_text_view_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WidgetsEditableTextViewClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) widgets_editable_text_view_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WidgetsEditableTextView), 0, (GInstanceInitFunc) widgets_editable_text_view_instance_init, NULL };
	GType widgets_editable_text_view_type_id;
	widgets_editable_text_view_type_id = g_type_register_static (adw_bin_get_type (), "WidgetsEditableTextView", &g_define_type_info, 0);
	WidgetsEditableTextView_private_offset = g_type_add_instance_private (widgets_editable_text_view_type_id, sizeof (WidgetsEditableTextViewPrivate));
	return widgets_editable_text_view_type_id;
}

GType
widgets_editable_text_view_get_type (void)
{
	static volatile gsize widgets_editable_text_view_type_id__once = 0;
	if (g_once_init_enter (&widgets_editable_text_view_type_id__once)) {
		GType widgets_editable_text_view_type_id;
		widgets_editable_text_view_type_id = widgets_editable_text_view_get_type_once ();
		g_once_init_leave (&widgets_editable_text_view_type_id__once, widgets_editable_text_view_type_id);
	}
	return widgets_editable_text_view_type_id__once;
}

static void
_vala_widgets_editable_text_view_get_property (GObject * object,
                                               guint property_id,
                                               GValue * value,
                                               GParamSpec * pspec)
{
	WidgetsEditableTextView * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WIDGETS_TYPE_EDITABLE_TEXT_VIEW, WidgetsEditableTextView);
	switch (property_id) {
		case WIDGETS_EDITABLE_TEXT_VIEW_PLACEHOLDER_TEXT_PROPERTY:
		g_value_set_string (value, widgets_editable_text_view_get_placeholder_text (self));
		break;
		case WIDGETS_EDITABLE_TEXT_VIEW_MAX_CHARS_PROPERTY:
		g_value_set_int (value, widgets_editable_text_view_get_max_chars (self));
		break;
		case WIDGETS_EDITABLE_TEXT_VIEW_TEXT_PROPERTY:
		g_value_set_string (value, widgets_editable_text_view_get_text (self));
		break;
		case WIDGETS_EDITABLE_TEXT_VIEW_IS_EDITING_PROPERTY:
		g_value_set_boolean (value, widgets_editable_text_view_get_is_editing (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_widgets_editable_text_view_set_property (GObject * object,
                                               guint property_id,
                                               const GValue * value,
                                               GParamSpec * pspec)
{
	WidgetsEditableTextView * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WIDGETS_TYPE_EDITABLE_TEXT_VIEW, WidgetsEditableTextView);
	switch (property_id) {
		case WIDGETS_EDITABLE_TEXT_VIEW_PLACEHOLDER_TEXT_PROPERTY:
		widgets_editable_text_view_set_placeholder_text (self, g_value_get_string (value));
		break;
		case WIDGETS_EDITABLE_TEXT_VIEW_MAX_CHARS_PROPERTY:
		widgets_editable_text_view_set_max_chars (self, g_value_get_int (value));
		break;
		case WIDGETS_EDITABLE_TEXT_VIEW_TEXT_PROPERTY:
		widgets_editable_text_view_set_text (self, g_value_get_string (value));
		break;
		case WIDGETS_EDITABLE_TEXT_VIEW_EDITABLE_PROPERTY:
		widgets_editable_text_view_set_editable (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

