/* Definitions for SGI widget extensions */

#ifndef _SgiP_h
#define _SgiP_h

#ifdef __cplusplus
extern "C" {
#endif

#ifdef XM_LIBRARY_BUILD /* SGI upgrade for 64-bits */
/*
 * strlen() -- Xm strings are never more than 32 bits, so this definition
 *      does not hurt.  It does prevent "implicit conversion from "unsigned
 *      long" to ..." warnings.
 *
 * sizeof() -- Ditto for "sizeof".
 *
 * XtMalloc() -- We have no need to XtMalloc more than 32 bits worth.
 *
 * Doing this sort of thing is a really ugly kludge to get rid of a lot
 * of compiler warnings in just this one place.  The real problem is that
 * XtMalloc & friends are busted -- they should take size_t sizes, justg as
 * underlying routines they wrap do.  Once that happens, these defines
 * should be removed.  Also those in the Mrm and uil directories.
 */
#  define strlen(s) ((unsigned int)strlen(s))
#  define sizeof(s) ((unsigned int)sizeof(s))
#  define XtMalloc(s) (XtMalloc((Cardinal)(s)))
#  define XtCalloc(n,s) (XtCalloc((n),(Cardinal)(s)))
#  define XtRealloc(p,n) (XtRealloc((p),(Cardinal)(n)))

/*
 * Motif has a number of implicit conversions that risk losing data.
 * Probably the most troublesome are long-to-int type conversions, because
 * in a 64 bit (but not a 32-bit) environment the upper 32 bits are thrown
 * away.  This creates a bug that will work OK on a little-endian machine,
 * but fail on a MIPS machine.  We have really found such a bug in libMrm,
 * and there is other code where it would be very difficult to check by
 * hand whether that could ever occur.  Therefore, we make a ASSERT to
 * catch such stuff.
 *
 * This assertion will pass all good data.  It will fail to catch some bad
 * data.  Probably close enough for catching porting mistakes, though.
 */
#  if (_MIPS_SZLONG == 64)
#    include <assert.h>
#    define SGI_ASSERT_NO_TRUNC(val) assert( (((val) & 0xFFFFFFFF00000000) == 0) || (((val) & 0xFFFFFFFF00000000) == 0xFFFFFFFF00000000) )
#  else
#    define SGI_ASSERT_NO_TRUNC(val)
#  endif /* _MIPS_SZLONG */

#endif /* XM_LIBRARY_BUILD */
		
/* Global Variables declared */
extern int sgIsWindowManager;		/* Only set by mwm */
extern int SGImode;	/* So it is resolved for apps linked with libChow */
/* unique contexts used for reference counting in _SG_XtSetValues(): */
extern XContext SGIrefCntContext;	/* context for the reference count */
extern XContext SGIsetValuesFcnContext;	/* context for the saved fcn */

/*
 * SGI has added a vendor extension pointer to all widget class and instance
 * records.  That helps to preserve compatible shared libraries and widget
 * subclasses.
 *
 * The following is an SGI class extension record.  Any class that needs
 * one will have one.  The record supports automatic intialization of SGI
 * sub-resources.  Therefore, it is the same for all widgets.
 *
 * The instance extension record is specific to each widget that needs one,
 * so it is declared in corresponding the <Widget>P.h file.
 */

#define _SgExtensionRecVersion	1L
typedef struct _sgClassExtensionRec {
	long        version;	/* Version, for future compatibility control */
	Cardinal    isize;	/* Size of the instance extension record */
	XtResource *rsrc_ptr;	/* Ptr to the resources data definition */
	int	    rsrc_num;	/* Number of resources */
} _SgClassExtensionRec, *_SgClassExtension;

#define _SgInstanceExtensionRecVersion	1L
typedef struct _sgInstanceExtensionRec {
	long	    version;	/* Version, for future compatibility control */
	/* OK to add extra fields as they become necessary. */
	/* Instance resource data starts here, after the common fields. */
} _SgInstanceExtensionRec, *_SgInstanceExtension;


/*******************************************************************************
 *
 * Definitions for the SGI "shader" -- i.e. picking different shades of the
 * same color to get SGI-standard visual effects.
 */

typedef struct _shader {
    Display *dpy;
    Colormap cmap;
    Cardinal depth;
    Pixel    pixel;
    short    r,g,b;
    int      faceShade; /* point along the shade line where bkg color falls */
    GC       GCarray[9]; /* GCs for different shades of the base color*/
    struct _shader* next;
}*shaderptr;

/* indices to access GCs from a shader */
#  define tuShader_darkest   0
#  define tuShader_veryDark  1
#  define tuShader_dark      2
#  define tuShader_medium    3
#  define tuShader_light     4
#  define tuShader_veryLight 5
#  define tuShader_lightest  6
#  define tuShader_white     7

/* definitions for brighter and darker to be used for _sgAllocClosestColor */
#  define _SG_ANY_BRIGHTNESS	 0
#  define _SG_BRIGHTER		 1
#  define _SG_DARKER		-1


/********    Function Declarations Used From Widgets    ********/
#ifdef _NO_PROTO

    extern XtPointer _SG_GetResourcePtr()	;
    extern GC _sgFindGC()			;
    extern void _sgFindShader()			;
    Status _sgAllocClosestColor()	;

#else

    extern XtPointer _SG_GetResourcePtr(
			Widget       w		,
			WidgetClass  wc)	;
    extern GC _sgFindGC(Widget w, shaderptr shader1,int index);
    extern void _sgFindShader(Widget w, shaderptr* return_adr,Pixel p);
    Status _sgAllocClosestColor(Display *display, Screen *screen, Colormap cmap, XColor *cdef, int direction, XColor *cantbe);

#endif /* _NO_PROTO */
/********    End Function Declarations Used From Widgets    ********/



/********    Private Function Declarations    ********/
#ifdef _NO_PROTO

    extern void    _SG_ClassPartInitialize()	;
    extern void    _SG_XtInitialize()           ;
    extern void    _SG_XtDestroyPrehook()	;
    extern void    _SG_XtDestroyPosthook()	;
    extern void    _SG_XtGetValuesHook()	;
    extern Boolean _SG_XtSetValues()		;
    extern int     _XmBrightness() 		; /* Sgi made this visible */

#else

    extern void _SG_ClassPartInitialize(void)	;

    extern void _SG_XtInitialize(
        		Widget       req	,
        		Widget       new_w	,
        		ArgList      args	,
        		Cardinal    *num_args)	;

    extern void _SG_XtDestroyPrehook(
			Widget       w)		;

    extern void _SG_XtDestroyPosthook(
			Widget       w)		;

    extern void _SG_XtGetValuesHook(
			Widget       new_w	,
			ArgList      args	,
			Cardinal    *num_args)	;

    extern Boolean _SG_XtSetValues(
			Widget       current	,
			Widget       req	,
			Widget       new_w	,
			ArgList      args	,
			Cardinal    *num_args)	;
    extern int _XmBrightness(			/* Sgi made this visible */
			XColor	    *color)	;

#endif /* _NO_PROTO */
/********    End Private Function Declarations    ********/


#if 0
/*
 * The following declare NOP routines are for libXm, so that Chow-ized
 * code can be linked with libXm.  The expectation is that the code will
 * never call these routines at run time.  The actual functions are
 * declared in Sgi.c.
 */
#if !(defined sgiLibChow && sgiLibChow)
#ifdef _NO_PROTO
extern void __SGI_RenderShadows();
#else

extern void _SGI_RenderShadows(Widget w ,Display* dpy,Drawable d,
                               shaderptr shader,Position x, Position y,
                               Dimension width,Dimension height,
                               int* state_array,
                               int shadow_thickness,
                               unsigned int shadow_style);

#endif  /* _NO_PROTO */
#endif  /* !(defined sgiLibChow && sgiLibChow) */
#endif  /* 0 */


/* This was called _XmOSGetQualifiedDir() in Motif 1.2.
 * Renaming it to emphasize SGI-added feature.  It is used
 * by SgFSB.c
 */
extern String _SgOSGetQualifiedDir(String dirSpec);

/* same as XmeGetDefaultRenderTable, except returns new fontList
 * instead of (not thread safe) pointer to static memory
 * caller must free the fontList!!!
 * code is in ResConvert.c
 */
extern XmFontList
_SgXmeGetDefaultRenderTable(
        Widget w,
#if NeedWidePrototypes
        unsigned int fontListType);
#else
        unsigned char fontListType);
#endif /* NeedWidePrototypes */

#ifdef __cplusplus
}  /* Close scope of 'extern "C"' declaration which encloses file. */
#endif

#endif /* _SgiP_h */
/* DON'T ADD STUFF AFTER THIS #endif */

