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

#line 1 "Xlib.xs"
#define PERL_NO_GET_CONTEXT
#include <EXTERN.h>
#include <perl.h>
#include <XSUB.h>
#include "tkGlue.def"

#include "pTk/tkPort.h"
#include "pTk/tkInt.h"
#include "tkGlue.h"
#include "tkGlue.m"
#include "pTk/tkVMacro.h"

DECLARE_VTABLES;

/* A few sample routines to get at Xlib via perl
   Will eventaually be extended to the point where
   simple pTk widgets can be *implemented* in perl

   Main stumbling block is a clean way of filling in
   a GC.

   The XDraw*() functions may be a bit messy, but
   should be okay via CODE: bodies and variable number
   of args and/or passing in array refs
*/

/* Now we have some sneakyness for Benefit of Win32.
 * As we have tkVMacro.h above any function which exists
 * should be #define'd so we can test for existance.
 */

#ifndef XLoadFont
#define XLoadFont(dpy,name) None
#endif

#ifndef XDrawString
#define XDrawString(dpy,win,gc,x,y,string,len)
#endif

static IV
SvGCIVOBJ(pTHX_ char *class,SV *sv)
{
 if (sv_isa(sv, class))
  return SvIV((SV*)SvRV(sv));
 else
  croak("Not of type %s",class);
 return 0;
}

#define SvGCint(x)           SvIV(x)
#define SvGCBool(x)          SvIV(x)
#define SvGCunsigned_long(x) SvIV(x)
#define SvGCPixmap(x)        (Pixmap) SvGCIVOBJ(aTHX_ "Pixmap",x)
#define SvGCFont(x)          (Font)   SvGCIVOBJ(aTHX_ "Font",x)

#define GCField(name,bit,field,func) \
 if (!strcmp(key,name)) {            \
  values->field = func(value);       \
  valuemask |= bit;                  \
 } else

unsigned long
GCSetValue(pTHX_ unsigned long valuemask,
           XGCValues *values,char *key,SV *value)
{
#include "GC.def"
 croak("Setting GC %s not implemented",key);
 return valuemask;
}

