/*
 * This file was generated automatically by ExtUtils::ParseXS version 3.24 from the
 * contents of GnomeIconTheme.xs. Do not edit this file, edit GnomeIconTheme.xs instead.
 *
 *    ANY CHANGES MADE HERE WILL BE LOST!
 *
 */

#line 1 "xs/GnomeIconTheme.xs"
/*
 * Copyright (C) 2003, 2013 by the gtk2-perl team (see the file AUTHORS)
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library 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 LICENSE file in the top level of this distribution
 * for the complete license terms.
 *
 */

#include "gnome2perl.h"

/* gnome-icon-theme.h was deprecated in 2003. */
#undef GNOME_DISABLE_DEPRECATED

#ifdef GNOME_TYPE_ICON_THEME

static SV * 
newSVGnomeIconData (const GnomeIconData * data)
{
	HV * hv = newHV ();

	if (data) {
		AV * av = newAV ();
		int i;

		for (i = 0; i < data->n_attach_points; i++) {
			AV * av_points = newAV ();
			GnomeIconDataPoint point = (data->attach_points)[i];

			av_store (av_points, 0, newSViv (point.x));
			av_store (av_points, 1, newSViv (point.y));

			av_store (av, i, newRV_noinc ((SV*) av_points));
		}

		hv_store (hv, "has_embedded_rect", 17, newSVuv (data->has_embedded_rect), 0);
		hv_store (hv, "x0", 2, newSViv (data->x0), 0);
		hv_store (hv, "y0", 2, newSViv (data->y0), 0);
		hv_store (hv, "x1", 2, newSViv (data->x1), 0);
		hv_store (hv, "y1", 2, newSViv (data->y1), 0);
		hv_store (hv, "attach_points", 13, newRV_noinc ((SV*) av), 0);
		if (data->display_name)
			hv_store (hv, "display_name", 12, newSVpv (data->display_name, 0), 0);
	}

	return newRV_noinc ((SV *) hv);
}

#if 0 /* not used at the moment */

static GnomeIconData * 
SvGnomeIconData (SV * sv)
{
	HV * hv = (HV*) SvRV (sv);
	SV ** value;
	GnomeIconData * data = gperl_alloc_temp (sizeof (GnomeIconData));

	SV ** points = hv_fetch (hv, "attach_points", 13, FALSE);

	int i;
	AV * av = (AV*) SvRV (*points);

	if (! (sv && SvOK (sv) && SvROK (sv) && SvTYPE (SvRV (sv)) == SVt_PVHV))
		croak ("malformed icon data; use a reference to a hash as icon data");

	/* ----------------------------------------------------------------- */

	value = hv_fetch (hv, "has_embedded_rect", 17, FALSE);
	if (value) data->has_embedded_rect = SvUV (*value);

	value = hv_fetch (hv, "x0", 2, FALSE);
	if (value) data->x0 = SvIV (*value);

	value = hv_fetch (hv, "y0", 2, FALSE);
	if (value) data->y0 = SvIV (*value);

	value = hv_fetch (hv, "x1", 2, FALSE);
	if (value) data->x1 = SvIV (*value);

	value = hv_fetch (hv, "y1", 2, FALSE);
	if (value) data->y1 = SvIV (*value);

	value = hv_fetch (hv, "display_name", 12, FALSE);
	if (value) data->display_name = SvPV_nolen (*value);

	/* ----------------------------------------------------------------- */

	if (! (*points && SvOK (*points) && SvROK (*points) && SvTYPE (SvRV (*points)) == SVt_PVAV))
		croak ("malformed points data; use a reference to an array as points data");

	data->attach_points = gperl_alloc_temp (av_len (av) * sizeof (GnomeIconDataPoint));

	for (i = 0; i <= av_len (av); i++) {
		SV ** point = av_fetch (av, i, FALSE);
		AV * av_point = (AV*) SvRV (*point);

		GnomeIconDataPoint point_data;

		if (! (*point && SvOK (*point) && SvROK (*point) && SvTYPE (SvRV (*point)) == SVt_PVAV))
			croak ("malformed point data; use a reference to an array as point data");

		if (av_len (av) != 1)
			croak ("malformed point data; point data must have two elements");

		point = av_fetch (av_point, 0, FALSE);
		if (point) point_data.x = SvIV (*point);

		point = av_fetch (av_point, 1, FALSE);
		if (point) point_data.y = SvIV (*point);

		(data->attach_points)[i] = point_data;
	}

	/* ----------------------------------------------------------------- */

	return data;
}

