/*
* $Header: Intrinsic.h,v 7.51 88/06/08 10:04:33 guarino Exp $
*/

/*
*****************************************************************************
**                                                                          *
**                         COPYRIGHT (c) 1988 BY                            *
**             DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.                *
**	MASSACHUSSETTS INSTITUTE OF TECHNOLOGY, CAMBRIDGE, MASS.	    *
**                         ALL RIGHTS RESERVED                              *
**                                                                          *
**  THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED  *
**  ONLY  IN  ACCORDANCE  WITH  THE  TERMS  OF  SUCH  LICENSE AND WITH THE  *
**  INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR  ANY  OTHER  *
**  COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY  *
**  OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY  *
**  TRANSFERRED.                                                            *
**                                                                          *
**  THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE  WITHOUT  NOTICE  *
**  AND  SHOULD  NOT  BE  CONSTRUED  AS  A COMMITMENT BY DIGITAL EQUIPMENT  *
**  CORPORATION OR MIT.                                                     *
**                                                                          *
**  DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR  RELIABILITY  OF  ITS  *
**  SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.                 *
**                                                                          *
*****************************************************************************
**++
**  FACILITY:
**
**      < to be supplied >
**
**  ABSTRACT:
**
**      < to be supplied >
**
**  ENVIRONMENT:
**
**      < to be supplied >
**
**  MODIFICATION HISTORY:
**
**      < to be supplied >
**
**--
**/
#ifndef _XtIntrinsic_h
#define _XtIntrinsic_h
#ifndef VMS
#include	<X++/Xlib.h>
#include	<X++/Xutil.h>
#include	<X++/Xresource.h>
#include	<sys/types.h>
#else
#include	<decw$include/Xlib.h>
#include	<decw$include/Xutil.h>
#include	<decw$include/Xresource.h>
#include	types
/* MIN and MAX get defined vis <sys/types.h> on Unix */
#define	MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))	
#endif

#ifndef NULL
#define NULL 0
#endif

#ifdef unix
#define externalref extern
#define externaldef(psect)
#else
#define externalref globalref
#define externaldef(psect) globaldef {"psect"} noshare
#endif

#ifndef BOOLEANTYPE
#ifndef FALSE
#define FALSE 0
#define TRUE  1
#endif FALSE
#endif BOOLEANTYPE

#define XtNumber(arr)		((Cardinal) (sizeof(arr) / sizeof(arr[0])))

#ifndef STRINGTYPE
typedef char *String;
#define STRINGTYPE
#endif STRINGTYPE
class WidgetRec;
class ObjectRec;
class RectObjRec;
class WindowObjRec;
class WindowObjClassRec;
class WidgetClassRec;
class CompositeRec;
class XtActionsRec;
class XtEventRec;
class XtBoundAccActionRec;
typedef WidgetRec *Widget;
typedef ObjectRec *Object;
typedef RectObjRec *RectObj;
typedef WindowObjRec *WindowObj;
typedef WindowObjClassRec *WindowObjClass;
typedef WidgetClassRec *WidgetClass;
typedef CompositeRec *CompositeWidget;
typedef XtActionsRec *XtActionList;
typedef XtEventRec *XtEventTable;
typedef XtBoundAccActionRec *XtBoundAccActions;
typedef Widget *WidgetList;
typedef unsigned int   Cardinal;
typedef unsigned short  ShortCard;
#ifndef BOOLEANTYPE
typedef char	Boolean;
#define BOOLEANTYPE
#endif
class XtAppStruct;
typedef XtAppStruct *XtAppContext;
typedef unsigned long	*Opaque;
typedef unsigned long   XtValueMask;
typedef unsigned long   XtIntervalId;
typedef unsigned long   XtInputId;
typedef unsigned long	XtWorkProcId;
typedef unsigned int    XtGeometryMask;
typedef unsigned long   XtGCMask;   /* Mask of values that are used by widget*/
typedef unsigned long   Pixel;	    /* Index into colormap	        */
typedef short		Position;   /* Offset from 0 coordinate	        */
typedef ShortCard	Dimension;  /* Size in pixels		        */