static void
tmpLine(tkwin,x1,y1,x2,y2,flags)
Tk_Window tkwin;
int x1,y1,x2,y2;
int flags;
{
 GC gc = None;
 XGCValues values;
 Window root = Tk_WindowId(tkwin);
 unsigned long valuemask = GCForeground | GCBackground
                           | GCSubwindowMode | GCFunction
#if 0
                           | GCLineStyle
#endif
                           ;
 values.line_style     = LineDoubleDash;

 if (flags & 4)
  {
   Window child;
   root = XRootWindow(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
   XTranslateCoordinates(Tk_Display(tkwin),Tk_WindowId(tkwin),root,
                         x1, y1, &x1, &y1, &child);
   XTranslateCoordinates(Tk_Display(tkwin),Tk_WindowId(tkwin),root,
                         x2, y2, &x2, &y2, &child);
   values.subwindow_mode = IncludeInferiors;
  }
 else
  {
   values.subwindow_mode = ClipByChildren;
  }

 if (flags & 2)
  {
   values.background     = 0x0a;
   values.foreground     = 0x05;
   values.function       = GXxor;
  }
 else
  {
   values.function       = GXcopy;
   if (flags & 1)
    {
     values.foreground     = BlackPixelOfScreen(Tk_Screen(tkwin));
     values.background     = WhitePixelOfScreen(Tk_Screen(tkwin));
    }
   else
    {
     values.background     = BlackPixelOfScreen(Tk_Screen(tkwin));
     values.foreground     = WhitePixelOfScreen(Tk_Screen(tkwin));
    }
  }
 gc = Tk_GetGC(tkwin, valuemask, &values);
 if (gc != None)
  {
   XDrawLine(Tk_Display(tkwin), root, gc, x1, y1, x2, y2);
   Tk_FreeGC(Tk_Display(tkwin),gc);
  }
 else
  croak("Cannot get graphic context");
}

#if defined(WIN32) || defined(__WIN32__) || defined(__PM__)
/* wrap the naive macro versions of these ... */
static int
pTk_XSync(Display *dpy, int flush)
{
 XSync(dpy,flush);
 return 0;
}

static int
pTk_XFlush(Display *dpy)
{
 XFlush(dpy);
 return 0;
}
#else
#define pTk_XSync  XSync
#define pTk_XFlush XFlush
#endif /* WIN32 or friends */



#line 165 "Xlib.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 309 "Xlib.c"

XS_EUPXS(XS_Tk__Widget_tmpLine); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Tk__Widget_tmpLine)
{
    dVAR; dXSARGS;
    if (items < 5 || items > 6)
       croak_xs_usage(cv,  "win, x1, y1, x2, y2, onroot = 0");
    {
	Tk_Window	win = SVtoWindow(ST(0))
;
	int	x1 = (int)SvIV(ST(1))
;
	int	y1 = (int)SvIV(ST(2))
;
	int	x2 = (int)SvIV(ST(3))
;
	int	y2 = (int)SvIV(ST(4))
;
	int	onroot;

	if (items < 6)
	    onroot = 0;
	else {
	    onroot = (int)SvIV(ST(5))
;
	}

	tmpLine(win, x1, y1, x2, y2, onroot);
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_ScreenPtr_WidthOfScreen); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_ScreenPtr_WidthOfScreen)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "s");
    {
	Screen *	s;
	int	RETVAL;
	dXSTARG;

	if (sv_isa(ST(0), "ScreenPtr")) {
	    s = INT2PTR(Screen *, SvIV(SvRV(ST(0))));
	}
	else {
	    s = (Screen *) NULL;
	    croak("s is not of type ScreenPtr");
	}
;

	RETVAL = WidthOfScreen(s);
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_ScreenPtr_WidthMMOfScreen); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_ScreenPtr_WidthMMOfScreen)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "s");
    {
	Screen *	s;
	int	RETVAL;
	dXSTARG;

	if (sv_isa(ST(0), "ScreenPtr")) {
	    s = INT2PTR(Screen *, SvIV(SvRV(ST(0))));
	}
	else {
	    s = (Screen *) NULL;
	    croak("s is not of type ScreenPtr");
	}
;

	RETVAL = WidthMMOfScreen(s);
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_ScreenPtr_HeightOfScreen); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_ScreenPtr_HeightOfScreen)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "s");
    {
	Screen *	s;
	int	RETVAL;
	dXSTARG;

	if (sv_isa(ST(0), "ScreenPtr")) {
	    s = INT2PTR(Screen *, SvIV(SvRV(ST(0))));
	}
	else {
	    s = (Screen *) NULL;
	    croak("s is not of type ScreenPtr");
	}
;

	RETVAL = HeightOfScreen(s);
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_ScreenPtr_HeightMMOfScreen); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_ScreenPtr_HeightMMOfScreen)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "s");
    {
	Screen *	s;
	int	RETVAL;
	dXSTARG;

	if (sv_isa(ST(0), "ScreenPtr")) {
	    s = INT2PTR(Screen *, SvIV(SvRV(ST(0))));
	}
	else {
	    s = (Screen *) NULL;
	    croak("s is not of type ScreenPtr");
	}
;

	RETVAL = HeightMMOfScreen(s);
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_ScreenPtr_DefaultGCOfScreen); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_ScreenPtr_DefaultGCOfScreen)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "s");
    {
	Screen *	s;
	GC	RETVAL;

	if (sv_isa(ST(0), "ScreenPtr")) {
	    s = INT2PTR(Screen *, SvIV(SvRV(ST(0))));
	}
	else {
	    s = (Screen *) NULL;
	    croak("s is not of type ScreenPtr");
	}
;

	RETVAL = DefaultGCOfScreen(s);
	{
	    SV * RETVALSV;
	    RETVALSV = sv_newmortal();
	    sv_setref_iv(RETVALSV, "GC", PTR2IV(RETVAL));
	    ST(0) = RETVALSV;
	}
    }
    XSRETURN(1);
}


