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

#line 1 "xs/GtkBindings.xs"
/*
 * Copyright 2009 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 Library 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 GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */

#include "gtk2perl.h"

/* GtkBindingSet is a struct treated here as a boxed type.  As of Gtk 2.12
   there's no GType for it, so that's created here, with a #ifndef in
   gtk2perl.h in case gtk gains it later.

   Once created a GtkBindingSet is never destroyed, so no ref counting and
   no distinction between "own" and "copy".

   ENHANCE-ME: Currently there's nothing to retrieve the contents of a
   bindingset at the perl level.  The widget_path_pspecs and other pspecs
   use a private PatternMatch struct so are inaccessible.  The linked list
   of GtkBindingEntry and their contained GtkBindingSignal might be
   extracted though, maybe in some form tolerably close to the kind of
   entry_add_signal() calls that would build the set.  */

static GtkBindingSet *
gtk2perl_binding_set_copy (GtkBindingSet *binding_set)
{
	/* no copying */
	return binding_set;
}
static void
gtk2perl_binding_set_free (GtkBindingSet *binding_set)
{
	PERL_UNUSED_VAR (binding_set);
	/* no freeing */
}
GType
gtk2perl_binding_set_get_type (void)
{
	static GType binding_set_type = 0;
	if (binding_set_type == 0)
		binding_set_type = g_boxed_type_register_static
			("GtkBindingSet",
			 (GBoxedCopyFunc) gtk2perl_binding_set_copy,
			 (GBoxedFreeFunc) gtk2perl_binding_set_free);
	return binding_set_type;
}

#line 68 "xs/GtkBindings.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 210 "xs/GtkBindings.c"

