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

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

#define TOOTLE_WIDGETS_ATTACHMENT_TYPE_BOX (tootle_widgets_attachment_box_get_type ())
#define TOOTLE_WIDGETS_ATTACHMENT_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOOTLE_WIDGETS_ATTACHMENT_TYPE_BOX, TootleWidgetsAttachmentBox))
#define TOOTLE_WIDGETS_ATTACHMENT_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOOTLE_WIDGETS_ATTACHMENT_TYPE_BOX, TootleWidgetsAttachmentBoxClass))
#define TOOTLE_WIDGETS_ATTACHMENT_IS_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOOTLE_WIDGETS_ATTACHMENT_TYPE_BOX))
#define TOOTLE_WIDGETS_ATTACHMENT_IS_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOOTLE_WIDGETS_ATTACHMENT_TYPE_BOX))
#define TOOTLE_WIDGETS_ATTACHMENT_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TOOTLE_WIDGETS_ATTACHMENT_TYPE_BOX, TootleWidgetsAttachmentBoxClass))

typedef struct _TootleWidgetsAttachmentBox TootleWidgetsAttachmentBox;
typedef struct _TootleWidgetsAttachmentBoxClass TootleWidgetsAttachmentBoxClass;
typedef struct _TootleWidgetsAttachmentBoxPrivate TootleWidgetsAttachmentBoxPrivate;
enum  {
	TOOTLE_WIDGETS_ATTACHMENT_BOX_0_PROPERTY,
	TOOTLE_WIDGETS_ATTACHMENT_BOX_EDITING_PROPERTY,
	TOOTLE_WIDGETS_ATTACHMENT_BOX_NUM_PROPERTIES
};
static GParamSpec* tootle_widgets_attachment_box_properties[TOOTLE_WIDGETS_ATTACHMENT_BOX_NUM_PROPERTIES];

#define TOOTLE_TYPE_ENTITY (tootle_entity_get_type ())
#define TOOTLE_ENTITY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOOTLE_TYPE_ENTITY, TootleEntity))
#define TOOTLE_ENTITY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOOTLE_TYPE_ENTITY, TootleEntityClass))
#define TOOTLE_IS_ENTITY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOOTLE_TYPE_ENTITY))
#define TOOTLE_IS_ENTITY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOOTLE_TYPE_ENTITY))
#define TOOTLE_ENTITY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TOOTLE_TYPE_ENTITY, TootleEntityClass))

typedef struct _TootleEntity TootleEntity;
typedef struct _TootleEntityClass TootleEntityClass;

#define TOOTLE_API_TYPE_ATTACHMENT (tootle_api_attachment_get_type ())
#define TOOTLE_API_ATTACHMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOOTLE_API_TYPE_ATTACHMENT, TootleAPIAttachment))
#define TOOTLE_API_ATTACHMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOOTLE_API_TYPE_ATTACHMENT, TootleAPIAttachmentClass))
#define TOOTLE_API_IS_ATTACHMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOOTLE_API_TYPE_ATTACHMENT))
#define TOOTLE_API_IS_ATTACHMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOOTLE_API_TYPE_ATTACHMENT))
#define TOOTLE_API_ATTACHMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TOOTLE_API_TYPE_ATTACHMENT, TootleAPIAttachmentClass))

typedef struct _TootleAPIAttachment TootleAPIAttachment;
typedef struct _TootleAPIAttachmentClass TootleAPIAttachmentClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define TOOTLE_WIDGETS_ATTACHMENT_TYPE_SLOT (tootle_widgets_attachment_slot_get_type ())
#define TOOTLE_WIDGETS_ATTACHMENT_SLOT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOOTLE_WIDGETS_ATTACHMENT_TYPE_SLOT, TootleWidgetsAttachmentSlot))
#define TOOTLE_WIDGETS_ATTACHMENT_SLOT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOOTLE_WIDGETS_ATTACHMENT_TYPE_SLOT, TootleWidgetsAttachmentSlotClass))
#define TOOTLE_WIDGETS_ATTACHMENT_IS_SLOT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOOTLE_WIDGETS_ATTACHMENT_TYPE_SLOT))
#define TOOTLE_WIDGETS_ATTACHMENT_IS_SLOT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOOTLE_WIDGETS_ATTACHMENT_TYPE_SLOT))
#define TOOTLE_WIDGETS_ATTACHMENT_SLOT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TOOTLE_WIDGETS_ATTACHMENT_TYPE_SLOT, TootleWidgetsAttachmentSlotClass))

