/* set-window-size-dialog.c generated by valac 0.56.17, the Vala compiler
 * generated from set-window-size-dialog.vala, do not modify */

/*
Peek Copyright (c) 2017 by Philipp Wolfer <ph.wolfer@gmail.com>

This file is part of Peek.

This software is licensed under the GNU General Public License
(version 3 or later). See the LICENSE file in this distribution.
*/

#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <gdk/gdk.h>
#include "../../application.h"
#include <float.h>
#include <math.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

#define PEEK_UI_TYPE_SET_WINDOW_SIZE_DIALOG (peek_ui_set_window_size_dialog_get_type ())
#define PEEK_UI_SET_WINDOW_SIZE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PEEK_UI_TYPE_SET_WINDOW_SIZE_DIALOG, PeekUiSetWindowSizeDialog))
#define PEEK_UI_SET_WINDOW_SIZE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PEEK_UI_TYPE_SET_WINDOW_SIZE_DIALOG, PeekUiSetWindowSizeDialogClass))
#define PEEK_UI_IS_SET_WINDOW_SIZE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PEEK_UI_TYPE_SET_WINDOW_SIZE_DIALOG))
#define PEEK_UI_IS_SET_WINDOW_SIZE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PEEK_UI_TYPE_SET_WINDOW_SIZE_DIALOG))
#define PEEK_UI_SET_WINDOW_SIZE_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PEEK_UI_TYPE_SET_WINDOW_SIZE_DIALOG, PeekUiSetWindowSizeDialogClass))

typedef struct _PeekUiSetWindowSizeDialog PeekUiSetWindowSizeDialog;
typedef struct _PeekUiSetWindowSizeDialogClass PeekUiSetWindowSizeDialogClass;
typedef struct _PeekUiSetWindowSizeDialogPrivate PeekUiSetWindowSizeDialogPrivate;

#define PEEK_UI_TYPE_APPLICATION_WINDOW (peek_ui_application_window_get_type ())
#define PEEK_UI_APPLICATION_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PEEK_UI_TYPE_APPLICATION_WINDOW, PeekUiApplicationWindow))
#define PEEK_UI_APPLICATION_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PEEK_UI_TYPE_APPLICATION_WINDOW, PeekUiApplicationWindowClass))
#define PEEK_UI_IS_APPLICATION_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PEEK_UI_TYPE_APPLICATION_WINDOW))
#define PEEK_UI_IS_APPLICATION_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PEEK_UI_TYPE_APPLICATION_WINDOW))
#define PEEK_UI_APPLICATION_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PEEK_UI_TYPE_APPLICATION_WINDOW, PeekUiApplicationWindowClass))

typedef struct _PeekUiApplicationWindow PeekUiApplicationWindow;
typedef struct _PeekUiApplicationWindowClass PeekUiApplicationWindowClass;
enum  {
	PEEK_UI_SET_WINDOW_SIZE_DIALOG_0_PROPERTY,
	PEEK_UI_SET_WINDOW_SIZE_DIALOG_NUM_PROPERTIES
};
static GParamSpec* peek_ui_set_window_size_dialog_properties[PEEK_UI_SET_WINDOW_SIZE_DIALOG_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _PeekUiSetWindowSizeDialog {
	GtkDialog parent_instance;
	PeekUiSetWindowSizeDialogPrivate * priv;
};

struct _PeekUiSetWindowSizeDialogClass {
	GtkDialogClass parent_class;
};

struct _PeekUiSetWindowSizeDialogPrivate {
	GtkAdjustment* width_adjustment;
	GtkAdjustment* height_adjustment;
	PeekUiApplicationWindow* window;
};

static gint PeekUiSetWindowSizeDialog_private_offset;
static gpointer peek_ui_set_window_size_dialog_parent_class = NULL;
static PeekUiSetWindowSizeDialog* peek_ui_set_window_size_dialog_instance;
static PeekUiSetWindowSizeDialog* peek_ui_set_window_size_dialog_instance = NULL;

VALA_EXTERN GType peek_ui_set_window_size_dialog_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType peek_ui_application_window_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GtkDialog* peek_ui_set_window_size_dialog_present_single_instance (PeekUiApplicationWindow* main_window);
static PeekUiSetWindowSizeDialog* peek_ui_set_window_size_dialog_new (PeekUiApplicationWindow* window);
static PeekUiSetWindowSizeDialog* peek_ui_set_window_size_dialog_construct (GType object_type,
                                                                     PeekUiApplicationWindow* window);
static gboolean ___lambda5_ (GdkEventAny* event);
static gboolean ____lambda5__gtk_widget_delete_event (GtkWidget* _sender,
                                               GdkEventAny* event,
                                               gpointer self);
VALA_EXTERN void peek_ui_application_window_get_recording_area (PeekUiApplicationWindow* self,
                                                    PeekRecordingRecordingArea* result);
static void peek_ui_set_window_size_dialog_set_height (PeekUiSetWindowSizeDialog* self,
                                                gint value);
static void peek_ui_set_window_size_dialog_set_width (PeekUiSetWindowSizeDialog* self,
                                               gint value);
VALA_EXTERN void peek_ui_set_window_size_dialog_close_instance (void);
static void peek_ui_set_window_size_dialog_on_set_size_button_clicked (PeekUiSetWindowSizeDialog* self,
                                                                GtkButton* source);
VALA_EXTERN void peek_ui_application_window_resize_recording_area (PeekUiApplicationWindow* self,
                                                       gint width,
                                                       gint height);
static gint peek_ui_set_window_size_dialog_get_width (PeekUiSetWindowSizeDialog* self);
static gint peek_ui_set_window_size_dialog_get_height (PeekUiSetWindowSizeDialog* self);
static void _peek_ui_set_window_size_dialog_on_set_size_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                                    gpointer self);
static void peek_ui_set_window_size_dialog_on_cancel_button_clicked (PeekUiSetWindowSizeDialog* self,
                                                              GtkButton* source);
