/* $XConsortium: TranslateI.h,v 1.25 90/08/17 15:48:27 swick Exp $ */

/***********************************************************
Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
and the Massachusetts Institute of Technology, Cambridge, Massachusetts.

                        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 names of Digital or MIT not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.  

DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

******************************************************************/

/* 
 * TranslateI.h - Header file private to translation management
 * 
 * Author:	Charles Haynes
 * 		Digital Equipment Corporation
 * 		Western Research Laboratory
 * Date:	Sat Aug 29 1987
 */

/*#define REFCNT_TRANSLATIONS*/
#define CACHE_TRANSLATIONS

#define _XtRStateTablePair "_XtStateTablePair"

typedef Boolean (*MatchProc)();
  /* Event parsed;
     XEvent incoming;
  */

typedef struct _ModToKeysymTable {
    Modifiers mask;
    int count;
    int index;
} ModToKeysymTable;

typedef struct _LateBindings {
    Boolean knot;
    Boolean pair;
#ifdef PRECOMPILED_TM
    char pad[2];
#endif
    KeySym keysym;
} LateBindings, *LateBindingsPtr;

typedef short ModifierMask;
typedef struct _EventObjRec *EventObjPtr;
typedef struct _EventRec {
    unsigned long modifiers;
    unsigned long modifierMask;
    LateBindingsPtr lateModifiers;
    unsigned long eventType;
    unsigned long eventCode;
    unsigned long eventCodeMask;
#ifdef PRECOMPILED_TM
    int	matchEvent;
#else
    MatchProc matchEvent;
#endif
    Boolean standard;
#ifdef PRECOMPILED_TM
    char pad[3];
#endif
} Event;

typedef enum _TMkind {override,augment} TMkind;

typedef struct _EventObjRec {
    Event event;	/* X event description */
    StatePtr state;	/* pointer to linked lists of state info */
} EventObjRec;

typedef struct _ActionsRec *ActionPtr;
typedef struct _ActionsRec {
#ifdef DEC_EXTENSION
/* Save memory by reducing size of fields... */
    short index;		/* index into quarkTable to find proc */
    unsigned short num_params;	/* number of params */
    String *params;		/* pointer to array of params */
#else
    int index;			/* index into quarkTable to find proc */
    String *params;		/* pointer to array of params */
    Cardinal num_params;	/* number of params */
#endif
    ActionPtr next;		/* next action to perform */
} ActionRec;

typedef struct _StateRec {
#ifdef DEC_EXTENSION
/* Save memory by reducing size of fields... */
    short index;	/* index of event into EventObj table */
    Boolean cycle;	/* true iff nextLevel is a loop */
#ifdef PRECOMPILED_TM
    char pad[1];
#endif
#else
    int index;		/* index of event into EventObj table */
#endif
    ActionPtr actions;	/* rhs list of actions to perform */
    StatePtr nextLevel;	/* the next level points to the next event
			   in one event sequence */
    StatePtr next;	/* points to other event state at same level */
    StatePtr forw;	/* points to next state in list of all states */
#ifndef DEC_EXTENSION
    Boolean cycle;	/* true iff nextLevel is a loop */
#endif
}  StateRec;
typedef enum {XtTableReplace,XtTableAugment,XtTableOverride} _XtTranslateOp;

typedef struct _StateTableData {
    _XtTranslateOp	operation; /*replace,augment,override*/
#ifdef DEC_EXTENSION
/* Save memory by reducing size of fields... */
    unsigned short	numEvents;
    unsigned short	eventTblSize;
    unsigned short	numQuarks;   /* # of entries in quarkTable */
    unsigned short	quarkTblSize; /*total size of quarkTable */
    unsigned short	accNumQuarks;
    unsigned short	accQuarkTblSize;
#else
    unsigned int	numEvents;
    unsigned int	eventTblSize;
#endif
    EventObjPtr		eventObjTbl;
#ifndef DEC_EXTENSION
    unsigned int	numQuarks;   /* # of entries in quarkTable */
    unsigned int	quarkTblSize; /*total size of quarkTable */
#endif
    XrmQuark*		quarkTable;  /* table of quarkified rhs*/
#ifndef DEC_EXTENSION
    unsigned int	accNumQuarks;
    unsigned int	accQuarkTblSize;
#endif
    XrmQuark*		accQuarkTable;
    StatePtr		head;	/* head of list of all states */
    Boolean		mappingNotifyInterest;
#ifdef PRECOMPILED_TM
    char pad[3];
#endif
} StateTableData, *StateTablePtr;
 
