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

/* Copyright 2016 Software Freedom Conservancy Inc.
 * Copyright 2017 Jens Georg <mail@jensge.org>
 *
 * This software is licensed under the GNU LGPL (version 2.1 or later).
 * See the COPYING file in this distribution.
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <gdk/gdk.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define TYPE_DISMISSABLE_TEXT_VIEW (dismissable_text_view_get_type ())
#define DISMISSABLE_TEXT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DISMISSABLE_TEXT_VIEW, DismissableTextView))
#define DISMISSABLE_TEXT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DISMISSABLE_TEXT_VIEW, DismissableTextViewClass))
#define IS_DISMISSABLE_TEXT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DISMISSABLE_TEXT_VIEW))
#define IS_DISMISSABLE_TEXT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DISMISSABLE_TEXT_VIEW))
#define DISMISSABLE_TEXT_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DISMISSABLE_TEXT_VIEW, DismissableTextViewClass))

typedef struct _DismissableTextView DismissableTextView;
typedef struct _DismissableTextViewClass DismissableTextViewClass;
typedef struct _DismissableTextViewPrivate DismissableTextViewPrivate;
enum  {
	DISMISSABLE_TEXT_VIEW_0_PROPERTY,
	DISMISSABLE_TEXT_VIEW_NUM_PROPERTIES
};
static GParamSpec* dismissable_text_view_properties[DISMISSABLE_TEXT_VIEW_NUM_PROPERTIES];
enum  {
	DISMISSABLE_TEXT_VIEW_EDIT_DONE_SIGNAL,
	DISMISSABLE_TEXT_VIEW_NUM_SIGNALS
};
static guint dismissable_text_view_signals[DISMISSABLE_TEXT_VIEW_NUM_SIGNALS] = {0};

#define TYPE_MULTI_TEXT_ENTRY_DIALOG (multi_text_entry_dialog_get_type ())
#define MULTI_TEXT_ENTRY_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MULTI_TEXT_ENTRY_DIALOG, MultiTextEntryDialog))
#define MULTI_TEXT_ENTRY_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MULTI_TEXT_ENTRY_DIALOG, MultiTextEntryDialogClass))
#define IS_MULTI_TEXT_ENTRY_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MULTI_TEXT_ENTRY_DIALOG))
#define IS_MULTI_TEXT_ENTRY_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MULTI_TEXT_ENTRY_DIALOG))
#define MULTI_TEXT_ENTRY_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MULTI_TEXT_ENTRY_DIALOG, MultiTextEntryDialogClass))

typedef struct _MultiTextEntryDialog MultiTextEntryDialog;
typedef struct _MultiTextEntryDialogClass MultiTextEntryDialogClass;
typedef struct _MultiTextEntryDialogPrivate MultiTextEntryDialogPrivate;
typedef gboolean (*MultiTextEntryDialogOnModifyValidateType) (const gchar* text, gpointer user_data);
enum  {
	MULTI_TEXT_ENTRY_DIALOG_0_PROPERTY,
	MULTI_TEXT_ENTRY_DIALOG_NUM_PROPERTIES
};
static GParamSpec* multi_text_entry_dialog_properties[MULTI_TEXT_ENTRY_DIALOG_NUM_PROPERTIES];

#define TYPE_PAGE_WINDOW (page_window_get_type ())
#define PAGE_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PAGE_WINDOW, PageWindow))
#define PAGE_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PAGE_WINDOW, PageWindowClass))
#define IS_PAGE_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PAGE_WINDOW))
#define IS_PAGE_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PAGE_WINDOW))
#define PAGE_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PAGE_WINDOW, PageWindowClass))

typedef struct _PageWindow PageWindow;
typedef struct _PageWindowClass PageWindowClass;

#define TYPE_APP_WINDOW (app_window_get_type ())
#define APP_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_APP_WINDOW, AppWindow))
#define APP_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_APP_WINDOW, AppWindowClass))
#define IS_APP_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_APP_WINDOW))
#define IS_APP_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_APP_WINDOW))
#define APP_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_APP_WINDOW, AppWindowClass))

typedef struct _AppWindow AppWindow;
typedef struct _AppWindowClass AppWindowClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _DismissableTextView {
	GtkTextView parent_instance;
	DismissableTextViewPrivate * priv;
};

struct _DismissableTextViewClass {
	GtkTextViewClass parent_class;
};

struct _MultiTextEntryDialog {
	GtkDialog parent_instance;
	MultiTextEntryDialogPrivate * priv;
};

struct _MultiTextEntryDialogClass {
	GtkDialogClass parent_class;
};

struct _MultiTextEntryDialogPrivate {
	MultiTextEntryDialogOnModifyValidateType on_modify_validate;
	gpointer on_modify_validate_target;
	DismissableTextView* entry;
};

static gpointer dismissable_text_view_parent_class = NULL;
static gint MultiTextEntryDialog_private_offset;
static gpointer multi_text_entry_dialog_parent_class = NULL;

VALA_EXTERN GType dismissable_text_view_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DismissableTextView, g_object_unref)
static gboolean dismissable_text_view_real_key_press_event (GtkWidget* base,
                                                     GdkEventKey* ev);
VALA_EXTERN DismissableTextView* dismissable_text_view_new (void);
VALA_EXTERN DismissableTextView* dismissable_text_view_construct (GType object_type);
static GType dismissable_text_view_get_type_once (void);
VALA_EXTERN GType multi_text_entry_dialog_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MultiTextEntryDialog, g_object_unref)
VALA_EXTERN MultiTextEntryDialog* multi_text_entry_dialog_new (void);
VALA_EXTERN MultiTextEntryDialog* multi_text_entry_dialog_construct (GType object_type);
VALA_EXTERN gint resources_use_header_bar (void);
static void __lambda21_ (MultiTextEntryDialog* self);
static void ___lambda21__dismissable_text_view_edit_done (DismissableTextView* _sender,
                                                   gpointer self);
VALA_EXTERN void multi_text_entry_dialog_setup (MultiTextEntryDialog* self,
                                    MultiTextEntryDialogOnModifyValidateType modify_validate,
                                    gpointer modify_validate_target,
                                    const gchar* title,
                                    const gchar* label,
                                    const gchar* initial_text);
VALA_EXTERN GType page_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (PageWindow, g_object_unref)
VALA_EXTERN GType app_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (AppWindow, g_object_unref)
VALA_EXTERN AppWindow* app_window_get_instance (void);
VALA_EXTERN gchar* multi_text_entry_dialog_execute (MultiTextEntryDialog* self);
static void multi_text_entry_dialog_finalize (GObject * obj);
static GType multi_text_entry_dialog_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static gboolean
dismissable_text_view_real_key_press_event (GtkWidget* base,
                                            GdkEventKey* ev)
{
	DismissableTextView * self;
	gboolean _tmp0_ = FALSE;
	const gchar* _tmp1_;
	gboolean result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, TYPE_DISMISSABLE_TEXT_VIEW, DismissableTextView);
	g_return_val_if_fail (ev != NULL, FALSE);
	if (!((ev->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)) {
		result = GTK_WIDGET_CLASS (dismissable_text_view_parent_class)->key_press_event (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_text_view_get_type (), GtkTextView), gtk_widget_get_type (), GtkWidget), ev);
		return result;
	}
	_tmp1_ = gdk_keyval_name (ev->keyval);
	if (g_strcmp0 (_tmp1_, "KP_Enter") == 0) {
		_tmp0_ = TRUE;
	} else {
		const gchar* _tmp2_;
		_tmp2_ = gdk_keyval_name (ev->keyval);
		_tmp0_ = g_strcmp0 (_tmp2_, "Return") == 0;
	}
	if (_tmp0_) {
		g_signal_emit (self, dismissable_text_view_signals[DISMISSABLE_TEXT_VIEW_EDIT_DONE_SIGNAL], 0);
		result = TRUE;
		return result;
	}
	result = GTK_WIDGET_CLASS (dismissable_text_view_parent_class)->key_press_event (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_text_view_get_type (), GtkTextView), gtk_widget_get_type (), GtkWidget), ev);
	return result;
}

DismissableTextView*
dismissable_text_view_construct (GType object_type)
{
	DismissableTextView * self = NULL;
	self = (DismissableTextView*) g_object_new (object_type, NULL);
	return self;
}

DismissableTextView*
dismissable_text_view_new (void)
{
	return dismissable_text_view_construct (TYPE_DISMISSABLE_TEXT_VIEW);
}

static void
dismissable_text_view_class_init (DismissableTextViewClass * klass,
                                  gpointer klass_data)
{
	dismissable_text_view_parent_class = g_type_class_peek_parent (klass);
	((GtkWidgetClass *) klass)->key_press_event = (gboolean (*) (GtkWidget*, GdkEventKey*)) dismissable_text_view_real_key_press_event;
	dismissable_text_view_signals[DISMISSABLE_TEXT_VIEW_EDIT_DONE_SIGNAL] = g_signal_new ("edit-done", TYPE_DISMISSABLE_TEXT_VIEW, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
dismissable_text_view_instance_init (DismissableTextView * self,
                                     gpointer klass)
{
}

static GType
dismissable_text_view_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DismissableTextViewClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dismissable_text_view_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DismissableTextView), 0, (GInstanceInitFunc) dismissable_text_view_instance_init, NULL };
	GType dismissable_text_view_type_id;
	dismissable_text_view_type_id = g_type_register_static (gtk_text_view_get_type (), "DismissableTextView", &g_define_type_info, 0);
	return dismissable_text_view_type_id;
}

GType
dismissable_text_view_get_type (void)
{
	static volatile gsize dismissable_text_view_type_id__once = 0;
	if (g_once_init_enter (&dismissable_text_view_type_id__once)) {
		GType dismissable_text_view_type_id;
		dismissable_text_view_type_id = dismissable_text_view_get_type_once ();
		g_once_init_leave (&dismissable_text_view_type_id__once, dismissable_text_view_type_id);
	}
	return dismissable_text_view_type_id__once;
}

static inline gpointer
multi_text_entry_dialog_get_instance_private (MultiTextEntryDialog* self)
{
	return G_STRUCT_MEMBER_P (self, MultiTextEntryDialog_private_offset);
}

static void
__lambda21_ (MultiTextEntryDialog* self)
{
	gtk_dialog_response (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_dialog_get_type (), GtkDialog), (gint) GTK_RESPONSE_OK);
}

static void
___lambda21__dismissable_text_view_edit_done (DismissableTextView* _sender,
                                              gpointer self)
{
	__lambda21_ ((MultiTextEntryDialog*) self);
}

MultiTextEntryDialog*
multi_text_entry_dialog_construct (GType object_type)
{
	MultiTextEntryDialog * self = NULL;
	DismissableTextView* _tmp0_;
	self = (MultiTextEntryDialog*) g_object_new (object_type, "use-header-bar", resources_use_header_bar (), NULL);
	_tmp0_ = self->priv->entry;
	g_signal_connect_object (_tmp0_, "edit-done", (GCallback) ___lambda21__dismissable_text_view_edit_done, self, 0);
	return self;
}

MultiTextEntryDialog*
multi_text_entry_dialog_new (void)
{
	return multi_text_entry_dialog_construct (TYPE_MULTI_TEXT_ENTRY_DIALOG);
}

void
multi_text_entry_dialog_setup (MultiTextEntryDialog* self,
                               MultiTextEntryDialogOnModifyValidateType modify_validate,
                               gpointer modify_validate_target,
                               const gchar* title,
                               const gchar* label,
                               const gchar* initial_text)
{
	AppWindow* _tmp0_;
	AppWindow* _tmp1_;
	GdkWindow* _tmp2_;
	AppWindow* _tmp3_;
	AppWindow* _tmp4_;
	const gchar* _tmp5_ = NULL;
	DismissableTextView* _tmp6_;
	GtkTextBuffer* _tmp7_;
	GtkTextBuffer* _tmp8_;
	DismissableTextView* _tmp9_;
	g_return_if_fail (IS_MULTI_TEXT_ENTRY_DIALOG (self));
	g_return_if_fail (title != NULL);
	g_return_if_fail (label != NULL);
	gtk_window_set_title (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_window_get_type (), GtkWindow), title);
	_tmp0_ = app_window_get_instance ();
	_tmp1_ = _tmp0_;
	_tmp2_ = gtk_widget_get_parent_window (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, gtk_widget_get_type (), GtkWidget));
	gtk_widget_set_parent_window (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget), _tmp2_);
	_g_object_unref0 (_tmp1_);
	_tmp3_ = app_window_get_instance ();
	_tmp4_ = _tmp3_;
	gtk_window_set_transient_for (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_window_get_type (), GtkWindow), G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, gtk_window_get_type (), GtkWindow));
	_g_object_unref0 (_tmp4_);
	self->priv->on_modify_validate = modify_validate;
	self->priv->on_modify_validate_target = modify_validate_target;
	if (initial_text != NULL) {
		_tmp5_ = initial_text;
	} else {
		_tmp5_ = "";
	}
	_tmp6_ = self->priv->entry;
	_tmp7_ = gtk_text_view_get_buffer (G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, gtk_text_view_get_type (), GtkTextView));
	_tmp8_ = _tmp7_;
	g_object_set (_tmp8_, "text", _tmp5_, NULL);
	_tmp9_ = self->priv->entry;
	gtk_widget_grab_focus (G_TYPE_CHECK_INSTANCE_CAST (_tmp9_, gtk_widget_get_type (), GtkWidget));
}

gchar*
multi_text_entry_dialog_execute (MultiTextEntryDialog* self)
{
	gchar* text = NULL;
	gchar* result;
	g_return_val_if_fail (IS_MULTI_TEXT_ENTRY_DIALOG (self), NULL);
	text = NULL;
	gtk_widget_show_all (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
	if (gtk_dialog_run (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_dialog_get_type (), GtkDialog)) == ((gint) GTK_RESPONSE_OK)) {
		DismissableTextView* _tmp0_;
		GtkTextBuffer* _tmp1_;
		GtkTextBuffer* _tmp2_;
		gchar* _tmp3_;
		gchar* _tmp4_;
		_tmp0_ = self->priv->entry;
		_tmp1_ = gtk_text_view_get_buffer (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_text_view_get_type (), GtkTextView));
		_tmp2_ = _tmp1_;
		g_object_get (_tmp2_, "text", &_tmp3_, NULL);
		_tmp4_ = _tmp3_;
		_g_free0 (text);
		text = _tmp4_;
	}
	gtk_widget_destroy (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
	result = text;
	return result;
}

static void
multi_text_entry_dialog_class_init (MultiTextEntryDialogClass * klass,
                                    gpointer klass_data)
{
	multi_text_entry_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &MultiTextEntryDialog_private_offset);
	G_OBJECT_CLASS (klass)->finalize = multi_text_entry_dialog_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Shotwell/ui/multitextentrydialog.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "entry", FALSE, MultiTextEntryDialog_private_offset + G_STRUCT_OFFSET (MultiTextEntryDialogPrivate, entry));
}

static void
multi_text_entry_dialog_instance_init (MultiTextEntryDialog * self,
                                       gpointer klass)
{
	self->priv = multi_text_entry_dialog_get_instance_private (self);
	g_type_ensure (TYPE_DISMISSABLE_TEXT_VIEW);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
multi_text_entry_dialog_finalize (GObject * obj)
{
	MultiTextEntryDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_MULTI_TEXT_ENTRY_DIALOG, MultiTextEntryDialog);
	G_OBJECT_CLASS (multi_text_entry_dialog_parent_class)->finalize (obj);
}

static GType
multi_text_entry_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (MultiTextEntryDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) multi_text_entry_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MultiTextEntryDialog), 0, (GInstanceInitFunc) multi_text_entry_dialog_instance_init, NULL };
	GType multi_text_entry_dialog_type_id;
	multi_text_entry_dialog_type_id = g_type_register_static (gtk_dialog_get_type (), "MultiTextEntryDialog", &g_define_type_info, 0);
	MultiTextEntryDialog_private_offset = g_type_add_instance_private (multi_text_entry_dialog_type_id, sizeof (MultiTextEntryDialogPrivate));
	return multi_text_entry_dialog_type_id;
}

GType
multi_text_entry_dialog_get_type (void)
{
	static volatile gsize multi_text_entry_dialog_type_id__once = 0;
	if (g_once_init_enter (&multi_text_entry_dialog_type_id__once)) {
		GType multi_text_entry_dialog_type_id;
		multi_text_entry_dialog_type_id = multi_text_entry_dialog_get_type_once ();
		g_once_init_leave (&multi_text_entry_dialog_type_id__once, multi_text_entry_dialog_type_id);
	}
	return multi_text_entry_dialog_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;
}