#endif

#endif /* GNOME_TYPE_ICON_THEME */

#line 141 "xs/GnomeIconTheme.c"
#ifndef PERL_UNUSED_VAR
#  define PERL_UNUSED_VAR(var) if (0) var = var
#endif

#ifndef dVAR
#  define dVAR		dNOOP
#endif


/* This stuff is not part of the API! You have been warned. */
#ifndef PERL_VERSION_DECIMAL
#  define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s)
#endif
#ifndef PERL_DECIMAL_VERSION
#  define PERL_DECIMAL_VERSION \
	  PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION)
#endif
#ifndef PERL_VERSION_GE
#  define PERL_VERSION_GE(r,v,s) \
	  (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
#endif
#ifndef PERL_VERSION_LE
#  define PERL_VERSION_LE(r,v,s) \
	  (PERL_DECIMAL_VERSION <= PERL_VERSION_DECIMAL(r,v,s))
#endif

/* XS_INTERNAL is the explicit static-linkage variant of the default
 * XS macro.
 *
 * XS_EXTERNAL is the same as XS_INTERNAL except it does not include
 * "STATIC", ie. it exports XSUB symbols. You probably don't want that
 * for anything but the BOOT XSUB.
 *
 * See XSUB.h in core!
 */


/* TODO: This might be compatible further back than 5.10.0. */
#if PERL_VERSION_GE(5, 10, 0) && PERL_VERSION_LE(5, 15, 1)
#  undef XS_EXTERNAL
#  undef XS_INTERNAL
#  if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
#    define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO(name)
#    define XS_INTERNAL(name) STATIC XSPROTO(name)
#  endif
#  if defined(__SYMBIAN32__)
#    define XS_EXTERNAL(name) EXPORT_C XSPROTO(name)
#    define XS_INTERNAL(name) EXPORT_C STATIC XSPROTO(name)
#  endif
#  ifndef XS_EXTERNAL
#    if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
#      define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unused__)
#      define XS_INTERNAL(name) STATIC void name(pTHX_ CV* cv __attribute__unused__)
#    else
#      ifdef __cplusplus
#        define XS_EXTERNAL(name) extern "C" XSPROTO(name)
#        define XS_INTERNAL(name) static XSPROTO(name)
#      else
#        define XS_EXTERNAL(name) XSPROTO(name)
#        define XS_INTERNAL(name) STATIC XSPROTO(name)
#      endif
#    endif
#  endif
#endif

/* perl >= 5.10.0 && perl <= 5.15.1 */


/* The XS_EXTERNAL macro is used for functions that must not be static
 * like the boot XSUB of a module. If perl didn't have an XS_EXTERNAL
 * macro defined, the best we can do is assume XS is the same.
 * Dito for XS_INTERNAL.
 */
#ifndef XS_EXTERNAL
#  define XS_EXTERNAL(name) XS(name)
#endif
#ifndef XS_INTERNAL
#  define XS_INTERNAL(name) XS(name)
#endif

/* Now, finally, after all this mess, we want an ExtUtils::ParseXS
 * internal macro that we're free to redefine for varying linkage due
 * to the EXPORT_XSUB_SYMBOLS XS keyword. This is internal, use
 * XS_EXTERNAL(name) or XS_INTERNAL(name) in your code if you need to!
 */

#undef XS_EUPXS
#if defined(PERL_EUPXS_ALWAYS_EXPORT)
#  define XS_EUPXS(name) XS_EXTERNAL(name)
#else
   /* default to internal */
#  define XS_EUPXS(name) XS_INTERNAL(name)
#endif

#ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE
#define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params)

/* prototype to pass -Wmissing-prototypes */
STATIC void
S_croak_xs_usage(pTHX_ const CV *const cv, const char *const params);

STATIC void
S_croak_xs_usage(pTHX_ const CV *const cv, const char *const params)
{
    const GV *const gv = CvGV(cv);

    PERL_ARGS_ASSERT_CROAK_XS_USAGE;

    if (gv) {
        const char *const gvname = GvNAME(gv);
        const HV *const stash = GvSTASH(gv);
        const char *const hvname = stash ? HvNAME(stash) : NULL;

        if (hvname)
            Perl_croak(aTHX_ "Usage: %s::%s(%s)", hvname, gvname, params);
        else
            Perl_croak(aTHX_ "Usage: %s(%s)", gvname, params);
    } else {
        /* Pants. I don't think that it should be possible to get here. */
        Perl_croak(aTHX_ "Usage: CODE(0x%"UVxf")(%s)", PTR2UV(cv), params);
    }
}
#undef  PERL_ARGS_ASSERT_CROAK_XS_USAGE

#ifdef PERL_IMPLICIT_CONTEXT
#define croak_xs_usage(a,b)    S_croak_xs_usage(aTHX_ a,b)
#else
#define croak_xs_usage        S_croak_xs_usage
#endif

#endif

/* NOTE: the prototype of newXSproto() is different in versions of perls,
 * so we define a portable version of newXSproto()
 */
#ifdef newXS_flags
#define newXSproto_portable(name, c_impl, file, proto) newXS_flags(name, c_impl, file, proto, 0)
#else
#define newXSproto_portable(name, c_impl, file, proto) (PL_Sv=(SV*)newXS(name, c_impl, file), sv_setpv(PL_Sv, proto), (CV*)PL_Sv)
#endif /* !defined(newXS_flags) */

#line 283 "xs/GnomeIconTheme.c"
#ifdef GNOME_TYPE_ICON_THEME
#define XSubPPtmpAAAA 1


XS_EUPXS(XS_Gnome2__IconTheme_new); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__IconTheme_new)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "class");
    {
	GnomeIconTheme *	RETVAL;

	RETVAL = gnome_icon_theme_new(/* void */);
	ST(0) = newSVGnomeIconTheme (RETVAL);
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Gnome2__IconTheme_set_search_path); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__IconTheme_set_search_path)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "theme, ...");
    {
	GnomeIconTheme *	theme = SvGnomeIconTheme (ST(0))
;
#line 157 "xs/GnomeIconTheme.xs"
	int i;
	const char **path = NULL;
#line 317 "xs/GnomeIconTheme.c"
#line 160 "xs/GnomeIconTheme.xs"
	path = g_new0 (const char*, items - 1);

	for (i = 1; i < items; i++)
		path[i - 1] = SvPV_nolen (ST (i));

	gnome_icon_theme_set_search_path (theme, path, i - 1);
#line 325 "xs/GnomeIconTheme.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Gnome2__IconTheme_get_search_path); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__IconTheme_get_search_path)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "theme");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	GnomeIconTheme *	theme = SvGnomeIconTheme (ST(0))
;
#line 177 "xs/GnomeIconTheme.xs"
	char **path;
	int n_elements, i;
#line 345 "xs/GnomeIconTheme.c"
#line 180 "xs/GnomeIconTheme.xs"
	gnome_icon_theme_get_search_path (theme, &path, &n_elements);

	if (path) {
		EXTEND (sp, n_elements);
		for (i = 0; i < n_elements; i++)
			PUSHs (sv_2mortal (newSVpv (path[i], 0)));
	}
	else
		XSRETURN_EMPTY;
#line 356 "xs/GnomeIconTheme.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Gnome2__IconTheme_set_allow_svg); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__IconTheme_set_allow_svg)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "theme, allow_svg");
    {
	GnomeIconTheme *	theme = SvGnomeIconTheme (ST(0))
;
	gboolean	allow_svg = (bool)SvTRUE(ST(1))
;

	gnome_icon_theme_set_allow_svg(theme, allow_svg);
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Gnome2__IconTheme_get_allow_svg); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__IconTheme_get_allow_svg)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "theme");
    {
	GnomeIconTheme *	theme = SvGnomeIconTheme (ST(0))
;
	gboolean	RETVAL;

	RETVAL = gnome_icon_theme_get_allow_svg(theme);
	ST(0) = boolSV(RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Gnome2__IconTheme_append_search_path); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__IconTheme_append_search_path)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "theme, path");
    {
	GnomeIconTheme *	theme = SvGnomeIconTheme (ST(0))
;
	const char *	path = (const char *)SvPV_nolen(ST(1))
;

	gnome_icon_theme_append_search_path(theme, path);
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Gnome2__IconTheme_prepend_search_path); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__IconTheme_prepend_search_path)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "theme, path");
    {
	GnomeIconTheme *	theme = SvGnomeIconTheme (ST(0))
;
	const char *	path = (const char *)SvPV_nolen(ST(1))
;

	gnome_icon_theme_prepend_search_path(theme, path);
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Gnome2__IconTheme_set_custom_theme); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__IconTheme_set_custom_theme)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "theme, theme_name");
    {
	GnomeIconTheme *	theme = SvGnomeIconTheme (ST(0))
;
	const char *	theme_name = (const char *)SvPV_nolen(ST(1))
;

	gnome_icon_theme_set_custom_theme(theme, theme_name);
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Gnome2__IconTheme_lookup_icon); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__IconTheme_lookup_icon)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "theme, icon_name, size");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	GnomeIconTheme *	theme = SvGnomeIconTheme (ST(0))
;
	const char *	icon_name = (const char *)SvPV_nolen(ST(1))