static void _peek_ui_set_window_size_dialog_on_cancel_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                                  gpointer self);
static void peek_ui_set_window_size_dialog_finalize (GObject * obj);
static GType peek_ui_set_window_size_dialog_get_type_once (void);
static void _vala_peek_ui_set_window_size_dialog_get_property (GObject * object,
                                                        guint property_id,
                                                        GValue * value,
                                                        GParamSpec * pspec);
static void _vala_peek_ui_set_window_size_dialog_set_property (GObject * object,
                                                        guint property_id,
                                                        const GValue * value,
                                                        GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
peek_ui_set_window_size_dialog_get_instance_private (PeekUiSetWindowSizeDialog* self)
{
	return G_STRUCT_MEMBER_P (self, PeekUiSetWindowSizeDialog_private_offset);
}

static gboolean
___lambda5_ (GdkEventAny* event)
{
	gboolean result;
	g_return_val_if_fail (event != NULL, FALSE);
	_g_object_unref0 (peek_ui_set_window_size_dialog_instance);
	peek_ui_set_window_size_dialog_instance = NULL;
	result = FALSE;
	return result;
}

static gboolean
____lambda5__gtk_widget_delete_event (GtkWidget* _sender,
                                      GdkEventAny* event,
                                      gpointer self)
{
	gboolean result;
	result = ___lambda5_ (event);
	return result;
}

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

GtkDialog*
peek_ui_set_window_size_dialog_present_single_instance (PeekUiApplicationWindow* main_window)
{
	PeekUiSetWindowSizeDialog* _tmp0_;
	PeekRecordingRecordingArea area = {0};
	PeekRecordingRecordingArea _tmp3_ = {0};
	PeekUiSetWindowSizeDialog* _tmp4_;
	PeekRecordingRecordingArea _tmp5_;
	PeekUiSetWindowSizeDialog* _tmp6_;
	PeekRecordingRecordingArea _tmp7_;
	PeekUiSetWindowSizeDialog* _tmp8_;
	PeekUiSetWindowSizeDialog* _tmp9_;
	PeekUiSetWindowSizeDialog* _tmp10_;
	GtkDialog* _tmp11_;
	GtkDialog* result;
	g_return_val_if_fail (main_window != NULL, NULL);
	_tmp0_ = peek_ui_set_window_size_dialog_instance;
	if (_tmp0_ == NULL) {
		PeekUiSetWindowSizeDialog* _tmp1_;
		PeekUiSetWindowSizeDialog* _tmp2_;
		_tmp1_ = peek_ui_set_window_size_dialog_new (main_window);
		g_object_ref_sink (_tmp1_);
		_g_object_unref0 (peek_ui_set_window_size_dialog_instance);
		peek_ui_set_window_size_dialog_instance = _tmp1_;
		_tmp2_ = peek_ui_set_window_size_dialog_instance;
		g_signal_connect ((GtkWidget*) _tmp2_, "delete-event", (GCallback) ____lambda5__gtk_widget_delete_event, NULL);
	}
	peek_ui_application_window_get_recording_area (main_window, &_tmp3_);
	area = _tmp3_;
	_tmp4_ = peek_ui_set_window_size_dialog_instance;
	_tmp5_ = area;
	peek_ui_set_window_size_dialog_set_height (_tmp4_, _tmp5_.height);
	_tmp6_ = peek_ui_set_window_size_dialog_instance;
	_tmp7_ = area;
	peek_ui_set_window_size_dialog_set_width (_tmp6_, _tmp7_.width);
	_tmp8_ = peek_ui_set_window_size_dialog_instance;
	gtk_window_set_transient_for ((GtkWindow*) _tmp8_, (GtkWindow*) main_window);
	_tmp9_ = peek_ui_set_window_size_dialog_instance;
	gtk_window_present ((GtkWindow*) _tmp9_);
	_tmp10_ = peek_ui_set_window_size_dialog_instance;
	_tmp11_ = _g_object_ref0 ((GtkDialog*) _tmp10_);
	result = _tmp11_;
	peek_recording_recording_area_destroy (&area);
	return result;
}

void
peek_ui_set_window_size_dialog_close_instance (void)
{
	PeekUiSetWindowSizeDialog* _tmp0_;
	_tmp0_ = peek_ui_set_window_size_dialog_instance;
	if (_tmp0_ != NULL) {
		PeekUiSetWindowSizeDialog* _tmp1_;
		_tmp1_ = peek_ui_set_window_size_dialog_instance;
		g_signal_emit_by_name ((GtkDialog*) _tmp1_, "close");
	}
}

static PeekUiSetWindowSizeDialog*
peek_ui_set_window_size_dialog_construct (GType object_type,
                                          PeekUiApplicationWindow* window)
{
	PeekUiSetWindowSizeDialog * self = NULL;
	PeekUiApplicationWindow* _tmp0_;
	g_return_val_if_fail (window != NULL, NULL);
	self = (PeekUiSetWindowSizeDialog*) g_object_new (object_type, "use-header-bar", 1, NULL);
	_tmp0_ = _g_object_ref0 (window);
	_g_object_unref0 (self->priv->window);
	self->priv->window = _tmp0_;
	return self;
}

static PeekUiSetWindowSizeDialog*
peek_ui_set_window_size_dialog_new (PeekUiApplicationWindow* window)
{
	return peek_ui_set_window_size_dialog_construct (PEEK_UI_TYPE_SET_WINDOW_SIZE_DIALOG, window);
}

static void
peek_ui_set_window_size_dialog_on_set_size_button_clicked (PeekUiSetWindowSizeDialog* self,
                                                           GtkButton* source)
{
	PeekUiApplicationWindow* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (source != NULL);
	_tmp0_ = self->priv->window;
	_tmp1_ = peek_ui_set_window_size_dialog_get_width (self);
	_tmp2_ = _tmp1_;
	_tmp3_ = peek_ui_set_window_size_dialog_get_height (self);
	_tmp4_ = _tmp3_;
	peek_ui_application_window_resize_recording_area (_tmp0_, _tmp2_, _tmp4_);
	g_signal_emit_by_name ((GtkDialog*) self, "close");
}

static void
_peek_ui_set_window_size_dialog_on_set_size_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                               gpointer self)
{
	peek_ui_set_window_size_dialog_on_set_size_button_clicked ((PeekUiSetWindowSizeDialog*) self, _sender);
}