typedef struct _TootleWidgetsAttachmentSlot TootleWidgetsAttachmentSlot;
typedef struct _TootleWidgetsAttachmentSlotClass TootleWidgetsAttachmentSlotClass;

struct _TootleWidgetsAttachmentBox {
	GtkFlowBox parent_instance;
	TootleWidgetsAttachmentBoxPrivate * priv;
};

struct _TootleWidgetsAttachmentBoxClass {
	GtkFlowBoxClass parent_class;
};

struct _TootleWidgetsAttachmentBoxPrivate {
	gboolean _editing;
};

static gint TootleWidgetsAttachmentBox_private_offset;
static gpointer tootle_widgets_attachment_box_parent_class = NULL;

GType tootle_widgets_attachment_box_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TootleWidgetsAttachmentBox, g_object_unref)
TootleWidgetsAttachmentBox* tootle_widgets_attachment_box_new (gboolean editing);
TootleWidgetsAttachmentBox* tootle_widgets_attachment_box_construct (GType object_type,
                                                                     gboolean editing);
GType tootle_entity_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TootleEntity, g_object_unref)
GType tootle_api_attachment_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TootleAPIAttachment, g_object_unref)
gboolean tootle_widgets_attachment_box_populate (TootleWidgetsAttachmentBox* self,
                                                 GeeArrayList* list);
static gboolean __lambda33_ (TootleWidgetsAttachmentBox* self,
                      TootleAPIAttachment* obj);
gboolean tootle_widgets_attachment_box_pack (TootleWidgetsAttachmentBox* self,
                                             TootleAPIAttachment* obj);
static gboolean ___lambda33__gee_forall_func (gpointer g,
                                       gpointer self);
GType tootle_widgets_attachment_slot_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TootleWidgetsAttachmentSlot, g_object_unref)
TootleWidgetsAttachmentSlot* tootle_widgets_attachment_slot_new (TootleAPIAttachment* obj);
TootleWidgetsAttachmentSlot* tootle_widgets_attachment_slot_construct (GType object_type,
                                                                       TootleAPIAttachment* obj);
gboolean tootle_widgets_attachment_box_get_editing (TootleWidgetsAttachmentBox* self);
void tootle_widgets_attachment_box_set_editing (TootleWidgetsAttachmentBox* self,
                                                gboolean value);
static GObject * tootle_widgets_attachment_box_constructor (GType type,
                                                     guint n_construct_properties,
                                                     GObjectConstructParam * construct_properties);
static void tootle_widgets_attachment_box_finalize (GObject * obj);
static GType tootle_widgets_attachment_box_get_type_once (void);
static void _vala_tootle_widgets_attachment_box_get_property (GObject * object,
                                                       guint property_id,
                                                       GValue * value,
                                                       GParamSpec * pspec);
static void _vala_tootle_widgets_attachment_box_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
tootle_widgets_attachment_box_get_instance_private (TootleWidgetsAttachmentBox* self)
{
	return G_STRUCT_MEMBER_P (self, TootleWidgetsAttachmentBox_private_offset);
}

TootleWidgetsAttachmentBox*
tootle_widgets_attachment_box_construct (GType object_type,
                                         gboolean editing)
{
	TootleWidgetsAttachmentBox * self = NULL;
	self = (TootleWidgetsAttachmentBox*) g_object_new (object_type, "editing", editing, NULL);
	return self;
}

TootleWidgetsAttachmentBox*
tootle_widgets_attachment_box_new (gboolean editing)
{
	return tootle_widgets_attachment_box_construct (TOOTLE_WIDGETS_ATTACHMENT_TYPE_BOX, editing);
}

