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

#line 1 "GladeXML.xs"
/*
 * $Header: /cvsroot/gtk2-perl/gtk2-perl-xs/Glade/GladeXML.xs,v 1.14 2006/05/07 14:20:42 kaffeetisch Exp $
 *
 */

#include "gladexmlperl.h"

static GPerlCallback *
create_connect_func_handler_callback (SV * func, SV * data)
{
	GType param_types[] = {
		G_TYPE_STRING,
		G_TYPE_OBJECT,
		G_TYPE_STRING,
		G_TYPE_STRING,
		G_TYPE_OBJECT,
		G_TYPE_BOOLEAN
	};
	return gperl_callback_new (func, data,
	                           G_N_ELEMENTS (param_types),
	                           param_types,
	                           G_TYPE_NONE);
}

static void
connect_func_handler (const gchar *handler_name,
		      GObject     *object,
		      const gchar *signal_name,
		      const gchar *signal_data,
		      GObject     *connect_object,
		      gboolean     after,
		      gpointer     user_data)
{
#define IF_NULL_SET_EMPTY(var) \
	if( !(var) )		\
		(var) = "";
	IF_NULL_SET_EMPTY(handler_name);
	IF_NULL_SET_EMPTY(signal_name);
	IF_NULL_SET_EMPTY(signal_data);
#undef IF_NULL_SET_EMPTY

	gperl_callback_invoke ((GPerlCallback*) user_data,
	                       NULL,
			       handler_name,
			       object,
			       signal_name,
			       signal_data,
			       connect_object,
			       after,
			       user_data);
}

static GtkWidget*
glade_custom_widget(
	GladeXML * xml,
	gchar    * func_name,
	char     * name,
	char     * string1,
	char     * string2,
	int        int1,
	int        int2,
	gpointer   data
) {
	GPerlCallback * callback     = (GPerlCallback*)data;
	GValue          return_value = {0,};
	GtkWidget*      retval;
	g_value_init(&return_value, callback->return_type);
	gperl_callback_invoke(
		callback,       /*the perl subroutine*/
		&return_value,  /*to catch the return value*/
		xml,            /*the calling gladexml object*/
		func_name,      /*the widget creation function name*/
		name,           /*this widget's name for use with get_widget*/
		string1,        /*the four args from the xml file*/
		string2,
		int1,
		int2
	);
	/* dup refs, unset unrefs. */
	retval = (GtkWidget *)g_value_dup_object(&return_value);
	g_value_unset(&return_value);
	return retval;
}

#line 95 "GladeXML.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(const CV *const cv, const char *const params);

STATIC void
S_croak_xs_usage(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_nocontext("Usage: %s::%s(%s)", hvname, gvname, params);
        else
	    Perl_croak_nocontext("Usage: %s(%s)", gvname, params);
    } else {
        /* Pants. I don't think that it should be possible to get here. */
	Perl_croak_nocontext("Usage: CODE(0x%" UVxf ")(%s)", PTR2UV(cv), params);
    }
}
#undef  PERL_ARGS_ASSERT_CROAK_XS_USAGE

#define croak_xs_usage        S_croak_xs_usage

#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) */

#if PERL_VERSION_LE(5, 21, 5)
#  define newXS_deffile(a,b) Perl_newXS(aTHX_ a,b,file)
#else
#  define newXS_deffile(a,b) Perl_newXS_deffile(aTHX_ a,b)
#endif

#line 239 "GladeXML.c"