static void
peek_ui_set_window_size_dialog_on_cancel_button_clicked (PeekUiSetWindowSizeDialog* self,
                                                         GtkButton* source)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (source != NULL);
	g_signal_emit_by_name ((GtkDialog*) self, "close");
}

static void
_peek_ui_set_window_size_dialog_on_cancel_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                             gpointer self)
{
	peek_ui_set_window_size_dialog_on_cancel_button_clicked ((PeekUiSetWindowSizeDialog*) self, _sender);
}

static gint
peek_ui_set_window_size_dialog_get_width (PeekUiSetWindowSizeDialog* self)
{
	gint result;
	GtkAdjustment* _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->width_adjustment;
	_tmp1_ = gtk_adjustment_get_value (_tmp0_);
	_tmp2_ = _tmp1_;
	result = (gint) _tmp2_;
	return result;
}

static void
peek_ui_set_window_size_dialog_set_width (PeekUiSetWindowSizeDialog* self,
                                          gint value)
{
	GtkAdjustment* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->width_adjustment;
	gtk_adjustment_set_value (_tmp0_, (gdouble) value);
}

static gint
peek_ui_set_window_size_dialog_get_height (PeekUiSetWindowSizeDialog* self)
{
	gint result;
	GtkAdjustment* _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->height_adjustment;
	_tmp1_ = gtk_adjustment_get_value (_tmp0_);
	_tmp2_ = _tmp1_;
	result = (gint) _tmp2_;
	return result;
}