XS_EUPXS(XS_ScreenPtr_BlackPixelOfScreen); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_ScreenPtr_BlackPixelOfScreen)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "s");
    {
	Screen *	s;
	unsigned long	RETVAL;
	dXSTARG;

	if (sv_isa(ST(0), "ScreenPtr")) {
	    s = INT2PTR(Screen *, SvIV(SvRV(ST(0))));
	}
	else {
	    s = (Screen *) NULL;
	    croak("s is not of type ScreenPtr");
	}
;

	RETVAL = BlackPixelOfScreen(s);
	XSprePUSH; PUSHu((UV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_ScreenPtr_WhitePixelOfScreen); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_ScreenPtr_WhitePixelOfScreen)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "s");
    {
	Screen *	s;
	unsigned long	RETVAL;
	dXSTARG;

	if (sv_isa(ST(0), "ScreenPtr")) {
	    s = INT2PTR(Screen *, SvIV(SvRV(ST(0))));
	}
	else {
	    s = (Screen *) NULL;
	    croak("s is not of type ScreenPtr");
	}
;

	RETVAL = WhitePixelOfScreen(s);
	XSprePUSH; PUSHu((UV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_DisplayPtr_XSync); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_DisplayPtr_XSync)
{
    dVAR; dXSARGS;
    if (items < 1 || items > 2)
       croak_xs_usage(cv,  "dpy, discard = False");
    {
	Display *	dpy;
	int	discard;
	int	RETVAL;
	dXSTARG;

	if (sv_isa(ST(0), "DisplayPtr")) {
	    dpy = INT2PTR(Display *, SvIV(SvRV(ST(0))));
	}
	else {
	    dpy = (Display *) NULL;
	    croak("dpy is not of type DisplayPtr");
	}
;

	if (items < 2)
	    discard = False;
	else {
	    discard = (int)SvIV(ST(1))
;
	}

	RETVAL = pTk_XSync(dpy, discard);
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_DisplayPtr_XFlush); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_DisplayPtr_XFlush)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "dpy");
    {
	Display *	dpy;
	int	RETVAL;
	dXSTARG;

	if (sv_isa(ST(0), "DisplayPtr")) {
	    dpy = INT2PTR(Display *, SvIV(SvRV(ST(0))));
	}
	else {
	    dpy = (Display *) NULL;
	    croak("dpy is not of type DisplayPtr");
	}
;

	RETVAL = pTk_XFlush(dpy);
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_DisplayPtr_ConnectionNumber); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_DisplayPtr_ConnectionNumber)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "dpy");
    {
	Display *	dpy;
	int	RETVAL;
	dXSTARG;

	if (sv_isa(ST(0), "DisplayPtr")) {
	    dpy = INT2PTR(Display *, SvIV(SvRV(ST(0))));
	}
	else {
	    dpy = (Display *) NULL;
	    croak("dpy is not of type DisplayPtr");
	}
;

	RETVAL = ConnectionNumber(dpy);
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_DisplayPtr_XLoadFont); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_DisplayPtr_XLoadFont)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "dpy, name");
    {
	Display *	dpy;
	char *	name = (char *)SvPV_nolen(ST(1))
;
	Font	RETVAL;

	if (sv_isa(ST(0), "DisplayPtr")) {
	    dpy = INT2PTR(Display *, SvIV(SvRV(ST(0))));
	}
	else {
	    dpy = (Display *) NULL;
	    croak("dpy is not of type DisplayPtr");
	}
;

	RETVAL = XLoadFont(dpy, name);
	{
	    SV * RETVALSV;
	    RETVALSV = sv_newmortal();
	    sv_setref_iv(RETVALSV, "Font", PTR2IV(RETVAL));
	    ST(0) = RETVALSV;
	}
    }
    XSRETURN(1);
}


XS_EUPXS(XS_DisplayPtr_XListFonts); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_DisplayPtr_XListFonts)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "dpy, pattern, max");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	Display *	dpy;
	char *	pattern = (char *)SvPV_nolen(ST(1))
;
	int	max = (int)SvIV(ST(2))
;

	if (sv_isa(ST(0), "DisplayPtr")) {
	    dpy = INT2PTR(Display *, SvIV(SvRV(ST(0))));
	}
	else {
	    dpy = (Display *) NULL;
	    croak("dpy is not of type DisplayPtr");
	}