XS_EUPXS(XS_Gtk2__GladeXML_new); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gtk2__GladeXML_new)
{
    dVAR; dXSARGS;
    if (items < 2 || items > 4)
       croak_xs_usage(cv,  "class, filename, root=NULL, domain=NULL");
    {
	GPerlFilename	filename = (GPerlFilename) gperl_filename_from_sv (ST(1))
;
	const char_ornull *	root;
	const char_ornull *	domain;
	GladeXML_ornull *	RETVAL;

	if (items < 3)
	    root = NULL;
	else {
	    if (gperl_sv_is_defined (ST(2))) {
		    root = (const char_ornull *)SvPV_nolen (ST(2));
	    } else {
		    root = NULL;
	    }
;
	}

	if (items < 4)
	    domain = NULL;
	else {
	    if (gperl_sv_is_defined (ST(3))) {
		    domain = (const char_ornull *)SvPV_nolen (ST(3));
	    } else {
		    domain = NULL;
	    }
;
	}

	RETVAL = glade_xml_new(filename, root, domain);
	{
	    SV * RETVALSV;
	    RETVALSV = newSVGladeXML_ornull(RETVAL);
	    RETVALSV = sv_2mortal(RETVALSV);
	    ST(0) = RETVALSV;
	}
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Gtk2__GladeXML_new_from_buffer); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gtk2__GladeXML_new_from_buffer)
{
    dVAR; dXSARGS;
    if (items < 2 || items > 4)
       croak_xs_usage(cv,  "class, buffer, root=NULL, domain=NULL");
    {
	SV *	buffer = ST(1)
;
	const char_ornull *	root;
	const char_ornull *	domain;
#line 106 "GladeXML.xs"
	STRLEN len;
	char *p;
#line 302 "GladeXML.c"
	GladeXML_ornull *	RETVAL;

	if (items < 3)
	    root = NULL;
	else {
	    if (gperl_sv_is_defined (ST(2))) {
		    root = (const char_ornull *)SvPV_nolen (ST(2));
	    } else {
		    root = NULL;
	    }
;
	}

	if (items < 4)
	    domain = NULL;
	else {
	    if (gperl_sv_is_defined (ST(3))) {
		    domain = (const char_ornull *)SvPV_nolen (ST(3));
	    } else {
		    domain = NULL;
	    }
;
	}
#line 109 "GladeXML.xs"
    	p = SvPV(buffer, len);
	RETVAL = glade_xml_new_from_buffer(p, len, root, domain);
#line 329 "GladeXML.c"
	{
	    SV * RETVALSV;
	    RETVALSV = newSVGladeXML_ornull(RETVAL);
	    RETVALSV = sv_2mortal(RETVALSV);
	    ST(0) = RETVALSV;
	}
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Gtk2__GladeXML_signal_autoconnect); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gtk2__GladeXML_signal_autoconnect)
{
    dVAR; dXSARGS;
    if (items < 2 || items > 3)
       croak_xs_usage(cv,  "self, func, user_data=NULL");
    {
	GladeXML *	self = SvGladeXML(ST(0))
;
	SV *	func = ST(1)
;
	SV *	user_data;
#line 145 "GladeXML.xs"
	GPerlCallback * real_callback;
#line 355 "GladeXML.c"

	if (items < 3)
	    user_data = NULL;
	else {
	    user_data = ST(2)
;
	}
#line 147 "GladeXML.xs"
	real_callback = create_connect_func_handler_callback (func, user_data);
    	glade_xml_signal_autoconnect_full (self,
	                                   connect_func_handler, 
	                                   real_callback);
	gperl_callback_destroy (real_callback);
#line 369 "GladeXML.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Gtk2__GladeXML_signal_connect_full); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gtk2__GladeXML_signal_connect_full)
{
    dVAR; dXSARGS;
    if (items < 3 || items > 4)
       croak_xs_usage(cv,  "self, handler_name, func, user_data=NULL");
    {
	GladeXML *	self = SvGladeXML(ST(0))
;
	const gchar *	handler_name;
	SV *	func = ST(2)
;
	SV *	user_data;
#line 162 "GladeXML.xs"
	GPerlCallback * real_callback;
#line 390 "GladeXML.c"

	/* same as SvGChar(), but not in a function */
	sv_utf8_upgrade (ST(1));
	handler_name = (const gchar *)SvPV_nolen (ST(1))
;

	if (items < 4)
	    user_data = NULL;
	else {
	    user_data = ST(3)
;
	}
#line 164 "GladeXML.xs"
	real_callback = create_connect_func_handler_callback (func, user_data);
    	glade_xml_signal_connect_full (self, handler_name, connect_func_handler, 
				       real_callback);
	gperl_callback_destroy (real_callback);
#line 408 "GladeXML.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Gtk2__GladeXML_get_widget); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gtk2__GladeXML_get_widget)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "self, name");
    {
	GladeXML *	self = SvGladeXML(ST(0))
;
	const char *	name = (const char *)SvPV_nolen(ST(1))
;
	GtkWidget_ornull *	RETVAL;

	RETVAL = glade_xml_get_widget(self, name);
	{
	    SV * RETVALSV;
	    RETVALSV = newSVGtkWidget_ornull (RETVAL);
	    RETVALSV = sv_2mortal(RETVALSV);
	    ST(0) = RETVALSV;
	}
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Gtk2__GladeXML_get_widget_prefix); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gtk2__GladeXML_get_widget_prefix)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "self, name");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	GladeXML *	self = SvGladeXML(ST(0))
;
	const char *	name = (const char *)SvPV_nolen(ST(1))
;
#line 181 "GladeXML.xs"
	GList * widgets = NULL;
	GList * i = NULL;
#line 455 "GladeXML.c"
#line 184 "GladeXML.xs"
	widgets = glade_xml_get_widget_prefix(self, name);
	if( !widgets )
		XSRETURN_EMPTY;
	for( i = widgets; i != NULL; i = i->next )
		XPUSHs(sv_2mortal(newSVGtkWidget(i->data)));
	g_list_free(widgets);
#line 463 "GladeXML.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Gtk2__GladeXML_relative_file); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gtk2__GladeXML_relative_file)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "self, filename");
    {
	GladeXML *	self = SvGladeXML(ST(0))
;
	GPerlFilename	filename = (GPerlFilename) gperl_filename_from_sv (ST(1))
;
	gchar_own *	RETVAL;

	RETVAL = glade_xml_relative_file(self, filename);
	{
	    SV * RETVALSV;
	    RETVALSV = sv_newmortal();
	    /* used when we can directly own the returned string. */
	    /* we have to copy in the case when perl's malloc != gtk's malloc,
	     * so best copy all the time. */
	    sv_setpv ((SV*)RETVALSV, RETVAL);
	    SvUTF8_on (RETVALSV);
	    g_free (RETVAL);
	    ST(0) = RETVALSV;
	}
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Gtk2__Glade_set_custom_handler); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gtk2__Glade_set_custom_handler)
{
    dVAR; dXSARGS;
    if (items < 2 || items > 3)
       croak_xs_usage(cv,  "class, callback, callback_data=NULL");
    {
	SV *	callback = ST(1)
;
	SV *	callback_data;
#line 208 "GladeXML.xs"
        static GPerlCallback * real_callback = NULL;
        GType param_types [] = {
		GLADE_TYPE_XML,  /*gladexml object*/
		G_TYPE_STRING,   /*creation function name*/
		G_TYPE_STRING,   /*widget name*/
		G_TYPE_STRING,   /*string 1*/
		G_TYPE_STRING,   /*string 2*/
		G_TYPE_INT,      /*integer 1*/
		G_TYPE_INT       /*integer 2*/
	};
#line 521 "GladeXML.c"

	if (items < 3)
	    callback_data = NULL;
	else {
	    callback_data = ST(2)
;
	}
#line 219 "GladeXML.xs"
	if (real_callback)
		/* we're being called again... */
		gperl_callback_destroy (real_callback);
	real_callback = gperl_callback_new(
		callback,       /*perl function to treat as a callback*/
		callback_data,  /*extra data to pass to callback*/
		7,              /*number of parameters*/
		param_types,    /*list of parameters*/
		GTK_TYPE_WIDGET /*return type*/
	);
	glade_set_custom_handler (glade_custom_widget, real_callback);
#line 541 "GladeXML.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Gtk2__Widget_get_widget_name); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gtk2__Widget_get_widget_name)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "widget");
    {
	GtkWidget *	widget = SvGtkWidget (ST(0))
;
	const char *	RETVAL;
	dXSTARG;

	RETVAL = glade_get_widget_name(widget);
	sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG;
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Gtk2__Widget_get_widget_tree); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gtk2__Widget_get_widget_tree)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "widget");
    {
	GtkWidget *	widget = SvGtkWidget (ST(0))
;
	GladeXML *	RETVAL;

	RETVAL = glade_get_widget_tree(widget);
	{
	    SV * RETVALSV;
	    RETVALSV = newSVGladeXML(RETVAL);
	    RETVALSV = sv_2mortal(RETVALSV);
	    ST(0) = RETVALSV;
	}
    }
    XSRETURN(1);
}

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

    PERL_UNUSED_VAR(file);

    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