static void
peek_ui_set_window_size_dialog_set_height (PeekUiSetWindowSizeDialog* self,
                                           gint value)
{
	GtkAdjustment* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->height_adjustment;
	gtk_adjustment_set_value (_tmp0_, (gdouble) value);
}

static void
peek_ui_set_window_size_dialog_class_init (PeekUiSetWindowSizeDialogClass * klass,
                                           gpointer klass_data)
{
	peek_ui_set_window_size_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &PeekUiSetWindowSizeDialog_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_peek_ui_set_window_size_dialog_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_peek_ui_set_window_size_dialog_set_property;
	G_OBJECT_CLASS (klass)->finalize = peek_ui_set_window_size_dialog_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/com/uploadedlobster/peek/set-window-size-dialog.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "width_adjustment", FALSE, PeekUiSetWindowSizeDialog_private_offset + G_STRUCT_OFFSET (PeekUiSetWindowSizeDialogPrivate, width_adjustment));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "height_adjustment", FALSE, PeekUiSetWindowSizeDialog_private_offset + G_STRUCT_OFFSET (PeekUiSetWindowSizeDialogPrivate, height_adjustment));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_set_size_button_clicked", G_CALLBACK(_peek_ui_set_window_size_dialog_on_set_size_button_clicked_gtk_button_clicked));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_cancel_button_clicked", G_CALLBACK(_peek_ui_set_window_size_dialog_on_cancel_button_clicked_gtk_button_clicked));
}

static void
peek_ui_set_window_size_dialog_instance_init (PeekUiSetWindowSizeDialog * self,
                                              gpointer klass)
{
	self->priv = peek_ui_set_window_size_dialog_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
peek_ui_set_window_size_dialog_finalize (GObject * obj)
{
	PeekUiSetWindowSizeDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PEEK_UI_TYPE_SET_WINDOW_SIZE_DIALOG, PeekUiSetWindowSizeDialog);
	_g_object_unref0 (self->priv->window);
	G_OBJECT_CLASS (peek_ui_set_window_size_dialog_parent_class)->finalize (obj);
}

static GType
peek_ui_set_window_size_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (PeekUiSetWindowSizeDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) peek_ui_set_window_size_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PeekUiSetWindowSizeDialog), 0, (GInstanceInitFunc) peek_ui_set_window_size_dialog_instance_init, NULL };
	GType peek_ui_set_window_size_dialog_type_id;
	peek_ui_set_window_size_dialog_type_id = g_type_register_static (gtk_dialog_get_type (), "PeekUiSetWindowSizeDialog", &g_define_type_info, 0);
	PeekUiSetWindowSizeDialog_private_offset = g_type_add_instance_private (peek_ui_set_window_size_dialog_type_id, sizeof (PeekUiSetWindowSizeDialogPrivate));
	return peek_ui_set_window_size_dialog_type_id;
}

GType
peek_ui_set_window_size_dialog_get_type (void)
{
	static volatile gsize peek_ui_set_window_size_dialog_type_id__once = 0;
	if (g_once_init_enter (&peek_ui_set_window_size_dialog_type_id__once)) {
		GType peek_ui_set_window_size_dialog_type_id;
		peek_ui_set_window_size_dialog_type_id = peek_ui_set_window_size_dialog_get_type_once ();
		g_once_init_leave (&peek_ui_set_window_size_dialog_type_id__once, peek_ui_set_window_size_dialog_type_id);
	}
	return peek_ui_set_window_size_dialog_type_id__once;
}

static void
_vala_peek_ui_set_window_size_dialog_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec)
{
	PeekUiSetWindowSizeDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PEEK_UI_TYPE_SET_WINDOW_SIZE_DIALOG, PeekUiSetWindowSizeDialog);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_peek_ui_set_window_size_dialog_set_property (GObject * object,
                                                   guint property_id,
                                                   const GValue * value,
                                                   GParamSpec * pspec)
{
	PeekUiSetWindowSizeDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PEEK_UI_TYPE_SET_WINDOW_SIZE_DIALOG, PeekUiSetWindowSizeDialog);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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;
}