;
#line 225 "Xlib.xs"
 {
  int  count = 0;
#if !defined(__WIN32__) && !defined(__PM__)
  char **list = XListFonts(dpy, pattern, max, &count);
  int i;
  EXTEND(sp, count);
  for (i=0; i < count; i++)
   {
    PUSHs(sv_2mortal(newSVpv(list[i],0)));
   }
  XFreeFontNames(list);
#endif
  XSRETURN(count);
 }
#line 696 "Xlib.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_DisplayPtr_XDrawLine); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_DisplayPtr_XDrawLine)
{
    dVAR; dXSARGS;
    if (items != 7)
       croak_xs_usage(cv,  "dpy, win, gc, x1, y1, x2, y2");
    {
	Display *	dpy;
	Window	win;
	GC	gc;
	int	x1 = (int)SvIV(ST(3))
;
	int	y1 = (int)SvIV(ST(4))
;
	int	x2 = (int)SvIV(ST(5))
;
	int	y2 = (int)SvIV(ST(6))
;

	if (sv_isa(ST(0), "DisplayPtr")) {
	    dpy = INT2PTR(Display *, SvIV(SvRV(ST(0))));
	}
	else {
	    dpy = (Display *) NULL;
	    croak("dpy is not of type DisplayPtr");
	}
;

	if (sv_isa(ST(1), "Window")) {
	    win = INT2PTR(Window, SvIV(SvRV(ST(1))));
	}
	else {
	    win = (Window) NULL;
	    croak("win is not of type Window");
	}
;

	if (sv_isa(ST(2), "GC")) {
	    gc = INT2PTR(GC, SvIV(SvRV(ST(2))));
	}
	else {
	    gc = (GC) NULL;
	    croak("gc is not of type GC");
	}
;

	XDrawLine(dpy, win, gc, x1, y1, x2, y2);
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_DisplayPtr_XDrawRectangle); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_DisplayPtr_XDrawRectangle)
{
    dVAR; dXSARGS;
    if (items != 7)
       croak_xs_usage(cv,  "dpy, win, gc, x, y, width, height");
    {
	Display *	dpy;
	Window	win;
	GC	gc;
	int	x = (int)SvIV(ST(3))
;
	int	y = (int)SvIV(ST(4))
;
	int	width = (int)SvIV(ST(5))
;
	int	height = (int)SvIV(ST(6))
;

	if (sv_isa(ST(0), "DisplayPtr")) {
	    dpy = INT2PTR(Display *, SvIV(SvRV(ST(0))));
	}
	else {
	    dpy = (Display *) NULL;
	    croak("dpy is not of type DisplayPtr");
	}
;

	if (sv_isa(ST(1), "Window")) {
	    win = INT2PTR(Window, SvIV(SvRV(ST(1))));
	}
	else {
	    win = (Window) NULL;
	    croak("win is not of type Window");
	}
;

	if (sv_isa(ST(2), "GC")) {
	    gc = INT2PTR(GC, SvIV(SvRV(ST(2))));
	}
	else {
	    gc = (GC) NULL;
	    croak("gc is not of type GC");
	}
;

	XDrawRectangle(dpy, win, gc, x, y, width, height);
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_DisplayPtr_XDrawString); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_DisplayPtr_XDrawString)
{
    dVAR; dXSARGS;
    if (items != 6)
       croak_xs_usage(cv,  "dpy, win, gc, x, y, string");
    {
	Display *	dpy;
	Window	win;
	GC	gc;
	int	x = (int)SvIV(ST(3))
;
	int	y = (int)SvIV(ST(4))
;
	SV *	string = ST(5)
;

	if (sv_isa(ST(0), "DisplayPtr")) {
	    dpy = INT2PTR(Display *, SvIV(SvRV(ST(0))));
	}
	else {
	    dpy = (Display *) NULL;
	    croak("dpy is not of type DisplayPtr");
	}
;

	if (sv_isa(ST(1), "Window")) {
	    win = INT2PTR(Window, SvIV(SvRV(ST(1))));
	}
	else {
	    win = (Window) NULL;
	    croak("win is not of type Window");
	}
;

	if (sv_isa(ST(2), "GC")) {
	    gc = INT2PTR(GC, SvIV(SvRV(ST(2))));
	}
	else {
	    gc = (GC) NULL;
	    croak("gc is not of type GC");
	}
;
#line 269 "Xlib.xs"
 {
  if (SvOK(string))
   {STRLEN len;
    char *s = SvPV(string,len);
    if (s && len)
     {
      XDrawString(dpy,win,gc,x,y,s,len);
     }
   }
 }
#line 861 "Xlib.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_DisplayPtr_RootWindow); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_DisplayPtr_RootWindow)
{
    dVAR; dXSARGS;
    if (items < 1 || items > 2)
       croak_xs_usage(cv,  "dpy, scr = DefaultScreen(dpy)");
    {
	Display *	dpy;
	int	scr;
	Window	RETVAL;

	if (sv_isa(ST(0), "DisplayPtr")) {
	    dpy = INT2PTR(Display *, SvIV(SvRV(ST(0))));
	}
	else {
	    dpy = (Display *) NULL;
	    croak("dpy is not of type DisplayPtr");
	}
;

	if (items < 2)
	    scr = DefaultScreen(dpy);
	else {
	    scr = (int)SvIV(ST(1))
;
	}

	RETVAL = RootWindow(dpy, scr);
	{
	    SV * RETVALSV;
	    RETVALSV = sv_newmortal();
	    sv_setref_iv(RETVALSV, "Window", PTR2IV(RETVAL));
	    ST(0) = RETVALSV;
	}
    }
    XSRETURN(1);
}


XS_EUPXS(XS_DisplayPtr_DisplayString); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_DisplayPtr_DisplayString)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "dpy");
    {
	Display *	dpy;
	char *	RETVAL;
	dXSTARG;

	if (sv_isa(ST(0), "DisplayPtr")) {
	    dpy = INT2PTR(Display *, SvIV(SvRV(ST(0))));
	}
	else {
	    dpy = (Display *) NULL;
	    croak("dpy is not of type DisplayPtr");
	}
;

	RETVAL = DisplayString(dpy);
	sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG;
    }
    XSRETURN(1);
}