XS_EUPXS(XS_Gtk2__BindingSet_set_name); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gtk2__BindingSet_set_name)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "binding_set");
    {
	GtkBindingSet *	binding_set = SvGtkBindingSet (ST(0))
;
	gchar *	RETVAL;
#line 93 "xs/GtkBindings.xs"
	RETVAL = binding_set->set_name;
#line 224 "xs/GtkBindings.c"
	ST(0) = sv_newmortal();
	/* same as newSVGChar(), but not in a function */
	sv_setpv ((SV*)ST(0), RETVAL);
	SvUTF8_on (ST(0));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Gtk2__BindingSet_new); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gtk2__BindingSet_new)
{
    dVAR; dXSARGS;
    dXSI32;
    if (items != 2)
       croak_xs_usage(cv,  "class, name");
    {
	const gchar *	name;
	GtkBindingSet_ornull *	RETVAL;

	/* same as SvGChar(), but not in a function */
	sv_utf8_upgrade (ST(1));
	name = (const gchar *)SvPV_nolen (ST(1))
;
#line 158 "xs/GtkBindings.xs"
	switch (ix) {
	case 0:
		RETVAL = gtk_binding_set_new (name);
		break;
	case 1:
		RETVAL = gtk_binding_set_find (name);
		break;
	default:
	    {
		GType type;
		GtkObjectClass *oclass;
		type = gperl_object_type_from_package (name);
		if (! type)
			croak ("package %s is not registered to a GType",
			       name);
		if (! g_type_is_a (type, GTK_TYPE_OBJECT))
			croak ("'%s' is not an object subclass", name);
		oclass = (GtkObjectClass*) g_type_class_ref (type);
		RETVAL = gtk_binding_set_by_class (oclass);
		g_type_class_unref (oclass);
	    }
	    break;
	}
#line 273 "xs/GtkBindings.c"
	ST(0) = newSVGtkBindingSet_ornull (RETVAL);
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Gtk2__BindingSet_activate); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gtk2__BindingSet_activate)
{
    dVAR; dXSARGS;
    if (items != 4)
       croak_xs_usage(cv,  "binding_set, keyval, modifiers, object");
    {
	GtkBindingSet *	binding_set = SvGtkBindingSet (ST(0))
;
	guint	keyval = (guint)SvUV(ST(1))
;
	GdkModifierType	modifiers = SvGdkModifierType (ST(2))
;
	GtkObject *	object = SvGtkObject (ST(3))
;
	gboolean	RETVAL;

	RETVAL = gtk_binding_set_activate(binding_set, keyval, modifiers, object);
	ST(0) = boolSV(RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Gtk2__BindingSet_add_path); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gtk2__BindingSet_add_path)
{
    dVAR; dXSARGS;
    if (items != 4)
       croak_xs_usage(cv,  "binding_set, path_type, path_pattern, priority");
    {
	GtkBindingSet *	binding_set = SvGtkBindingSet (ST(0))
;
	GtkPathType	path_type = SvGtkPathType (ST(1))
;
	const gchar *	path_pattern;
	int	priority = (int)SvIV(ST(3))
;

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

	gtk_binding_set_add_path(binding_set, path_type, path_pattern, priority);
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Gtk2__BindingSet_entry_add_signal); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gtk2__BindingSet_entry_add_signal)
{
    dVAR; dXSARGS;
    if (items < 4)
       croak_xs_usage(cv,  "binding_set, keyval, modifiers, signal_name, ...");
    {
	GtkBindingSet *	binding_set = SvGtkBindingSet (ST(0))
;
	guint	keyval = (guint)SvUV(ST(1))
;
	GdkModifierType	modifiers = SvGdkModifierType (ST(2))
;
	const gchar *	signal_name;
#line 313 "xs/GtkBindings.xs"
	const int first_argnum = 4;
	int count, i;
	GSList *binding_args = NULL;
	GtkBindingArg *ap;
#line 350 "xs/GtkBindings.c"

	/* same as SvGChar(), but not in a function */
	sv_utf8_upgrade (ST(3));
	signal_name = (const gchar *)SvPV_nolen (ST(3))
;
#line 318 "xs/GtkBindings.xs"
	count = (items - first_argnum);
	if ((count % 2) != 0) {
		croak ("entry_add_signal expects type,value pairs "
		       "(odd number of arguments detected)");
	}
	count /= 2;
	ap = g_new (GtkBindingArg, count);
	for (i = 0; i < count; i += 2) {
		SV *sv_type  = ST(i + first_argnum);
		SV *sv_value = ST(i + first_argnum + 1);
		GType gtype  = gperl_type_from_package(SvPV_nolen(sv_type));

		/* gtype==G_TYPE_NONE if sv_type is not registered; it falls
		 * through to the "default:" error
		 */
		switch (G_TYPE_FUNDAMENTAL (gtype)) {
		case G_TYPE_LONG:
			ap[i].d.long_data = SvIV(sv_value);
			break;
		case G_TYPE_DOUBLE:
			ap[i].d.double_data = SvNV(sv_value);
			break;
		case G_TYPE_STRING:
			/* GTK_TYPE_IDENTIFIER comes through here, but
			 * believe that's only a hangover from gtk 1.2 and
			 * needs no special attention.
			 */
			/* gtk copies the string */
			ap[i].d.string_data = SvPV_nolen(sv_value);
			break;

		/* helpers converting to the three basic types ... */
		case G_TYPE_ENUM:
			/* coerce enum to long */
			ap[i].d.long_data = gperl_convert_enum(gtype,sv_value);
			gtype = G_TYPE_LONG;
			break;
		case G_TYPE_FLAGS:
			/* coerce flags to long */
			ap[i].d.long_data = gperl_convert_flags(gtype,sv_value);
			gtype = G_TYPE_LONG;
			break;

		default:
			g_slist_free (binding_args);
			g_free (ap);
			croak ("Unrecognised argument type '%s'",
				SvPV_nolen(sv_type));
		}
		ap[i].arg_type = gtype;
		binding_args = g_slist_append (binding_args, &(ap[i]));
	}
	gtk_binding_entry_add_signall (binding_set, keyval, modifiers,
				       signal_name, binding_args);
	g_slist_free (binding_args);
	g_free (ap);
#line 413 "xs/GtkBindings.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Gtk2__BindingSet_entry_remove); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gtk2__BindingSet_entry_remove)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "binding_set, keyval, modifiers");
    {
	GtkBindingSet *	binding_set = SvGtkBindingSet (ST(0))
;
	guint	keyval = (guint)SvUV(ST(1))
;
	GdkModifierType	modifiers = SvGdkModifierType (ST(2))
;
#line 384 "xs/GtkBindings.xs"
	gtk_binding_entry_remove (binding_set, keyval, modifiers);
#line 434 "xs/GtkBindings.c"
    }
    XSRETURN_EMPTY;
}

#if GTK_CHECK_VERSION (2, 12, 0)
#define XSubPPtmpAAAA 1


XS_EUPXS(XS_Gtk2__BindingSet_entry_skip); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gtk2__BindingSet_entry_skip)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "binding_set, keyval, modifiers");
    {
	GtkBindingSet *	binding_set = SvGtkBindingSet (ST(0))
;
	guint	keyval = (guint)SvUV(ST(1))
;
	GdkModifierType	modifiers = SvGdkModifierType (ST(2))
;
#line 397 "xs/GtkBindings.xs"
	gtk_binding_entry_skip (binding_set, keyval, modifiers);
#line 458 "xs/GtkBindings.c"
    }
    XSRETURN_EMPTY;
}