/****************************************************************
 *
 * System Dependent Definitions
 *
 *
 * XtArgVal ought to be a union of caddr_t, char *, long, int *, and proc *
 * but casting to union types is not really supported.
 *
 * So the typedef for XtArgVal should be chosen such that
 *
 *      sizeof (XtArgVal) >=	sizeof(caddr_t)
 *				sizeof(char *)
 *				sizeof(long)
 *				sizeof(int *)
 *				sizeof(proc *)
 *
 * ArgLists rely heavily on the above typedef.
 *
 ****************************************************************/
typedef long XtArgVal;

/***************************************************************
 *
 * Arg lists
 *
 ****************************************************************/

typedef struct {
    String	name;
    XtArgVal	value;
} Arg, *ArgList;

#define XtSetArg(arg, n, d) \
    ( (arg).name = (n), (arg).value = (XtArgVal)(d) )

extern ArgList XtMergeArgLists(ArgList, Cardinal, ArgList, Cardinal);

#ifdef VMS
class vms_time {
     unsigned long low;
     unsigned long high;
};
#endif

typedef unsigned long XtVersionType;

#define XT_VERSION 7
#define XT_REVISION 1
#define XtVersion (XT_VERSION * 1000 + XT_REVISION)
#define XtVersionDontCheck 0

extern void _XtInherit();

typedef void (*XtProc)();

typedef void (*XtWidgetClassProc)(WidgetClass);

typedef void (*XtWidgetProc)(Widget);

typedef Boolean (*XtAcceptFocusProc)(Widget, Time * /* X time */);

typedef void (*XtArgsProc)(Widget, ArgList, Cardinal *);

typedef void (*XtInitProc)(Widget, Widget);

typedef Boolean (*XtSetValuesFunc)(Widget, Widget, Widget);  
/* returns TRUE if redisplay needed */

typedef Boolean (*XtArgsFunc)(Widget, ArgList, Cardinal *);

typedef void (*XtAlmostProc)(
    Widget, Widget,XtWidgetGeometry *,  XtWidgetGeometry *);

typedef void (*XtExposeProc)(Widget, XEvent    *, Region);

typedef void (*XtRealizeProc) (
    Widget, XtValueMask, XSetWindowAttributes *);

typedef void (*XtCreatePopupChildProc)();

typedef XtGeometryResult (*XtGeometryHandler)(
	Widget, XtWidgetGeometry *, XtWidgetGeometry *);

typedef void (*XtStringProc)(Widget, String);

#ifndef R3_INTRINSICS
#define XtMapWidget(widget)	XMapWindow(XtDisplay(widget), XtWindow(widget))
#define XtUnmapWidget(widget)	\
		XUnmapWindow(XtDisplay(widget), XtWindow(widget))
#endif R3_INTRINSICS

#ifdef DEBUG
#define XtCheckSubclass(w, widget_class_ptr, message)	\
	if (!XtIsSubclass((w), (widget_class_ptr))) {	\
	    String params[3];				\
	    Cardinal num_params = 3;			\
	    params[0] = (w)->core.widget_class->core_class.class_name;	     \
	    params[1] = (widget_class_ptr)->core_class.class_name;	     \
	    params[2] = (message);					     \
	    XtErrorMsg("subclassMismatch", "xtCheckSubclass",		     \
		    "XtToolkitError",					     \
		    "Widget class %s found when subclass of %s expected: %s",\
		    params, &num_params);		\
	}
#else
#define XtCheckSubclass(w, widget_class, message)	/* nothing */
#endif

extern void XtCreateWindow (
    Widget, unsigned int, Visual *, Mask , XSetWindowAttributes *);

extern void XtResizeWidget(
    Widget, Dimension, Dimension, Dimension, Dimension);

extern void XtMoveWidget(Widget, Position, Position);

extern void XtConfigureWidget(
    Widget, Position, Position, 
    Dimension, Dimension, Dimension, Dimension);