XS_EUPXS(XS_DisplayPtr_DefaultScreen); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_DisplayPtr_DefaultScreen)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "dpy");
    {
	Display *	dpy;
	int	RETVAL;
	dXSTARG;

	if (sv_isa(ST(0), "DisplayPtr")) {
	    dpy = INT2PTR(Display *, SvIV(SvRV(ST(0))));
	}
	else {
	    dpy = (Display *) NULL;
	    croak("dpy is not of type DisplayPtr");
	}
;

	RETVAL = DefaultScreen(dpy);
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_DisplayPtr_ScreenOfDisplay); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_DisplayPtr_ScreenOfDisplay)
{
    dVAR; dXSARGS;
    if (items < 1 || items > 2)
       croak_xs_usage(cv,  "dpy, scr = DefaultScreen(dpy)");
    {
	Display *	dpy;
	int	scr;
	Screen *	RETVAL;

	if (sv_isa(ST(0), "DisplayPtr")) {
	    dpy = INT2PTR(Display *, SvIV(SvRV(ST(0))));
	}
	else {
	    dpy = (Display *) NULL;
	    croak("dpy is not of type DisplayPtr");
	}
;

	if (items < 2)
	    scr = DefaultScreen(dpy);
	else {
	    scr = (int)SvIV(ST(1))
;
	}

	RETVAL = ScreenOfDisplay(dpy, scr);
	{
	    SV * RETVALSV;
	    RETVALSV = sv_newmortal();
	    sv_setref_iv(RETVALSV, "ScreenPtr", PTR2IV(RETVAL));
	    ST(0) = RETVALSV;
	}
    }
    XSRETURN(1);
}