static gboolean
__lambda33_ (TootleWidgetsAttachmentBox* self,
             TootleAPIAttachment* obj)
{
	gboolean result = FALSE;
	g_return_val_if_fail (obj != NULL, FALSE);
	result = tootle_widgets_attachment_box_pack (self, obj);
	_g_object_unref0 (obj);
	return result;
}

static gboolean
___lambda33__gee_forall_func (gpointer g,
                              gpointer self)
{
	gboolean result;
	result = __lambda33_ ((TootleWidgetsAttachmentBox*) self, (TootleAPIAttachment*) g);
	return result;
}

gboolean
tootle_widgets_attachment_box_populate (TootleWidgetsAttachmentBox* self,
                                        GeeArrayList* list)
{
	gint max = 0;
	gint min = 0;
	gint _tmp0_;
	gint _tmp1_;
	gboolean result = FALSE;
	g_return_val_if_fail (self != NULL, FALSE);
	if (list == NULL) {
		result = FALSE;
		return result;
	}
	max = 2;
	min = 1;
	_tmp0_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) list);
	_tmp1_ = _tmp0_;
	if (_tmp1_ == 1) {
		max = 1;
	} else {
		gint _tmp2_;
		gint _tmp3_;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) list);
		_tmp3_ = _tmp2_;
		if ((_tmp3_ % 2) == 0) {
			min = 2;
			max = min;
		} else {
			gint _tmp4_;
			gint _tmp5_;
			_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) list);
			_tmp5_ = _tmp4_;
			if ((_tmp5_ % 3) == 0) {
				min = 3;
				max = min;
			}
		}
	}
	gtk_flow_box_set_max_children_per_line ((GtkFlowBox*) self, (guint) max);
	gtk_flow_box_set_min_children_per_line ((GtkFlowBox*) self, (guint) min);
	gee_abstract_collection_foreach ((GeeAbstractCollection*) list, ___lambda33__gee_forall_func, self);
	result = TRUE;
	return result;
}

gboolean
tootle_widgets_attachment_box_pack (TootleWidgetsAttachmentBox* self,
                                    TootleAPIAttachment* obj)
{
	TootleWidgetsAttachmentSlot* w = NULL;
	TootleWidgetsAttachmentSlot* _tmp0_;
	gboolean result = FALSE;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (obj != NULL, FALSE);
	_tmp0_ = tootle_widgets_attachment_slot_new (obj);
	g_object_ref_sink (_tmp0_);
	w = _tmp0_;
	gtk_flow_box_insert ((GtkFlowBox*) self, (GtkWidget*) w, -1);
	gtk_widget_show ((GtkWidget*) self);
	result = TRUE;
	_g_object_unref0 (w);
	return result;
}

gboolean
tootle_widgets_attachment_box_get_editing (TootleWidgetsAttachmentBox* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_editing;
	return result;
}

void
tootle_widgets_attachment_box_set_editing (TootleWidgetsAttachmentBox* self,
                                           gboolean value)
{
	gboolean old_value;
	g_return_if_fail (self != NULL);
	old_value = tootle_widgets_attachment_box_get_editing (self);
	if (old_value != value) {
		self->priv->_editing = value;
		g_object_notify_by_pspec ((GObject *) self, tootle_widgets_attachment_box_properties[TOOTLE_WIDGETS_ATTACHMENT_BOX_EDITING_PROPERTY]);
	}
}

static GObject *
tootle_widgets_attachment_box_constructor (GType type,
                                           guint n_construct_properties,
                                           GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	TootleWidgetsAttachmentBox * self;
	parent_class = G_OBJECT_CLASS (tootle_widgets_attachment_box_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TOOTLE_WIDGETS_ATTACHMENT_TYPE_BOX, TootleWidgetsAttachmentBox);
	gtk_widget_set_hexpand ((GtkWidget*) self, TRUE);
	gtk_widget_set_can_focus ((GtkWidget*) self, FALSE);
	gtk_flow_box_set_row_spacing ((GtkFlowBox*) self, (guint) 8);
	gtk_flow_box_set_column_spacing ((GtkFlowBox*) self, (guint) 8);
	gtk_flow_box_set_selection_mode ((GtkFlowBox*) self, GTK_SELECTION_NONE);
	return obj;
}

