/*
 * This file was generated automatically by ExtUtils::ParseXS version 3.24 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(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 237 "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);
	ST(0) = newSVGladeXML_ornull(RETVAL);
	sv_2mortal(ST(0));
    }
    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 296 "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 323 "GladeXML.c"
	ST(0) = newSVGladeXML_ornull(RETVAL);
	sv_2mortal(ST(0));
    }
    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 345 "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 359 "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 380 "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 398 "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);
	ST(0) = newSVGtkWidget_ornull (RETVAL);
	sv_2mortal(ST(0));
    }
    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 441 "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 449 "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);
	ST(0) = 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*)ST(0), RETVAL);
	SvUTF8_on (ST(0));
        g_free (RETVAL);
    }
    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 503 "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 523 "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);
	ST(0) = newSVGladeXML(RETVAL);
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}

#ifdef __cplusplus
extern "C"
#endif
XS_EXTERNAL(boot_Gtk2__GladeXML); /* prototype to pass -Wmissing-prototypes */
XS_EXTERNAL(boot_Gtk2__GladeXML)
{
    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;

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

    /* Initialisation Section */

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

#line 602 "GladeXML.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;
}