XS_EUPXS(XS_DisplayPtr_DefaultGC); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_DisplayPtr_DefaultGC)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "dpy, scr");
    {
	Display *	dpy;
	int	scr = (int)SvIV(ST(1))
;
	GC	RETVAL;

	if (sv_isa(ST(0), "DisplayPtr")) {
	    dpy = INT2PTR(Display *, SvIV(SvRV(ST(0))));
	}
	else {
	    dpy = (Display *) NULL;
	    croak("dpy is not of type DisplayPtr");
	}
;

	RETVAL = DefaultGC(dpy, scr);
	{
	    SV * RETVALSV;
	    RETVALSV = sv_newmortal();
	    sv_setref_iv(RETVALSV, "GC", PTR2IV(RETVAL));
	    ST(0) = RETVALSV;
	}
    }
    XSRETURN(1);
}


XS_EUPXS(XS_DisplayPtr_XQueryTree); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_DisplayPtr_XQueryTree)
{
    dVAR; dXSARGS;
    if (items < 2 || items > 4)
       croak_xs_usage(cv,  "dpy, w, root = NULL, parent = NULL");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	Display *	dpy;
	Window	w;
	SV *	root;
	SV *	parent;

	if (sv_isa(ST(0), "DisplayPtr")) {
	    dpy = INT2PTR(Display *, SvIV(SvRV(ST(0))));
	}
	else {
	    dpy = (Display *) NULL;
	    croak("dpy is not of type DisplayPtr");
	}
;

	if (sv_isa(ST(1), "Window")) {
	    w = INT2PTR(Window, SvIV(SvRV(ST(1))));
	}
	else {
	    w = (Window) NULL;
	    croak("w is not of type Window");
	}
;

	if (items < 3)
	    root = NULL;
	else {
	    root = ST(2)
;
	}

	if (items < 4)
	    parent = NULL;
	else {
	    parent = ST(3)
;
	}
#line 310 "Xlib.xs"
 {Window *children = NULL;
  unsigned int count = 0;
  Window pw = None;
  Window rw = None;
  if (XQueryTree(dpy, w, &rw, &pw, &children, &count))
   {
    unsigned int i;
    for (i=0; i < count; i++)
     {
      SV *sv = sv_newmortal();
      sv_setref_iv(sv, "Window", (IV) (children[i]));
      XPUSHs(sv);
     }
    XFree((char *) children);
   }
  else
   {
    count = 0;
    XSRETURN(0);
   }
  if (parent)
   {
    if (pw == None)
     sv_setsv(parent,&PL_sv_undef);
    else
     sv_setref_iv(parent, "Window", (IV) (pw));
   }
  if (root)
   {
    if (rw == None)
     sv_setsv(root,&PL_sv_undef);
    else
     sv_setref_iv(root, "Window", (IV) (rw));
   }
  XSRETURN(count);
 }
#line 1114 "Xlib.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_GC_new); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_GC_new)
{
    dVAR; dXSARGS;
    if (items < 3)
       croak_xs_usage(cv,  "CLASS, dpy, win, ...");
    {
	Display *	dpy;
	Window	win;
	char *	CLASS = (char *)SvPV_nolen(ST(0))
;
	GC	RETVAL;

	if (sv_isa(ST(1), "DisplayPtr")) {
	    dpy = INT2PTR(Display *, SvIV(SvRV(ST(1))));
	}
	else {
	    dpy = (Display *) NULL;
	    croak("dpy is not of type DisplayPtr");
	}
;

	if (sv_isa(ST(2), "Window")) {
	    win = INT2PTR(Window, SvIV(SvRV(ST(2))));
	}
	else {
	    win = (Window) NULL;
	    croak("win is not of type Window");
	}
;
#line 354 "Xlib.xs"
  {unsigned long valuemask = 0;
   XGCValues values;
   STRLEN na;
   int i;
   for (i=3; i < items; i += 2)
    {char *key = SvPV(ST(i),na);
     if (i+1 < items)
      valuemask = GCSetValue(aTHX_ valuemask,&values,key,ST(i+1));
     else
      croak("No value for %s",key);
    }
   RETVAL = XCreateGC(dpy,win,valuemask,&values);
  }
#line 1165 "Xlib.c"
	{
	    SV * RETVALSV;
	    RETVALSV = sv_newmortal();
	    sv_setref_iv(RETVALSV, "GC", PTR2IV(RETVAL));
	    ST(0) = RETVALSV;
	}
    }
    XSRETURN(1);
}


XS_EUPXS(XS_GC_Foreground); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_GC_Foreground)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "dpy, gc, val");
    {
	Display *	dpy;
	GC	gc;
	unsigned long	val = (unsigned long)SvUV(ST(2))
;

	if (sv_isa(ST(0), "DisplayPtr")) {
	    dpy = INT2PTR(Display *, SvIV(SvRV(ST(0))));
	}
	else {
	    dpy = (Display *) NULL;
	    croak("dpy is not of type DisplayPtr");
	}
;

	if (sv_isa(ST(1), "GC")) {
	    gc = INT2PTR(GC, SvIV(SvRV(ST(1))));
	}
	else {
	    gc = (GC) NULL;
	    croak("gc is not of type GC");
	}
;

	XSetForeground(dpy, gc, val);
    }
    XSRETURN_EMPTY;
}

