#include "types.h"
#include "common.h"

// FontHandle xlFormatFont(FormatHandle handle);
ERL_NIF_TERM c_xlFormatFont(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	FontHandle font_handle = xlFormatFont(format_resource->handle);

	if(!font_handle) {
		return enif_make_atom(env, "nil");
	} else {
		FontType *ret = enif_alloc_resource(TypeOfFont, sizeof(FontType));

		ret->handle = font_handle;

		ERL_NIF_TERM handle = enif_make_resource(env, ret);

		enif_release_resource(ret);

		return handle;
	}
}

// int xlFormatSetFont(FormatHandle handle, FontHandle fontHandle);
ERL_NIF_TERM c_xlFormatSetFont(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	FontType *font_resource = NULL;

	if (0 == enif_get_resource(env, argv[1], TypeOfFont, (void**)&font_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatSetFont(format_resource->handle, font_resource->handle);

	return enif_make_int(env, ret);
}

// int xlFormatNumFormat(FormatHandle handle);
ERL_NIF_TERM c_xlFormatNumFormat(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatNumFormat(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetNumFormat(FormatHandle handle, int numFormat);
ERL_NIF_TERM c_xlFormatSetNumFormat(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int num_format;

	if (0 == enif_get_int(env, argv[1], &num_format)) {
		return enif_make_badarg(env);
	}

	xlFormatSetNumFormat(format_resource->handle, num_format);

	return enif_make_atom(env, "nil");
}

// int xlFormatAlignH(FormatHandle handle);
ERL_NIF_TERM c_xlFormatAlignH(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatAlignH(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetAlignH(FormatHandle handle, int align);
ERL_NIF_TERM c_xlFormatSetAlignH(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int align;

	if (0 == enif_get_int(env, argv[1], &align)) {
		return enif_make_badarg(env);
	}

	xlFormatSetAlignH(format_resource->handle, align);

	return enif_make_atom(env, "nil");
}

// int xlFormatAlignV(FormatHandle handle);
ERL_NIF_TERM c_xlFormatAlignV(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatAlignV(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetAlignV(FormatHandle handle, int align);
ERL_NIF_TERM c_xlFormatSetAlignV(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int align;

	if (0 == enif_get_int(env, argv[1], &align)) {
		return enif_make_badarg(env);
	}

	xlFormatSetAlignV(format_resource->handle, align);

	return enif_make_atom(env, "nil");
}

// int xlFormatWrap(FormatHandle handle);
ERL_NIF_TERM c_xlFormatWrap(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatWrap(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetWrap(FormatHandle handle, int wrap);
ERL_NIF_TERM c_xlFormatSetWrap(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int wrap;

	if (0 == enif_get_int(env, argv[1], &wrap)) {
		return enif_make_badarg(env);
	}

	xlFormatSetWrap(format_resource->handle, wrap);

	return enif_make_atom(env, "nil");
}

// int xlFormatRotation(FormatHandle handle);
ERL_NIF_TERM c_xlFormatRotation(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatRotation(format_resource->handle);

	return enif_make_int(env, ret);
}

// int xlFormatSetRotation(FormatHandle handle, int rotation);
ERL_NIF_TERM c_xlFormatSetRotation(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int rotation;

	if (0 == enif_get_int(env, argv[1], &rotation)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatSetRotation(format_resource->handle, rotation);

	return enif_make_int(env, ret);
}

// int xlFormatIndent(FormatHandle handle);
ERL_NIF_TERM c_xlFormatIndent(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatIndent(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetIndent(FormatHandle handle, int indent);
ERL_NIF_TERM c_xlFormatSetIndent(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int indent;

	if (0 == enif_get_int(env, argv[1], &indent)) {
		return enif_make_badarg(env);
	}

	xlFormatSetIndent(format_resource->handle, indent);

	return enif_make_atom(env, "nil");
}

// int xlFormatShrinkToFit(FormatHandle handle);
ERL_NIF_TERM c_xlFormatShrinkToFit(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatShrinkToFit(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetShrinkToFit(FormatHandle handle, int shrinkToFit);
ERL_NIF_TERM c_xlFormatSetShrinkToFit(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int shrink_to_fit;

	if (0 == enif_get_int(env, argv[1], &shrink_to_fit)) {
		return enif_make_badarg(env);
	}

	xlFormatSetShrinkToFit(format_resource->handle, shrink_to_fit);

	return enif_make_atom(env, "nil");
}

// void xlFormatSetBorder(FormatHandle handle, int style);
ERL_NIF_TERM c_xlFormatSetBorder(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int style;

	if (0 == enif_get_int(env, argv[1], &style)) {
		return enif_make_badarg(env);
	}

	xlFormatSetBorder(format_resource->handle, style);

	return enif_make_atom(env, "nil");
}

// void xlFormatSetBorderColor(FormatHandle handle, int color);
ERL_NIF_TERM c_xlFormatSetBorderColor(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int color;

	if (0 == enif_get_int(env, argv[1], &color)) {
		return enif_make_badarg(env);
	}

	xlFormatSetBorderColor(format_resource->handle, color);

	return enif_make_atom(env, "nil");
}

// int xlFormatBorderLeft(FormatHandle handle);
ERL_NIF_TERM c_xlFormatBorderLeft(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatBorderLeft(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetBorderLeft(FormatHandle handle, int style);
ERL_NIF_TERM c_xlFormatSetBorderLeft(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int style;

	if (0 == enif_get_int(env, argv[1], &style)) {
		return enif_make_badarg(env);
	}

	xlFormatSetBorderLeft(format_resource->handle, style);

	return enif_make_atom(env, "nil");
}

// int xlFormatBorderRight(FormatHandle handle);
ERL_NIF_TERM c_xlFormatBorderRight(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatBorderRight(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetBorderRight(FormatHandle handle, int style);
ERL_NIF_TERM c_xlFormatSetBorderRight(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int style;

	if (0 == enif_get_int(env, argv[1], &style)) {
		return enif_make_badarg(env);
	}

	xlFormatSetBorderRight(format_resource->handle, style);

	return enif_make_atom(env, "nil");
}

// int xlFormatBorderTop(FormatHandle handle);
ERL_NIF_TERM c_xlFormatBorderTop(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatBorderTop(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetBorderTop(FormatHandle handle, int style);
ERL_NIF_TERM c_xlFormatSetBorderTop(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int style;

	if (0 == enif_get_int(env, argv[1], &style)) {
		return enif_make_badarg(env);
	}

	xlFormatSetBorderTop(format_resource->handle, style);

	return enif_make_atom(env, "nil");
}

// int xlFormatBorderBottom(FormatHandle handle);
ERL_NIF_TERM c_xlFormatBorderBottom(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatBorderBottom(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetBorderBottom(FormatHandle handle, int style);
ERL_NIF_TERM c_xlFormatSetBorderBottom(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int style;

	if (0 == enif_get_int(env, argv[1], &style)) {
		return enif_make_badarg(env);
	}

	xlFormatSetBorderBottom(format_resource->handle, style);

	return enif_make_atom(env, "nil");
}

// int xlFormatBorderLeftColor(FormatHandle handle);
ERL_NIF_TERM c_xlFormatBorderLeftColor(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatBorderLeftColor(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetBorderLeftColor(FormatHandle handle, int color);
ERL_NIF_TERM c_xlFormatSetBorderLeftColor(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int style;

	if (0 == enif_get_int(env, argv[1], &style)) {
		return enif_make_badarg(env);
	}

	xlFormatSetBorderLeftColor(format_resource->handle, style);

	return enif_make_atom(env, "nil");
}

// int xlFormatBorderRightColor(FormatHandle handle);
ERL_NIF_TERM c_xlFormatBorderRightColor(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatBorderRightColor(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetBorderRightColor(FormatHandle handle, int color);
ERL_NIF_TERM c_xlFormatSetBorderRightColor(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	return enif_make_atom(env, "nil");
}

// int xlFormatBorderTopColor(FormatHandle handle);
ERL_NIF_TERM c_xlFormatBorderTopColor(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatBorderTopColor(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetBorderTopColor(FormatHandle handle, int color);
ERL_NIF_TERM c_xlFormatSetBorderTopColor(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int color;

	if (0 == enif_get_int(env, argv[1], &color)) {
		return enif_make_badarg(env);
	}

	xlFormatSetBorderTopColor(format_resource->handle, color);

	return enif_make_atom(env, "nil");
}

// int xlFormatBorderBottomColor(FormatHandle handle);
ERL_NIF_TERM c_xlFormatBorderBottomColor(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatBorderBottomColor(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetBorderBottomColor(FormatHandle handle, int color);
ERL_NIF_TERM c_xlFormatSetBorderBottomColor(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int color;

	if (0 == enif_get_int(env, argv[1], &color)) {
		return enif_make_badarg(env);
	}

	xlFormatSetBorderBottomColor(format_resource->handle, color);

	return enif_make_atom(env, "nil");
}

// int xlFormatBorderDiagonal(FormatHandle handle);
ERL_NIF_TERM c_xlFormatBorderDiagonal(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatBorderDiagonal(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetBorderDiagonal(FormatHandle handle, int border);
ERL_NIF_TERM c_xlFormatSetBorderDiagonal(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int border;

	if (0 == enif_get_int(env, argv[1], &border)) {
		return enif_make_badarg(env);
	}

	xlFormatSetBorderDiagonal(format_resource->handle, border);

	return enif_make_atom(env, "nil");
}

// int xlFormatBorderDiagonalStyle(FormatHandle handle);
ERL_NIF_TERM c_xlFormatBorderDiagonalStyle(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatBorderDiagonalStyle(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetBorderDiagonalStyle(FormatHandle handle, int style);
ERL_NIF_TERM c_xlFormatSetBorderDiagonalStyle(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int style;

	if (0 == enif_get_int(env, argv[1], &style)) {
		return enif_make_badarg(env);
	}

	xlFormatSetBorderDiagonalStyle(format_resource->handle, style);

	return enif_make_atom(env, "nil");
}

// int xlFormatBorderDiagonalColor(FormatHandle handle);
ERL_NIF_TERM c_xlFormatBorderDiagonalColor(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatBorderDiagonalColor(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetBorderDiagonalColor(FormatHandle handle, int color);
ERL_NIF_TERM c_xlFormatSetBorderDiagonalColor(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int color;

	if (0 == enif_get_int(env, argv[1], &color)) {
		return enif_make_badarg(env);
	}

	xlFormatSetBorderDiagonalColor(format_resource->handle, color);

	return enif_make_atom(env, "nil");
}

// int xlFormatFillPattern(FormatHandle handle);
ERL_NIF_TERM c_xlFormatFillPattern(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatFillPattern(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetFillPattern(FormatHandle handle, int pattern);
ERL_NIF_TERM c_xlFormatSetFillPattern(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int pattern;

	if (0 == enif_get_int(env, argv[1], &pattern)) {
		return enif_make_badarg(env);
	}

	xlFormatSetFillPattern(format_resource->handle, pattern);

	return enif_make_atom(env, "nil");
}

// int xlFormatPatternForegroundColor(FormatHandle handle);
ERL_NIF_TERM c_xlFormatPatternForegroundColor(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatPatternForegroundColor(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetPatternForegroundColor(FormatHandle handle, int color);
ERL_NIF_TERM c_xlFormatSetPatternForegroundColor(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int color;

	if (0 == enif_get_int(env, argv[1], &color)) {
		return enif_make_badarg(env);
	}

	xlFormatSetPatternForegroundColor(format_resource->handle, color);

	return enif_make_atom(env, "nil");
}

// int xlFormatPatternBackgroundColor(FormatHandle handle);
ERL_NIF_TERM c_xlFormatPatternBackgroundColor(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatPatternBackgroundColor(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetPatternBackgroundColor(FormatHandle handle, int color);
ERL_NIF_TERM c_xlFormatSetPatternBackgroundColor(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	return enif_make_atom(env, "nil");
}

// int xlFormatLocked(FormatHandle handle);
ERL_NIF_TERM c_xlFormatLocked(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatLocked(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetLocked(FormatHandle handle, int locked);
ERL_NIF_TERM c_xlFormatSetLocked(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int locked;

	if (0 == enif_get_int(env, argv[1], &locked)) {
		return enif_make_badarg(env);
	}

	xlFormatSetLocked(format_resource->handle, locked);

	return enif_make_atom(env, "nil");
}

// int xlFormatHidden(FormatHandle handle);
ERL_NIF_TERM c_xlFormatHidden(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int ret = xlFormatHidden(format_resource->handle);

	return enif_make_int(env, ret);
}

// void xlFormatSetHidden(FormatHandle handle, int hidden);
ERL_NIF_TERM c_xlFormatSetHidden(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	FormatType *format_resource = NULL;

	if (0 == enif_get_resource(env, argv[0], TypeOfFormat, (void**)&format_resource)) {
		return enif_make_badarg(env);
	}

	int hidden;

	if (0 == enif_get_int(env, argv[1], &hidden)) {
		return enif_make_badarg(env);
	}

	xlFormatSetHidden(format_resource->handle, hidden);

	return enif_make_atom(env, "nil");
}