#endif

XS_EUPXS(XS_Gtk2__Object_bindings_activate); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gtk2__Object_bindings_activate)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "object, keyval, modifiers");
    {
	GtkObject *	object = SvGtkObject (ST(0))
;
	guint	keyval = (guint)SvUV(ST(1))
;
	GdkModifierType	modifiers = SvGdkModifierType (ST(2))
;
	gboolean	RETVAL;

	RETVAL = gtk_bindings_activate(object, keyval, modifiers);
	ST(0) = boolSV(RETVAL);
    }
    XSRETURN(1);
}

#if GTK_CHECK_VERSION(2, 4, 0)
#define XSubPPtmpAAAB 1


XS_EUPXS(XS_Gtk2__Object_bindings_activate_event); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gtk2__Object_bindings_activate_event)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "object, event");
    {
	GtkObject *	object = SvGtkObject (ST(0))
;
	GdkEvent *	event = SvGdkEvent (ST(1))
;
#line 431 "xs/GtkBindings.xs"
	GdkEventType type;
#line 503 "xs/GtkBindings.c"
	gboolean	RETVAL;
#line 433 "xs/GtkBindings.xs"
	type = event->type;
	if (type != GDK_KEY_PRESS && type != GDK_KEY_RELEASE)
		croak ("Event must be key-press or key-release");
	RETVAL = gtk_bindings_activate_event (object, (GdkEventKey*) event);
#line 510 "xs/GtkBindings.c"
	ST(0) = boolSV(RETVAL);
    }
    XSRETURN(1);
}

#endif
#ifdef __cplusplus
extern "C"
#endif
XS_EXTERNAL(boot_Gtk2__BindingSet); /* prototype to pass -Wmissing-prototypes */
XS_EXTERNAL(boot_Gtk2__BindingSet)
{
    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::BindingSet::set_name", XS_Gtk2__BindingSet_set_name, file);
        cv = newXS("Gtk2::BindingSet::by_class", XS_Gtk2__BindingSet_new, file);
        XSANY.any_i32 = 2;
        cv = newXS("Gtk2::BindingSet::find", XS_Gtk2__BindingSet_new, file);
        XSANY.any_i32 = 1;
        cv = newXS("Gtk2::BindingSet::new", XS_Gtk2__BindingSet_new, file);
        XSANY.any_i32 = 0;
        newXS("Gtk2::BindingSet::activate", XS_Gtk2__BindingSet_activate, file);
        newXS("Gtk2::BindingSet::add_path", XS_Gtk2__BindingSet_add_path, file);
        newXS("Gtk2::BindingSet::entry_add_signal", XS_Gtk2__BindingSet_entry_add_signal, file);
        newXS("Gtk2::BindingSet::entry_remove", XS_Gtk2__BindingSet_entry_remove, file);
#if XSubPPtmpAAAA
        newXS("Gtk2::BindingSet::entry_skip", XS_Gtk2__BindingSet_entry_skip, file);
#endif
        newXS("Gtk2::Object::bindings_activate", XS_Gtk2__Object_bindings_activate, file);
#if XSubPPtmpAAAB
        newXS("Gtk2::Object::bindings_activate_event", XS_Gtk2__Object_bindings_activate_event, file);
#endif

    /* Initialisation Section */

#if XSubPPtmpAAAA
#endif
#if XSubPPtmpAAAB
#endif
#line 562 "xs/GtkBindings.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;
}