#ifdef __cplusplus
extern "C"
#endif
XS_EXTERNAL(boot_Tk__Xlib); /* prototype to pass -Wmissing-prototypes */
XS_EXTERNAL(boot_Tk__Xlib)
{
#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("Tk::Widget::tmpLine", XS_Tk__Widget_tmpLine);
        newXS_deffile("ScreenPtr::WidthOfScreen", XS_ScreenPtr_WidthOfScreen);
        newXS_deffile("ScreenPtr::WidthMMOfScreen", XS_ScreenPtr_WidthMMOfScreen);
        newXS_deffile("ScreenPtr::HeightOfScreen", XS_ScreenPtr_HeightOfScreen);
        newXS_deffile("ScreenPtr::HeightMMOfScreen", XS_ScreenPtr_HeightMMOfScreen);
        newXS_deffile("ScreenPtr::DefaultGCOfScreen", XS_ScreenPtr_DefaultGCOfScreen);
        newXS_deffile("ScreenPtr::BlackPixelOfScreen", XS_ScreenPtr_BlackPixelOfScreen);
        newXS_deffile("ScreenPtr::WhitePixelOfScreen", XS_ScreenPtr_WhitePixelOfScreen);
        newXS_deffile("DisplayPtr::XSync", XS_DisplayPtr_XSync);
        newXS_deffile("DisplayPtr::XFlush", XS_DisplayPtr_XFlush);
        newXS_deffile("DisplayPtr::ConnectionNumber", XS_DisplayPtr_ConnectionNumber);
        newXS_deffile("DisplayPtr::XLoadFont", XS_DisplayPtr_XLoadFont);
        newXS_deffile("DisplayPtr::XListFonts", XS_DisplayPtr_XListFonts);
        newXS_deffile("DisplayPtr::XDrawLine", XS_DisplayPtr_XDrawLine);
        newXS_deffile("DisplayPtr::XDrawRectangle", XS_DisplayPtr_XDrawRectangle);
        newXS_deffile("DisplayPtr::XDrawString", XS_DisplayPtr_XDrawString);
        newXS_deffile("DisplayPtr::RootWindow", XS_DisplayPtr_RootWindow);
        newXS_deffile("DisplayPtr::DisplayString", XS_DisplayPtr_DisplayString);
        newXS_deffile("DisplayPtr::DefaultScreen", XS_DisplayPtr_DefaultScreen);
        newXS_deffile("DisplayPtr::ScreenOfDisplay", XS_DisplayPtr_ScreenOfDisplay);
        newXS_deffile("DisplayPtr::DefaultGC", XS_DisplayPtr_DefaultGC);
        newXS_deffile("DisplayPtr::XQueryTree", XS_DisplayPtr_XQueryTree);
        newXS_deffile("GC::new", XS_GC_new);
        newXS_deffile("GC::Foreground", XS_GC_Foreground);

    /* Initialisation Section */

#line 377 "Xlib.xs"
 {
  IMPORT_VTABLES;
 }

#line 1272 "Xlib.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
}