#ifdef VMS
#include <decw$include/Object.h>
#include <decw$include/RectObj.h>
#include <decw$include/WindowObj.h>
#include <decw$include/Core.h>
#include <decw$include/Composite.h>
#include <decw$include/CompObj.h>
#include <decw$include/Constraint.h>
#include <decw$include/Convert.h>
#include <decw$include/Translate.h>
#include <decw$include/Event.h>
/*#include <decw$include/Callback.h>
#include <decw$include/Event.h>
#include <decw$include/Geometry.h>
#include <decw$include/Popup.h>
#include <decw$include/Create.h>
#include <decw$include/Initialize.h>
#include <decw$include/Resource.h>
#include <decw$include/Error.h>
#include <decw$include/Alloc.h>
#include <decw$include/Work.h>
#include <decw$include/GC.h>*/
#else
#include "xt++/Object.h"
#include "xt++/RectObj.h"
#include "xt++/WindowObj.h"
#include "xt++/Core.h"
#include "xt++/Composite.h"
#include "xt++/CompObj.h"
#include "xt++/Constraint.h"
#include "xt++/Convert.h"
#include "X++/Translate.h"
#include "X++/Event.h"
/*#include "Callback.h"
#include  "Geometry.h"
#include  "Popup.h"
#include  "Create.h"
#include  "Initialize.h"
#include  "Resource.h"
#include  "Error.h"
#include  "Alloc.h"
#include  "Work.h"
#include  "GC.h"*/
#endif

extern Boolean XtIsSubclass (Widget, WindowObjClass);

#define XtIsComposite(widget)       XtIsSubclass(widget, (WidgetClass) compositeWidgetClass)
#define XtIsCompositeObject(widget) XtIsSubclass(widget, (WidgetClass) compositeObjectClass)
#define XtIsWindowObject(widget)    XtIsSubclass(widget, (WidgetClass) windowObjClass)
#define XtIsRectObject(widget)      XtIsSubclass(widget, (WidgetClass) rectObjClass)
#define XtIsConstraint(widget)      XtIsSubclass(widget, (WidgetClass) constraintWidgetClass)
#define XtIsShell(widget)	    XtIsSubclass(widget, (WidgetClass) shellWidgetClass)

extern void XtRealizeWidget (Widget);

extern void XtUnrealizeWidget (Widget);

extern void XtDestroyWidget (Widget);

extern void XtSetSensitive (Widget, Boolean);

extern void XtSetMappedWhenManaged (Widget, Boolean);

extern Widget XtNameToWidget(Widget, String);

extern Widget XtWindowToWidget(Display*, Window);


/*************************************************************
 *
 * Information routines
 *
 ************************************************************/

typedef class XtCallbackRec*    XtCallbackList;

typedef void (*XtCallbackProc)(Widget, caddr_t, caddr_t);

typedef class XtCallbackRec {
    XtCallbackProc  callback;
    caddr_t         closure;
} XtCallbackRec;

extern void XtAddCallback (Widget, String, XtCallbackProc, caddr_t);

extern void XtRemoveCallback (Widget, String, XtCallbackProc, caddr_t);

extern void XtAddCallbacks (Widget, String, XtCallbackList);

extern void XtRemoveCallbacks (Widget, String, XtCallbackList);

extern void XtRemoveAllCallbacks (Widget, String);

extern void XtCallCallbacks (Widget, String, caddr_t);

/* These utilities are here on Leo's request. We should think about them */
/* and decide if they really belong in the intrinsics, or a level above */

/* In particular, this procedure is nasty... */
extern void XtOverrideCallback(); /* widget, callcallback */
    /* Widget           widget; */
    /* String           callback_name; */
    /* XtCallbackProc   callback; */

typedef enum {
        XtCallbackNoList,
        XtCallbackHasNone,
        XtCallbackHasSome
} XtCallbackStatus;

extern XtCallbackStatus XtHasCallbacks(Widget, String);



/****************************************************************
 *
 * Geometry Management
 *
 ****************************************************************/

/* Additions to Xlib geometry requests: ask what would happen, don't do it */
#define XtCWQueryOnly   (1 << 7)

/* Additions to Xlib stack modes: don't change stack order */
#define XtSMDontChange  5