;
	int	size = (int)SvIV(ST(2))
;
#line 232 "xs/GnomeIconTheme.xs"
	char *filename;
	const GnomeIconData *icon_data;
	int base_size;
#line 472 "xs/GnomeIconTheme.c"
#line 236 "xs/GnomeIconTheme.xs"
	filename = gnome_icon_theme_lookup_icon (theme, icon_name, size, &icon_data, &base_size);

	if (!filename)
		XSRETURN_EMPTY;

	EXTEND (sp, 3);
	PUSHs (sv_2mortal (newSVpv (filename, 0)));
	PUSHs (sv_2mortal (newSVGnomeIconData (icon_data)));
	PUSHs (sv_2mortal (newSViv (base_size)));

	g_free (filename);
#line 485 "xs/GnomeIconTheme.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Gnome2__IconTheme_has_icon); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__IconTheme_has_icon)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "theme, icon_name");
    {
	GnomeIconTheme *	theme = SvGnomeIconTheme (ST(0))
;
	const char *	icon_name = (const char *)SvPV_nolen(ST(1))
;
	gboolean	RETVAL;

	RETVAL = gnome_icon_theme_has_icon(theme, icon_name);
	ST(0) = boolSV(RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Gnome2__IconTheme_list_icons); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__IconTheme_list_icons)
{
    dVAR; dXSARGS;
    if (items < 1 || items > 2)
       croak_xs_usage(cv,  "theme, context=NULL");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	GnomeIconTheme *	theme = SvGnomeIconTheme (ST(0))
;
	const char *	context;
#line 265 "xs/GnomeIconTheme.xs"
	GList *i, *results = NULL;
#line 526 "xs/GnomeIconTheme.c"

	if (items < 2)
	    context = NULL;
	else {
	    context = (const char *)SvPV_nolen(ST(1))
;
	}
#line 267 "xs/GnomeIconTheme.xs"
	results = gnome_icon_theme_list_icons (theme, context);
	for (i = results; i != NULL; i = i->next) {
		XPUSHs (sv_2mortal (newSVpv (i->data, 0)));
		g_free (i->data);
	}
	g_list_free (results);
#line 541 "xs/GnomeIconTheme.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Gnome2__IconTheme_get_example_icon_name); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__IconTheme_get_example_icon_name)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "theme");
    {
	GnomeIconTheme *	theme = SvGnomeIconTheme (ST(0))
;
	char *	RETVAL;
	dXSTARG;

	RETVAL = gnome_icon_theme_get_example_icon_name(theme);
	sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG;
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Gnome2__IconTheme_rescan_if_needed); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__IconTheme_rescan_if_needed)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "theme");
    {
	GnomeIconTheme *	theme = SvGnomeIconTheme (ST(0))
;
	gboolean	RETVAL;

	RETVAL = gnome_icon_theme_rescan_if_needed(theme);
	ST(0) = boolSV(RETVAL);
    }
    XSRETURN(1);
}