typedef struct _XtBoundAccActionRec {
    Widget widget;    /*widgetID to pass to action Proc*/
    XtActionProc proc; /*action procedure */
} XtBoundAccActionRec;

typedef struct _TranslationData {
    StateTablePtr	 stateTable;
    XtBoundAccActionRec* accProcTbl;
} TranslationData;
  
typedef struct _TMConvertRec {
   StateTablePtr old; /* table to merge into */
   StateTablePtr new; /* table to merge from */
   TMkind  operation; /* merge or augment     */
} TMConvertRec;

#define _XtEventTimerEventType ((unsigned long)-1L)
#define KeysymModMask		(1<<27) /* private to TM */
#define AnyButtonMask		(1<<28)	/* private to TM */

typedef struct _EventSeqRec *EventSeqPtr;
typedef struct _EventSeqRec {
    Event event;	/* X event description */
    StatePtr state;	/* private to state table builder */
    EventSeqPtr next;	/* next event on line */
    ActionPtr actions;	/* r.h.s.   list of actions to perform */
} EventSeqRec;

typedef EventSeqRec EventRec;
typedef EventSeqPtr EventPtr;
typedef struct _TMEventRec {
    XEvent *xev;
    Event event;
}TMEventRec,*TMEventPtr;

extern void _XtAddEventSeqToStateTable();
extern void _XtInitializeStateTable(); /* stateTable */
    /* _XtTranslations *stateTable; */

typedef struct _ActionHookRec {
    struct _ActionHookRec* next; /* must remain first */
    XtAppContext app;
    XtActionHookProc proc;
    XtPointer closure;
} ActionHookRec, *ActionHook;

typedef struct _TMContext {
    XEvent *event;
    unsigned long serial;
    KeySym keysym;
    Modifiers modifiers;
#ifdef DEC_EXTENSION
    Modifiers event_modifiers;
    KeyCode   event_keycode;
    KeySym*   possible_keysyms;
    int       pk_size;
#endif
} TMContextRec, *TMContext;

extern Boolean _XtMatchUsingStandardMods();
extern Boolean _XtMatchUsingDontCareMods();
extern Boolean _XtRegularMatch();
extern Boolean _XtMatchAtom();
extern void _XtConvertCase();
extern void _XtBuildKeysymTables();

extern void _XtPopupInitialize();

extern void _XtInstallTranslations(
#if NeedFunctionPrototypes
    Widget		/* widget */,
    XtTranslations	/* stateTable */
#endif
);
  
extern void _XtBindActions(
#if NeedFunctionPrototypes
    Widget	/* widget */,
    XtTM	/* tm_rec */
#endif
);
  
extern void _XtTranslateInitialize();
  
extern XtTranslations _XtParseTranslationTable(
#if NeedFunctionPrototypes
    String /* source */
#endif
);
  
#if NeedWidePrototypes
#define Boolean int
#endif

extern void _XtRegisterGrabs(
#if NeedFunctionPrototypes
    Widget /* widget */,
    Boolean /* acceleratorsOnly */
#endif
);

extern void _XtPopup(
#if NeedFunctionPrototypes
    Widget 	/* widget */,
    XtGrabKind 	/* grab_kind */,
    Boolean 	/* spring_loaded */
#endif
);

#undef Boolean

extern XtTranslations _XtCondCopyTranslations(
#if NeedFunctionPrototypes
    XtTranslations /* translations */
#endif
);

extern void _XtRegisterAccRemoveCallbacks(
#if NeedFunctionPrototypes
    Widget /* dest */
#endif
);

extern void _XtUninstallAccelerators(
#if NeedFunctionPrototypes
    Widget /* w */
#endif
);

extern Boolean _XtCvtMergeTranslations(
#if NeedFunctionPrototypes
    Display*	/* dpy */,
    XrmValuePtr /* args */,
    Cardinal*	/* num_args */,
    XrmValuePtr /* from */,
    XrmValuePtr /* to */,
    XtPointer*	/* closure_ret */
#endif
);

void _XtFreeTranslations(
#if NeedFunctionPrototypes
    XtAppContext /* app */,
    XrmValuePtr  /* toVal */,
    XtPointer    /* closure */,
    XrmValuePtr  /* args */,
    Cardinal*	 /* num_args */
#endif
);

#ifdef PRECOMPILED_TM
#define XTMATCHATOMCODE			1
#define XTMATCHUSINGSTANDARDMODSCODE 	2
#define XTMATCHUSINGDONTCAREMODSCODE 	3
#define XTREGULARMATCHCODE 		4
#endif
