/*------------------------------------------------------------------------------
 * $Date$			$Revision$
 *------------------------------------------------------------------------------
 *             Copyright (c) 1991, Visual Edge Software Ltd.
 *
 * ALL  RIGHTS  RESERVED.  Permission  to  use,  copy,  modify,  and
 * distribute  this  software  and its documentation for any purpose
 * and  without  fee  is  hereby  granted,  provided  that the above
 * copyright  notice  appear  in  all  copies  and  that  both  that
 * copyright  notice and this permission notice appear in supporting
 * documentation,  and that  the name of Visual Edge Software not be
 * used  in advertising  or publicity  pertaining to distribution of
 * the software without specific, written prior permission. The year
 * included in the notice is the year of the creation of the work.
 *------------------------------------------------------------------------------
 *				UxXt.h
 *----------------------------------------------------------------------------*/

#ifndef	_UX_XT_H_
#define	_UX_XT_H_

#ifdef __cplusplus
#define EXTERNC extern "C"
#else
#define EXTERNC extern
#endif /* __cplusplus */

#include <stdlib.h>
#include <string.h>
#include <Xm/Xm.h>

#ifdef UIL_CODE
#include <Mrm/MrmPublic.h>
#endif /* UIL_CODE */

/********************
** DOUG Commented Out
#if (defined(__STDC__) && !defined(SOLARIS) && !defined(sun4) && !defined(univel) && !defined(dgix86) && !defined(dg88) && !defined(motor88) && !defined(__sgi) && !defined(ncrix86) && !defined(sco) && !defined(ibmr2) && !defined(osf1) && !defined(linux) && !defined(_INCLUDE_HPUX_SOURCE)) || (defined(hp700v9) && !defined(_CADDR_T))
typedef char *caddr_t;
#endif
*******************/

#ifdef UX_CATALOG
#include <locale.h>
#include <nl_types.h>
#endif /* UX_CATALOG */



#ifndef	UXPROTO
#	ifdef _NO_PROTO
#		define UXPROTO(x) ()
#	else /* _NO_PROTO */
#		define UXPROTO(x) x
#	endif /* _NO_PROTO */
#endif /* UXPROTO */

#ifdef UXINLINE
#undef UXINLINE
#endif /* UXINLINE */
#if defined(DESIGN_TIME) || defined (UX_INTERPRETER)
#define UXINLINE 
#else
#define UXINLINE inline
#endif

/*-------------------------------------------------------
 * UXORB_HEADER, if defined, is the include form for
 * the header that defines the CORBA Environment type
 * and exception type codes.
 *
 * You can specify a file with a compile option like
 * 	-DUXORB_HEADER='<SomeOrb.h>'
 *
 * For CORBA 2.0 compliant Orbs -DCORBA2 should also
 * be used.
 *-----------------------------------------------------*/

/********************
** DOUG Commented Out
#include <sys/sysmacros.h>
*********************/

#ifdef major
#undef major
#endif
#ifdef minor
#undef minor
#endif

#ifdef UXORB_HEADER
#include UXORB_HEADER
#ifdef CORBA2
#ifdef __cplusplus
        typedef CORBA::Environment Environment;
#else /* ! __cplusplus */
        typedef CORBA_Environment Environment;
#endif /* __cplusplus */
#endif /* CORBA2 */
#else
        /*------------------------------------------------------------
         * In the absence of an ORB implementation,
         * these minimal definitions satisfy our method dispatch code.
         *-----------------------------------------------------------*/

#ifdef __cplusplus
        class CORBA
        {
                public:

		typedef enum
		{
			NO_EXCEPTION,
			USER_EXCEPTION,
			SYSTEM_EXCEPTION
		} exception_type;

                class Environment
                {
			private:

                        exception_type _major;

			public:

			exception_type major() { return _major;};
			void major (exception_type maj) { _major = maj;};
                };
        };
	typedef CORBA::Environment Environment;
	typedef CORBA::Environment CORBA_Environment;
#else /* ! __cplusplus */
	typedef enum
	{
		NO_EXCEPTION,
		USER_EXCEPTION,
		SYSTEM_EXCEPTION
	} exception_type;

        typedef struct CORBA_Environment {
                exception_type  _major;
        } CORBA_Environment;
	typedef CORBA_Environment Environment;
#endif /* __cplusplus */
#endif  /* UXORB_HEADER */

#ifdef EXTERN_C_WRAPPERS
#define EXTERNCCORBA CORBA_Environment
#else /* ! EXTERN_C_WRAPPERS */
#define EXTERNCCORBA CORBA::Environment
#endif  /* EXTERN_C_WRAPPERS */