#endif
#ifdef __cplusplus
extern "C"
#endif
XS_EXTERNAL(boot_Gnome2__IconTheme); /* prototype to pass -Wmissing-prototypes */
XS_EXTERNAL(boot_Gnome2__IconTheme)
{
    dVAR; dXSARGS;
#if (PERL_REVISION == 5 && PERL_VERSION < 9)
    char* file = __FILE__;
#else
    const char* file = __FILE__;
#endif

    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
#ifdef XS_APIVERSION_BOOTCHECK
    XS_APIVERSION_BOOTCHECK;
#endif
    XS_VERSION_BOOTCHECK;

#if XSubPPtmpAAAA
        newXS("Gnome2::IconTheme::new", XS_Gnome2__IconTheme_new, file);
        newXS("Gnome2::IconTheme::set_search_path", XS_Gnome2__IconTheme_set_search_path, file);
        newXS("Gnome2::IconTheme::get_search_path", XS_Gnome2__IconTheme_get_search_path, file);
        newXS("Gnome2::IconTheme::set_allow_svg", XS_Gnome2__IconTheme_set_allow_svg, file);
        newXS("Gnome2::IconTheme::get_allow_svg", XS_Gnome2__IconTheme_get_allow_svg, file);
        newXS("Gnome2::IconTheme::append_search_path", XS_Gnome2__IconTheme_append_search_path, file);
        newXS("Gnome2::IconTheme::prepend_search_path", XS_Gnome2__IconTheme_prepend_search_path, file);
        newXS("Gnome2::IconTheme::set_custom_theme", XS_Gnome2__IconTheme_set_custom_theme, file);
        newXS("Gnome2::IconTheme::lookup_icon", XS_Gnome2__IconTheme_lookup_icon, file);
        newXS("Gnome2::IconTheme::has_icon", XS_Gnome2__IconTheme_has_icon, file);
        newXS("Gnome2::IconTheme::list_icons", XS_Gnome2__IconTheme_list_icons, file);
        newXS("Gnome2::IconTheme::get_example_icon_name", XS_Gnome2__IconTheme_get_example_icon_name, file);
        newXS("Gnome2::IconTheme::rescan_if_needed", XS_Gnome2__IconTheme_rescan_if_needed, file);
#endif

    /* Initialisation Section */

#line 134 "xs/GnomeIconTheme.xs"
/* pass -Werror even if there are no xsubs at all */
#ifndef GNOME_TYPE_ICON_THEME
	PERL_UNUSED_VAR (file);
#endif

#if XSubPPtmpAAAA
#endif
#line 631 "xs/GnomeIconTheme.c"

    /* End of Initialisation Section */

#if (PERL_REVISION == 5 && PERL_VERSION >= 9)
  if (PL_unitcheckav)
       call_list(PL_scopestack_ix, PL_unitcheckav);
#endif
    XSRETURN_YES;
}