class XtWidgetGeometry {
    XtGeometryMask request_mode;
    Position x, y;
    Dimension width, height, border_width;
    Widget sibling;
    int stack_mode;    /* Above, Below, TopIf, BottomIf, Opposite, DontChange */
};

typedef enum  {
    XtGeometryYes,        /* Request accepted. */
    XtGeometryNo,         /* Request denied. */
    XtGeometryAlmost,     /* Request denied, but willing to take replyBox. */
    XtGeometryDone,       /* Request accepted and done. */
} XtGeometryResult;

extern XtGeometryResult XtMakeGeometryRequest(Widget, XtWidgetGeometry*,
	XtWidgetGeometry*);

extern XtGeometryResult XtMakeResizeRequest (Widget, Dimension, Dimension,
	Dimension*, Dimension*);

extern void XtTransformCoords(Widget,Position,Position,Position*,Position*);
    /* register Widget w;       */
    /* Position x, y;           */
    /* register Position *rootx, *rooty; */

extern XtGeometryResult XtQueryGeometry(Widget, XtWidgetGeometry*, XtWidgetGeometry*);


/* Class record constants */

typedef class PopupClassRec *PopupWidgetClass;

extern WidgetClass popupWidgetClass;

extern Widget XtCreatePopupShell(String, WidgetClass, Widget, ArgList, Cardinal);

typedef enum {XtGrabNone, XtGrabNonexclusive, XtGrabExclusive} XtGrabKind;

extern void XtPopup(Widget, XtGrabKind);

extern void XtCallbackNone(Widget, caddr_t, caddr_t);

extern void XtCallbackNonexclusive(Widget, caddr_t, caddr_t);

extern void XtCallbackExclusive(Widget, caddr_t, caddr_t);

extern void XtPopdown(Widget);

class XtPopdownIDRec {
    Widget  shell_widget;
    Widget  enable_widget;
};
typedef XtPopdownIDRec *XtPopdownID;

extern void XtCallbackPopdown(Widget, caddr_t, caddr_t);


extern Widget XtCreateWidget (String, WidgetClass, Widget, ArgList, Cardinal);

extern Widget XtCreateManagedWidget (String, WidgetClass, Widget, ArgList, Cardinal);

extern Widget XtCreateApplicationShell ();
    /* String       name;	    */
    /* WidgetClass  widget_class;   */
    /* ArgList      args;           */
    /* Cardinal     num_args;       */

extern Widget XtAppCreateShell (String, String, WidgetClass, Display*, ArgList, Cardinal);


/****************************************************************
 *
 * Toolkit initialization
 *
 ****************************************************************/

extern void XtToolkitInitialize();

extern void XtDisplayInitialize(XtAppContext,
				Display*,
				String,
				String,
				XrmOptionDescRec *,
				Cardinal,
				Cardinal*,
				char**);

extern Widget XtInitialize(String, String, XrmOptionDescRec*, Cardinal, Cardinal*, char**);

extern Display *XtOpenDisplay(
    XtAppContext,
    String,
    String,
    String,
    XrmOptionDescRec *,
    Cardinal,
    Cardinal *,
    char *[]);

extern XtAppContext XtCreateApplicationContext();

extern void XtDestroyApplicationContext(XtAppContext);

extern XtAppContext XtWidgetToApplicationContext(Widget);

extern XrmDatabase XtDatabase(Display*);

extern void XtCloseDisplay(Display *);

class XrmResource {
    XrmQuark	xrm_name;	  /* Resource name quark 		*/
    XrmQuark	xrm_class;	  /* Resource class quark 		*/
    XrmQuark	xrm_type;	  /* Resource representation type quark */
    Cardinal	xrm_size;	  /* Size in bytes of representation	*/
    long int	xrm_offset;	  /* -offset-1				*/
    XrmQuark	xrm_default_type; /* Default representation type quark 	*/
    caddr_t	xrm_default_addr; /* Default resource address		*/
};
typedef XrmResource *XrmResourceList;

extern void XtCopyFromParent();

extern void XtCopyDefaultDepth();