/* UxEnv is provided as a convenience for use in interface methods. */
extern	Environment	UxEnv;

/* The following macros are used in converting string values to the form
   required by the widgets */

#define	RES_CONVERT( res_name, res_value) \
	XtVaTypedArg, (res_name), XmRString, (res_value), strlen(res_value) + 1

#define	UxPutStrRes( wgt, res_name, res_value ) \
	XtVaSetValues( wgt, RES_CONVERT( res_name, res_value ), NULL )


#ifndef UX_INTERPRETER	/* Omit this section when interpreting the code */

/* The following macros are supplied for compatibility with swidget code */
#define	swidget			Widget
#define	UxIsValidSwidget(sw)	((sw) != NULL)
#define NO_PARENT             	((Widget) NULL)
#define UxThisWidget		(UxWidget)
#define UxWidgetToSwidget(w)    (w)
#define UxGetWidget(sw)         (sw)


/* Macros needed for the method support code */
#define	UxMalloc(a)		(malloc(a))
#define	UxCalloc(a,b)		(calloc((a), (b)))
#ifdef sun4
#ifdef __SUNPRO_CC
#define	UxRealloc(a,b)		((a) ? realloc((char *)(a), (b)): malloc((b)))
#define UxFree(a)		do{ if (a) free((char *)(a)); } while(0)
#else
#define	UxRealloc(a,b)		((a) ? realloc((a), (b)): malloc((b)))
#define UxFree(a)		do{ if (a) free((a)); } while(0)
#endif /* __SUNPRO_CC */
#else
#define	UxRealloc(a,b)		(realloc((a), (b)))
#define UxFree(a)		(free(a))
#endif /* sun4 */
#define UxStrEqual(a,b)		(!strcmp((a),(b)))
#define UxGetParent(a)		(XtParent((a)))

#ifndef _GRAB_INCLUDED
#define _GRAB_INCLUDED
typedef enum
{
        no_grab = XtGrabNone,
        nonexclusive_grab = XtGrabNonexclusive,
        exclusive_grab = XtGrabExclusive
} grabtype;
#endif  /* _GRAB_INCLUDED  */

/*-------------------------------------------------------------------
 * Macros, global needed are for using XOpen catalogs
 *------------------------------------------------------------------*/
#ifdef UX_CATALOG
#if (defined(sun4) && defined(__cplusplus))
extern "C" {
nl_catd catopen UXPROTO((const char *, int));
char *catgets UXPROTO((nl_catd, int, int, const char *));
int catclose UXPROTO((nl_catd));
}
#endif /* sun4 && __cplusplus */
#define UxCATOPEN( filename, oflag )	catopen( filename, oflag )
#define UxCATCLOSE( catId )		catclose( catId )
#define UxCATGETS( setId, msgId, ds ) \
        catgets( UxMsgCatalog, (setId), (msgId), (ds) )
#else
#define UxCATOPEN( filename, oflag )	-1
#define UxCATCLOSE( catId )		0
#define UxCATGETS( setId, msgId, ds )	(ds)
#endif /* UX_CATALOG */


/* The following global variables are defined in the main() function */
extern  XtAppContext	UxAppContext;
extern  Widget		UxTopLevel;
extern  Display		*UxDisplay;
extern  int		UxScreen;
#ifdef UX_CATALOG
extern  nl_catd		UxMsgCatalog;
#endif /* UX_CATALOG */


/* The following are error codes returned by the functions in UxXt.c */
#define UX_ERROR           -1
#define UX_NO_ERROR        0

#ifdef UIL_CODE
extern	void	UxMrmFetchError UXPROTO((MrmHierarchy, char *,Widget,Cardinal));
extern	MrmHierarchy    UxMrmOpenHierarchy UXPROTO(( char *));
extern  void            UxMrmRegisterClass UXPROTO(( char *,
				Widget (*)(Widget, String, Arg *, Cardinal)));
#endif /* UIL_CODE */


/*-----------------------------------------------------------------------
 * The following are declarations of the functions in UxXt.c
 *---------------------------------------------------------------------*/
/*****************************
** DOUG added ifdef __cplusplus  because these functions can be called
** from C++
******************************/
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

extern  int		UxDestroyInterface UXPROTO (( Widget wgt ));
extern  void		UxFreeClientDataCB UXPROTO (( Widget wgt,\
				 XtPointer client_data, XtPointer call_data ));
extern  void		UxLoadResources UXPROTO ((const char *fname ));
extern  XmFontList	UxConvertFontList UXPROTO (( char *fontlist_str ));
extern  Pixmap		UxConvertPixmap UXPROTO (( char *file_name ));
extern  Pixmap		UxConvert_bitmap UXPROTO (( char *file_name ));
extern	wchar_t *	UxConvertValueWcs UXPROTO (( char *value_str ));

