/*
**   ----------------------------------------------------------------- 
**        Copyright (C) 1990, 1991 Sun Microsystems, Inc
**                   All rights reserved.
**         Notice of copyright on this source code
**         product does not indicate publication.
**   
**   RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by
**   the U.S. Government is subject to restrictions as set forth
**   in subparagraph (c)(1)(ii) of the Rights in Technical Data
**   and Computer Software Clause at DFARS 252.227-7013 (Oct. 1988)
**   and FAR 52.227-19 (c) (June 1987).
**   
**     Sun Microsystems, Inc., 2550 Garcia Avenue,
**     Mountain View, California 94043.
**   ----------------------------------------------------------------- 
*/
/*	Copyright (c) 1990 UNIX System Laboratories, Inc.	*/
/*	Copyright (c) 1988 AT&T	*/
/*	  All Rights Reserved  	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF     	*/
/*	UNIX System Laboratories, Inc.                     	*/
/*	The copyright notice above does not evidence any   	*/
/*	actual or intended publication of such source code.	*/

#ifndef NOIDENT
#ident	"@(#)olmisc:DynamicP.h	1.13"
#endif

#ifndef __DynamicP_h__
#define __DynamicP_h__

#include <Xol/Dynamic.h>

#define XtROlKeyDef		"OlKeyDef"
#define XtROlBtnDef		"OlBtnDef"

#define MAXDEFS			2
#define MORESLOTS               4
#define BUFFER_SIZE		64

#define Xfree(x)		{ FREE(x); x = NULL; }
#define ABS_DELTA(x1, x2)	(x1 < x2 ? x2 - x1 : x1 - x2)

#define IsDampableKey(flag, k)	(flag == True && IsCursorKey(k))

#define CanBeBound(flag,keysym,modifier) \
				(flag == False || keysym >= 0x1000 || \
				(modifier & ~(ShiftMask | LockMask)))

#define DEF_SEPS		","	/* I18N */
#define MOD_SEPS		"!~ "	/* I18N */
#define LBRA			'<'	/* I18N */
#define RBRA			'>'	/* I18N */

#if	!defined(STREQU)
# define STREQU(A,B)	(strcmp((A),(B)) == 0)
#endif

#if	!defined(Malloc)
# define Malloc(N) XtMalloc(N)
#endif

#if	!defined(Realloc)
# define Realloc(P,N) XtRealloc(P,N)
#endif

#if	!defined(New)
# define New(M) XtNew(M)
#endif

#if	!defined(Free)
# define Free(M) XtFree(M)
#endif

#if	!defined(Strlen)
# define Strlen(S) ((S) && *(S)? strlen((S)) : 0)
#endif

#if	!defined(Strdup)
# define Strdup(S) strcpy(Malloc((unsigned)Strlen(S) + 1), S)
#endif

#if	!defined(Array)
# define Array(P,T,N) \
	((N)? \
		  ((P)? \
			  (T *)Realloc((P), sizeof(T) * (N)) \
			: (T *)Malloc(sizeof(T) * (N)) \
		  ) \
		: ((P)? (Free(P),(T *)0) : (T *)0) \
	)
#endif

typedef unsigned int	BtnSym;

typedef struct _OlKeyDef {
	int		used;
	Modifiers	modifier[MAXDEFS];
	KeySym		keysym[MAXDEFS];
} OlKeyDef;

typedef struct _OlBtnDef {
	int		used;
	Modifiers	modifier[MAXDEFS];
	BtnSym		button[MAXDEFS];
} OlBtnDef;

typedef struct _OlKeyBinding {
	OLconst String	name;           /* XtN string */
	OLconst String	default_value;  /* `,' sperated string, two most */
	OlInputEvent	ol_event;
	OlKeyDef	def;
} OlKeyBinding;

typedef struct _OlBtnBinding {
	OLconst String	name;           /* XtN string */
	OLconst String	default_value;  /* `,' sperated string, two most */
	OlInputEvent	ol_event;
	OlBtnDef	def;
} OlBtnBinding;

typedef enum { Alt, Meta, Hyper, Super, NumLock } ModifierType;

typedef struct {
    ModifierType	modifier_type;
    String              modifier_name;
    KeySym              left_keysym;
    KeySym              right_keysym;
    KeyCode             left_keycode;
    KeyCode             right_keycode;
    Modifiers           modifier;
} ModifierInfo;

typedef struct {
    KeySym 		keysym;
    KeyCode 		*keycodelist;
    Cardinal 		keycount;
} KeypadInfo;

typedef struct mapping {
	OLconst String			s;
	unsigned long			m;
} mapping;

typedef struct _btn_mapping {
	OLconst unsigned long		button;
	OLconst unsigned long		button_mask;
} btn_mapping;

typedef struct _Token {
	short			i;
	short			j;
} Token;

typedef struct _OlVirtualEventInfo {
	Display			*dpy;
	Boolean			keep;
	OlKeyBinding *		key_bindings;
	OlBtnBinding *		btn_bindings;
	char			num_key_bindings;
	char			num_btn_bindings;
	Token *			sorted_key_db;
} OlVirtualEventInfo;

typedef struct _OlClassSearchRec {
	WidgetClass		wc;
	OlVirtualEventInfo *	db;
} OlClassSearchRec, *OlClassSearchInfo;

typedef struct _OlWidgetSearchRec {
	Widget			w;
	OlVirtualEventInfo *	db;
} OlWidgetSearchRec, *OlWidgetSearchInfo;

typedef struct GrabbedVirtualKey {
	Widget			w;
	OlVirtualName		vkey;
	OlKeyBinding *		kb;
	OlKeyDef		as_grabbed;
	Boolean			grabbed;
	Boolean			owner_events;
	int			pointer_mode;
	int			keyboard_mode;
} GrabbedVirtualKey;

typedef struct {
	Cardinal		mouse_damping_factor;
	Cardinal		multi_click_timeout;
	Cardinal		key_remap_timeout;
} LocalData;

typedef struct _DynamicCallback {
	OlDynamicCallbackProc	CB;
	XtPointer		data;
} DynamicCallback;

typedef struct CharKeysymMap {
	OLconst char			single;
	OLconst KeySym			keysym;
} CharKeysymMap;

typedef struct _ComposeData {
	Widget		widget;
	Widget		vendor;
	Time		time;
	char		buf[10];
	int		buf_len;
	KeySym		keysym;
	XComposeStatus	cstatus;
} ComposeData, *ComposeDataPtr;

/*
 * new for multiple display support
 */

typedef struct	_PerDisplayVEDBInfo {
	Display			*dpy;
	Widget			appl_shell;
	Boolean			doing_copy;

	OlVirtualEventTable	*db_stack;
	short                   db_stack_slots_left;
	short                   db_stack_slots_alloced;
	short                   db_stack_entries;
 
	OlVirtualEventTable	*avail_dbs;
	short                   avail_dbs_slots_left;
	short                   avail_dbs_slots_alloced;
	short                   avail_dbs_entries;
	 
	OlWidgetSearchInfo      wid_list;
	short                   wid_list_slots_left;
	short                   wid_list_slots_alloced;
	short                   wid_list_entries;
	 
	OlClassSearchInfo       wc_list;
	short                   wc_list_slots_left;
	short                   wc_list_slots_alloced;
	short                   wc_list_entries;

	OlVirtualEventTable	OlCoreDB;
	OlVirtualEventTable	OlTextDB;

	ModifierInfo		*mod_info;
	KeypadInfo		*keypad_table;
} PerDisplayVEDBInfo, *PerDisplayVEDBInfoPtr;
#endif /* __DynamicP_h__ */