extern void XtCopyDefaultColormap();

extern void XtCopyAncestorSensitive();

extern void XtCopyScreen();

typedef class XtResource *XtResourceList;

extern void XrmCompileResourceList(XtResourceList, Cardinal);

extern void XtGetSubresources(Widget, caddr_t, String, String, XtResourceList,
	Cardinal, ArgList, Cardinal);

extern void XtSetValues(Widget, ArgList, Cardinal);

extern void XtGetValues(Widget, ArgList, Cardinal);

extern void XtSetSubvalues(caddr_t, XtResourceList, Cardinal, ArgList, Cardinal);

extern void XtGetSubvalues(caddr_t, XtResourceList, Cardinal, ArgList, Cardinal);


typedef class XtResource {
    String     resource_name;   /* Resource name                            */
    String     resource_class;  /* Resource class                           */
    String     resource_type;   /* Representation type desired              */
    Cardinal    resource_size;  /* Size in bytes of representation          */
    Cardinal    resource_offset;/* Offset from base to put resource value   */
    String     default_type;    /* representation type of specified default */
    caddr_t     default_addr;   /* Address of default resource              */
} XtResource;

/*
 * If we're going to go sticking proc *'s into default_addr, we should use a
 * different type for the field. Possibly XtArgVal?
 */

#define XtOffset(type,field)    ((unsigned int)&(((type)NULL)->field))

extern void XtReadBinaryDatabase ();
    /* FILE    *f;                      */
    /* ResourceDatabase *db;            */

extern void XtWriteBinaryDatabase ();
    /* FILE    *f;                      */
    /* ResourceDatabase db;             */

  
/*************************************************************
 *
 * Error Handling
 *
 ************************************************************/

typedef void (*XtErrorMsgHandler)(
    String, String, String, String, String*, Cardinal*);

extern void XtSetErrorMsgHandler(XtErrorMsgHandler);

extern void XtSetWarningMsgHandler(XtErrorMsgHandler);

extern void XtErrorMsg(String, String, String, String, String*, Cardinal*);

extern void XtWarningMsg(String, String, String, String, String*, Cardinal*);

typedef void (*XtErrorHandler)(String);

extern void XtSetErrorHandler(XtErrorHandler);

extern void XtSetWarningHandler(XtErrorHandler);

extern void XtError(String);

extern void XtWarning(String);

extern XrmDatabase XtGetErrorDatabase();
/* no paramters, returns toolkit error database*/


extern void XtGetErrorDatabaseText(char*, char*, char*, char*, char*, int);


/****************************************************************
 *
 * Memory Management
 *
 ****************************************************************/

#define XtNew(type) ((type *) XtMalloc((unsigned) sizeof(type)))
#define XtNewString(str) (strcpy(XtMalloc((unsigned) strlen(str) + 1), str))

#ifdef VMS
/* this is temporary, until VMS gets back in sync */

#ifdef XtMalloc
#undef XtMalloc
#endif

#ifdef XtCalloc
#undef XtCalloc
#endif

#ifdef XtRealloc
#undef XtRealloc
#endif

#ifdef XtFree
#undef XtFree
#endif

#endif

extern char *XtMalloc(Cardinal);

extern char *XtCalloc(Cardinal, Cardinal);

extern char *XtRealloc(char*, Cardinal);

extern void XtFree(char *);


/*************************************************************
 *
 *  Work procs
 *
 **************************************************************/

typedef Boolean (*XtWorkProc)(Opaque);

extern XtWorkProcId XtAddWorkProc();
    /*  XtWorkProc proc; */
    /*  Opaque closure; */

extern XtWorkProcId XtAppAddWorkProc(XtAppContext, XtWorkProc, Opaque);

extern void  XtRemoveWorkProc(XtWorkProcId);


/****************************************************************
 *
 * Graphic Context Management
 *****************************************************************/

extern GC XtGetGC(Widget, XtGCMask, XGCValues*);

extern void XtDestroyGC (Widget, GC);
/* we pass in the widget because XFreeGC needs a display, and there isn't */
/* one stored in the GC record. */

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