static void
tootle_widgets_attachment_box_class_init (TootleWidgetsAttachmentBoxClass * klass,
                                          gpointer klass_data)
{
	tootle_widgets_attachment_box_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &TootleWidgetsAttachmentBox_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_tootle_widgets_attachment_box_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_tootle_widgets_attachment_box_set_property;
	G_OBJECT_CLASS (klass)->constructor = tootle_widgets_attachment_box_constructor;
	G_OBJECT_CLASS (klass)->finalize = tootle_widgets_attachment_box_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), TOOTLE_WIDGETS_ATTACHMENT_BOX_EDITING_PROPERTY, tootle_widgets_attachment_box_properties[TOOTLE_WIDGETS_ATTACHMENT_BOX_EDITING_PROPERTY] = g_param_spec_boolean ("editing", "editing", "editing", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
}

static void
tootle_widgets_attachment_box_instance_init (TootleWidgetsAttachmentBox * self,
                                             gpointer klass)
{
	self->priv = tootle_widgets_attachment_box_get_instance_private (self);
}

static void
tootle_widgets_attachment_box_finalize (GObject * obj)
{
	TootleWidgetsAttachmentBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TOOTLE_WIDGETS_ATTACHMENT_TYPE_BOX, TootleWidgetsAttachmentBox);
	G_OBJECT_CLASS (tootle_widgets_attachment_box_parent_class)->finalize (obj);
}

static GType
tootle_widgets_attachment_box_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (TootleWidgetsAttachmentBoxClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) tootle_widgets_attachment_box_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TootleWidgetsAttachmentBox), 0, (GInstanceInitFunc) tootle_widgets_attachment_box_instance_init, NULL };
	GType tootle_widgets_attachment_box_type_id;
	tootle_widgets_attachment_box_type_id = g_type_register_static (gtk_flow_box_get_type (), "TootleWidgetsAttachmentBox", &g_define_type_info, 0);
	TootleWidgetsAttachmentBox_private_offset = g_type_add_instance_private (tootle_widgets_attachment_box_type_id, sizeof (TootleWidgetsAttachmentBoxPrivate));
	return tootle_widgets_attachment_box_type_id;
}

GType
tootle_widgets_attachment_box_get_type (void)
{
	static volatile gsize tootle_widgets_attachment_box_type_id__volatile = 0;
	if (g_once_init_enter (&tootle_widgets_attachment_box_type_id__volatile)) {
		GType tootle_widgets_attachment_box_type_id;
		tootle_widgets_attachment_box_type_id = tootle_widgets_attachment_box_get_type_once ();
		g_once_init_leave (&tootle_widgets_attachment_box_type_id__volatile, tootle_widgets_attachment_box_type_id);
	}
	return tootle_widgets_attachment_box_type_id__volatile;
}

static void
_vala_tootle_widgets_attachment_box_get_property (GObject * object,
                                                  guint property_id,
                                                  GValue * value,
                                                  GParamSpec * pspec)
{
	TootleWidgetsAttachmentBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TOOTLE_WIDGETS_ATTACHMENT_TYPE_BOX, TootleWidgetsAttachmentBox);
	switch (property_id) {
		case TOOTLE_WIDGETS_ATTACHMENT_BOX_EDITING_PROPERTY:
		g_value_set_boolean (value, tootle_widgets_attachment_box_get_editing (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_tootle_widgets_attachment_box_set_property (GObject * object,
                                                  guint property_id,
                                                  const GValue * value,
                                                  GParamSpec * pspec)
{
	TootleWidgetsAttachmentBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TOOTLE_WIDGETS_ATTACHMENT_TYPE_BOX, TootleWidgetsAttachmentBox);
	switch (property_id) {
		case TOOTLE_WIDGETS_ATTACHMENT_BOX_EDITING_PROPERTY:
		tootle_widgets_attachment_box_set_editing (self, g_value_get_boolean (value));
		break;
		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;
}