#if PERL_VERSION_LE(5, 21, 5)
    XS_VERSION_BOOTCHECK;
#  ifdef XS_APIVERSION_BOOTCHECK
    XS_APIVERSION_BOOTCHECK;
#  endif
#endif

        newXS_deffile("Gtk2::GladeXML::new", XS_Gtk2__GladeXML_new);
        newXS_deffile("Gtk2::GladeXML::new_from_buffer", XS_Gtk2__GladeXML_new_from_buffer);
        newXS_deffile("Gtk2::GladeXML::signal_autoconnect", XS_Gtk2__GladeXML_signal_autoconnect);
        newXS_deffile("Gtk2::GladeXML::signal_connect_full", XS_Gtk2__GladeXML_signal_connect_full);
        newXS_deffile("Gtk2::GladeXML::get_widget", XS_Gtk2__GladeXML_get_widget);
        newXS_deffile("Gtk2::GladeXML::get_widget_prefix", XS_Gtk2__GladeXML_get_widget_prefix);
        newXS_deffile("Gtk2::GladeXML::relative_file", XS_Gtk2__GladeXML_relative_file);
        newXS_deffile("Gtk2::Glade::set_custom_handler", XS_Gtk2__Glade_set_custom_handler);
        newXS_deffile("Gtk2::Widget::get_widget_name", XS_Gtk2__Widget_get_widget_name);
        newXS_deffile("Gtk2::Widget::get_widget_tree", XS_Gtk2__Widget_get_widget_tree);

    /* Initialisation Section */

#line 88 "GladeXML.xs"
	gperl_register_object (GLADE_TYPE_XML, "Gtk2::GladeXML");

#line 632 "GladeXML.c"

    /* End of Initialisation Section */

#if PERL_VERSION_LE(5, 21, 5)
#  if PERL_VERSION_GE(5, 9, 0)
    if (PL_unitcheckav)
        call_list(PL_scopestack_ix, PL_unitcheckav);
#  endif
    XSRETURN_YES;
#else
    Perl_xs_boot_epilog(aTHX_ ax);
#endif
}