extern  void            UxDestroyContextCB UXPROTO (( Widget, XtPointer,
						 XtPointer ));
extern	XtArgVal	UxRemoveValueFromArgList UXPROTO (( Arg *args,
						Cardinal *ptr_num_args,
						String res_name ));
#ifdef __cplusplus
}
#endif /* __cplusplus */

/*-----------------------------------------------------
 * Functions that need to be compiled as C functions
 * when compiling with C++.
 *-----------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

extern  int	UxPopupInterface UXPROTO (( Widget wgt, grabtype grab_flag ));
extern  int	UxPopdownInterface UXPROTO (( Widget wgt ));

extern	void    	UxDeleteContextCB UXPROTO (( Widget, XtPointer, XtPointer ));
extern  int		UxPutContext UXPROTO (( Widget wgt, void * context ));
extern  void *		UxGetContext UXPROTO (( Widget wgt ));
extern  void *          UxNewContext UXPROTO (( size_t size, int isSubclass ));
extern	Widget  	UxRealWidget UXPROTO (( Widget ));
extern	Widget		UxChildSite UXPROTO (( Widget ));
extern	Widget		UxInheritedChildSite UXPROTO (( Widget ));
extern	int     	UxGetClassCode UXPROTO (( swidget sw ));
extern	int     	UxMessageIndex UXPROTO (( const char* name ));
extern	int     	UxGetIfClassCode UXPROTO (( Widget wgt ));
extern	char *		UxConcatStrings UXPROTO(( char*, char* ));
extern  void            UxSetTranslations UXPROTO(( Widget wgt, char* translation ));

#ifdef UX_CATALOG
extern	char *		UxStrMem UXPROTO ((char *str));
#endif /* UX_CATALOG */

#ifdef __cplusplus
}
#endif /* __cplusplus */


#include "UxInterf.h"


/* backwards compatibility */
#ifdef __cplusplus
inline  int UxPopupInterface ( Widget wgt, XtGrabKind grab_flag )
{ return UxPopupInterface(wgt, (grabtype) grab_flag); }
#endif


#endif /* ! UX_INTERPRETER */

/*------------------------------------------------------------------------------
 * NAME:	UxAdapterSwidget
 * DESCRIPTION:	Creates a component swidget for any Widget.
 * INPUT:	Widget w	- any Widget
 *		swidget parent	- the swidget representing its parent.
 *		char * name	- the name for the swidget
 *		int  clsCode	- the class code for the component
 *		void * cmpntRef - user field for the external object
 *		void * context	- the UIM/X context ptr of the component
 * RETURNS:	The Widget supplied.
 *
 * See UxLib.h.  In Xt-mode, this function serves to attach the cmpntRef,
 * context, and interface class code, to the supplied Widget.
 *----------------------------------------------------------------------------*/

/*-------------------------------------------------------
 * Functions that need to be compiled as C functions
 * when compiling with C++.
 *-----------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

swidget	UxAdapterSwidget UXPROTO ((Widget w,
			 	Widget	parent,
			 	char*	name,
			 	int	clsCode,
			 	void*	cmpnt,
			 	void*	context));

void*	UxGetComponentRef	UXPROTO ((Widget adapter));
int     UxPutClassCode		UXPROTO (( Widget wgt, int id));
void	UxPutComponentRef	UXPROTO ((Widget adapter, void* ref));

/*-----------------------------------------------------
 * Declaration of swidget method helper functions
 *-----------------------------------------------------*/

#ifndef SWIDGET_METHOD_HELPER_FUNCTIONS_DECLARED
#define SWIDGET_METHOD_HELPER_FUNCTIONS_DECLARED
 
extern char *UxListToString UXPROTO((XmString *list, int itemcount));
extern XmString *UxStringToList UXPROTO((char *string, int *itemcount));
extern void UxFreeXmStringList UXPROTO((XmString *list));
extern void UxSwidgetMethodSetBackground UXPROTO((Widget widget, char *color));
extern void* UxMethodLookup UXPROTO((swidget, int, const char*));
 
#endif /* SWIDGET_METHOD_HELPER_FUNCTIONS_DECLARED */

#ifdef __cplusplus
}
#endif /* __cplusplus */

#define	UxNO_CLSCODE	-1
#define	UxNO_CONTEXT	0

/* Xt-code components cannot be used at design-time. */
 
#define	UxAdapterDesignMethods(a,b,c,d)	

#endif /* ! _UX_XT_H_ */

