TranslateI.h revision 2265a131
1/* $Xorg: TranslateI.h,v 1.4 2001/02/09 02:03:59 xorgcvs Exp $ */
2
3/***********************************************************
4
5Copyright 1987, 1988, 1998  The Open Group
6
7Permission to use, copy, modify, distribute, and sell this software and its
8documentation for any purpose is hereby granted without fee, provided that
9the above copyright notice appear in all copies and that both that
10copyright notice and this permission notice appear in supporting
11documentation.
12
13The above copyright notice and this permission notice shall be included in
14all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
19OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23Except as contained in this notice, the name of The Open Group shall not be
24used in advertising or otherwise to promote the sale, use or other dealings
25in this Software without prior written authorization from The Open Group.
26
27
28Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
29
30                        All Rights Reserved
31
32Permission to use, copy, modify, and distribute this software and its
33documentation for any purpose and without fee is hereby granted,
34provided that the above copyright notice appear in all copies and that
35both that copyright notice and this permission notice appear in
36supporting documentation, and that the name of Digital not be
37used in advertising or publicity pertaining to distribution of the
38software without specific, written prior permission.
39
40DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
41ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
42DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
43ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
44WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
45ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
46SOFTWARE.
47
48******************************************************************/
49/* $XFree86: xc/lib/Xt/TranslateI.h,v 1.3 2001/12/14 19:56:32 dawes Exp $ */
50
51/*
52 * TranslateI.h - Header file private to translation management
53 *
54 * Author:	Gabe Beged-Dov, HP
55 *
56 * Former Author:	Charles Haynes
57 * 		Digital Equipment Corporation
58 * 		Western Research Laboratory
59 * Date:	Sat Aug 29 1987
60 */
61
62/*#define REFCNT_TRANSLATIONS*/
63#define CACHE_TRANSLATIONS
64
65#define TM_NO_MATCH (-2)
66
67#define _XtRStateTablePair "_XtStateTablePair"
68
69typedef unsigned char TMByteCard;
70typedef unsigned short TMShortCard;
71typedef unsigned long TMLongCard;
72typedef short TMShortInt;
73
74typedef struct _TMTypeMatchRec *TMTypeMatch;
75typedef struct _TMModifierMatchRec *TMModifierMatch;
76typedef struct _TMEventRec *TMEventPtr;
77
78typedef Boolean (*MatchProc)(TMTypeMatch typeMatch,
79			     TMModifierMatch modMatch,
80			     TMEventPtr eventSeq);
81
82typedef struct _ModToKeysymTable {
83    Modifiers mask;
84    int count;
85    int idx;
86} ModToKeysymTable;
87
88typedef struct _LateBindings {
89    unsigned int knot:1;
90    unsigned int pair:1;
91    unsigned short ref_count;	/* garbage collection */
92    KeySym keysym;
93} LateBindings, *LateBindingsPtr;
94
95typedef short ModifierMask;
96
97typedef struct _ActionsRec *ActionPtr;
98typedef struct _ActionsRec {
99    int idx;			/* index into quarkTable to find proc */
100    String *params;		/* pointer to array of params */
101    Cardinal num_params;	/* number of params */
102    ActionPtr next;		/* next action to perform */
103} ActionRec;
104
105typedef struct _XtStateRec *StatePtr;
106typedef struct _XtStateRec {
107    unsigned int	isCycleStart:1;
108    unsigned int	isCycleEnd:1;
109    TMShortCard		typeIndex;
110    TMShortCard		modIndex;
111    ActionPtr		actions;	/* rhs list of actions to perform */
112    StatePtr 		nextLevel;
113}StateRec;
114
115
116#define XtTableReplace	0
117#define XtTableAugment	1
118#define XtTableOverride	2
119#define XtTableUnmerge  3
120
121typedef unsigned int _XtTranslateOp;
122
123/*
124 * New Definitions
125 */
126typedef struct _TMModifierMatchRec{
127    TMLongCard	 modifiers;
128    TMLongCard	 modifierMask;
129    LateBindingsPtr lateModifiers;
130    Boolean	 standard;
131}TMModifierMatchRec;
132
133typedef struct _TMTypeMatchRec{
134    TMLongCard	 eventType;
135    TMLongCard	 eventCode;
136    TMLongCard	 eventCodeMask;
137    MatchProc	 matchEvent;
138}TMTypeMatchRec;
139
140typedef struct _TMBranchHeadRec {
141    unsigned int	isSimple:1;
142    unsigned int	hasActions:1;
143    unsigned int	hasCycles:1;
144    unsigned int	more:13;
145    TMShortCard		typeIndex;
146    TMShortCard		modIndex;
147}TMBranchHeadRec, *TMBranchHead;
148
149/* NOTE: elements of this structure must match those of
150 * TMComplexStateTreeRec and TMParseStateTreeRec.
151 */
152typedef struct _TMSimpleStateTreeRec{
153    unsigned int	isSimple:1;
154    unsigned int	isAccelerator:1;
155    unsigned int	mappingNotifyInterest:1;
156    unsigned int	refCount:13;
157    TMShortCard		numBranchHeads;
158    TMShortCard		numQuarks;   /* # of entries in quarkTbl */
159    TMShortCard		unused;	     /* to ensure same alignment */
160    TMBranchHeadRec	*branchHeadTbl;
161    XrmQuark		*quarkTbl;  /* table of quarkified rhs*/
162}TMSimpleStateTreeRec, *TMSimpleStateTree;
163
164/* NOTE: elements of this structure must match those of
165 * TMSimpleStateTreeRec and TMParseStateTreeRec.
166 */
167typedef struct _TMComplexStateTreeRec{
168    unsigned int	isSimple:1;
169    unsigned int	isAccelerator:1;
170    unsigned int	mappingNotifyInterest:1;
171    unsigned int	refCount:13;
172    TMShortCard		numBranchHeads;
173    TMShortCard		numQuarks;   /* # of entries in quarkTbl */
174    TMShortCard		numComplexBranchHeads;
175    TMBranchHeadRec	*branchHeadTbl;
176    XrmQuark		*quarkTbl;  /* table of quarkified rhs*/
177    StatePtr		*complexBranchHeadTbl;
178}TMComplexStateTreeRec, *TMComplexStateTree;
179
180/* NOTE: elements of this structure must match those of
181 * TMSimpleStateTreeRec and TMComplexStateTreeRec.
182 */
183typedef struct _TMParseStateTreeRec{
184    unsigned int	isSimple:1;
185    unsigned int	isAccelerator:1;
186    unsigned int	mappingNotifyInterest:1;
187    unsigned int	isStackQuarks:1;
188    unsigned int	isStackBranchHeads:1;
189    unsigned int	isStackComplexBranchHeads:1;
190    unsigned int	unused:10; /* to ensure correct alignment */
191    TMShortCard		numBranchHeads;
192    TMShortCard		numQuarks;   /* # of entries in quarkTbl */
193    TMShortCard		numComplexBranchHeads;
194    TMBranchHeadRec	*branchHeadTbl;
195    XrmQuark		*quarkTbl;  /* table of quarkified rhs*/
196    StatePtr		*complexBranchHeadTbl;
197    TMShortCard		branchHeadTblSize;
198    TMShortCard		quarkTblSize; /*total size of quarkTbl */
199    TMShortCard		complexBranchHeadTblSize;
200    StatePtr		head;
201}TMParseStateTreeRec, *TMParseStateTree;
202
203typedef union _TMStateTreeRec{
204    TMSimpleStateTreeRec	simple;
205    TMParseStateTreeRec		parse;
206    TMComplexStateTreeRec	complex;
207}*TMStateTree, **TMStateTreePtr, **TMStateTreeList;
208
209typedef struct _TMSimpleBindProcsRec {
210    XtActionProc	*procs;
211}TMSimpleBindProcsRec, *TMSimpleBindProcs;
212
213typedef struct _TMComplexBindProcsRec {
214    Widget	 	widget;		/*widgetID to pass to action Proc*/
215    XtTranslations	aXlations;
216    XtActionProc	*procs;
217}TMComplexBindProcsRec, *TMComplexBindProcs;
218
219typedef struct _TMSimpleBindDataRec {
220    unsigned int		isComplex:1;	/* must be first */
221    TMSimpleBindProcsRec	bindTbl[1];	/* variable length */
222}TMSimpleBindDataRec, *TMSimpleBindData;
223
224typedef struct _TMComplexBindDataRec {
225    unsigned int		isComplex:1;	/* must be first */
226    struct _ATranslationData	*accel_context;	/* for GetValues */
227    TMComplexBindProcsRec	bindTbl[1]; 	/* variable length */
228}TMComplexBindDataRec, *TMComplexBindData;
229
230typedef union _TMBindDataRec{
231    TMSimpleBindDataRec		simple;
232    TMComplexBindDataRec	complex;
233}*TMBindData;
234
235typedef struct _TranslationData{
236    unsigned char		hasBindings;	/* must be first */
237    unsigned char		operation; /*replace,augment,override*/
238    TMShortCard			numStateTrees;
239    struct _TranslationData    	*composers[2];
240    EventMask			eventMask;
241    TMStateTree			stateTreeTbl[1]; /* variable length */
242}TranslationData;
243
244/*
245 * ATranslations is returned by GetValues for translations that contain
246 * accelerators.  The TM can differentiate between this and TranslationData
247 * (that don't have a bindTbl) by looking at the first field (hasBindings)
248 * of either structure.  All ATranslationData structures associated with a
249 * widget are chained off the BindData record of the widget.
250 */
251typedef struct _ATranslationData{
252    unsigned char		hasBindings;	/* must be first */
253    unsigned char		operation;
254    struct _TranslationData	*xlations;  /* actual translations */
255    struct _ATranslationData	*next;      /* chain the contexts together */
256    TMComplexBindProcsRec	bindTbl[1]; /* accelerator bindings */
257}ATranslationData, *ATranslations;
258
259typedef struct _TMConvertRec {
260    XtTranslations	old; /* table to merge into */
261    XtTranslations	new; /* table to merge from */
262} TMConvertRec;
263
264#define _XtEventTimerEventType ((TMLongCard)~0L)
265#define KeysymModMask		(1L<<27) /* private to TM */
266#define AnyButtonMask		(1L<<28) /* private to TM */
267
268typedef struct _EventRec {
269    TMLongCard modifiers;
270    TMLongCard modifierMask;
271    LateBindingsPtr lateModifiers;
272    TMLongCard eventType;
273    TMLongCard eventCode;
274    TMLongCard eventCodeMask;
275    MatchProc matchEvent;
276    Boolean standard;
277} Event;
278
279typedef struct _EventSeqRec *EventSeqPtr;
280typedef struct _EventSeqRec {
281    Event event;	/* X event description */
282    StatePtr state;	/* private to state table builder */
283    EventSeqPtr next;	/* next event on line */
284    ActionPtr actions;	/* r.h.s.   list of actions to perform */
285} EventSeqRec;
286
287typedef EventSeqRec EventRec;
288typedef EventSeqPtr EventPtr;
289
290typedef struct _TMEventRec {
291    XEvent *xev;
292    Event event;
293}TMEventRec;
294
295typedef struct _ActionHookRec {
296    struct _ActionHookRec* next; /* must remain first */
297    XtAppContext app;
298    XtActionHookProc proc;
299    XtPointer closure;
300} ActionHookRec, *ActionHook;
301
302/* choose a number between 2 and 8 */
303#define TMKEYCACHELOG2 6
304#define TMKEYCACHESIZE (1<<TMKEYCACHELOG2)
305
306typedef struct _KeyCacheRec {
307    unsigned char modifiers_return[256]; /* constant per KeyCode, key proc */
308    KeyCode keycode[TMKEYCACHESIZE];
309    unsigned char modifiers[TMKEYCACHESIZE];
310    KeySym keysym[TMKEYCACHESIZE];
311} TMKeyCache;
312
313typedef struct _TMKeyContextRec {
314    XEvent *event;
315    unsigned long serial;
316    KeySym keysym;
317    Modifiers modifiers;
318    TMKeyCache keycache;  /* keep this last, to keep offsets to others small */
319} TMKeyContextRec, *TMKeyContext;
320
321typedef struct _TMGlobalRec{
322    TMTypeMatchRec 		**typeMatchSegmentTbl;
323    TMShortCard			numTypeMatches;
324    TMShortCard			numTypeMatchSegments;
325    TMShortCard			typeMatchSegmentTblSize;
326    TMModifierMatchRec 		**modMatchSegmentTbl;
327    TMShortCard			numModMatches;
328    TMShortCard			numModMatchSegments;
329    TMShortCard			modMatchSegmentTblSize;
330    Boolean			newMatchSemantics;
331#ifdef TRACE_TM
332    XtTranslations		*tmTbl;
333    TMShortCard			numTms;
334    TMShortCard			tmTblSize;
335    struct _TMBindCacheRec	**bindCacheTbl;
336    TMShortCard			numBindCache;
337    TMShortCard			bindCacheTblSize;
338    TMShortCard			numLateBindings;
339    TMShortCard			numBranchHeads;
340    TMShortCard			numComplexStates;
341    TMShortCard			numComplexActions;
342#endif /* TRACE_TM */
343}TMGlobalRec;
344
345_XFUNCPROTOBEGIN
346
347extern TMGlobalRec _XtGlobalTM;
348
349#define TM_MOD_SEGMENT_SIZE 	16
350#define TM_TYPE_SEGMENT_SIZE 	16
351
352#define TMGetTypeMatch(idx) \
353  ((TMTypeMatch) \
354   &((_XtGlobalTM.typeMatchSegmentTbl[((idx) >> 4)])[(idx) & 15]))
355#define TMGetModifierMatch(idx) \
356  ((TMModifierMatch) \
357   &((_XtGlobalTM.modMatchSegmentTbl[(idx) >> 4])[(idx) & 15]))
358
359/* Useful Access Macros */
360#define TMNewMatchSemantics() (_XtGlobalTM.newMatchSemantics)
361#define TMBranchMore(branch) (branch->more)
362#define TMComplexBranchHead(tree, br) \
363  (((TMComplexStateTree)tree)->complexBranchHeadTbl[TMBranchMore(br)])
364
365#define TMGetComplexBindEntry(bindData, idx) \
366  ((TMComplexBindProcs)&(((TMComplexBindData)bindData)->bindTbl[idx]))
367
368#define TMGetSimpleBindEntry(bindData, idx) \
369  ((TMSimpleBindProcs)&(((TMSimpleBindData)bindData)->bindTbl[idx]))
370
371
372#define _InitializeKeysymTables(dpy, pd) \
373    if (pd->keysyms == NULL) \
374        _XtBuildKeysymTables(dpy, pd)
375
376/*
377 * Internal Functions
378 */
379
380extern void _XtPopup(
381    Widget      /* widget */,
382    XtGrabKind  /* grab_kind */,
383    _XtBoolean	/* spring_loaded */
384);
385
386extern String _XtPrintXlations(
387    Widget		/* w */,
388    XtTranslations 	/* xlations */,
389    Widget		/* accelWidget */,
390    _XtBoolean		/* includeRHS */
391);
392
393extern void _XtRegisterGrabs(
394    Widget	/* widget */
395);
396
397extern XtPointer _XtInitializeActionData(
398    struct _XtActionsRec *	/* actions */,
399    Cardinal 			/* count */,
400    _XtBoolean			/* inPlace */
401);
402
403extern void _XtAddEventSeqToStateTree(
404    EventSeqPtr		/* eventSeq */,
405    TMParseStateTree	/* stateTree */
406);
407
408extern Boolean _XtMatchUsingStandardMods(
409    TMTypeMatch		/* typeMatch */,
410    TMModifierMatch	/* modMatch */,
411    TMEventPtr		/* eventSeq */
412);
413
414extern Boolean _XtMatchUsingDontCareMods(
415    TMTypeMatch		/* typeMatch */,
416    TMModifierMatch	/* modMatch */,
417    TMEventPtr		/* eventSeq */
418);
419
420extern Boolean _XtRegularMatch(
421    TMTypeMatch		/* typeMatch */,
422    TMModifierMatch	/* modMatch */,
423    TMEventPtr		/* eventSeq */
424);
425
426extern Boolean _XtMatchAtom(
427    TMTypeMatch		/* typeMatch */,
428    TMModifierMatch	/* modMatch */,
429    TMEventPtr		/* eventSeq */
430);
431
432extern void _XtTranslateEvent(
433    Widget		/* widget */,
434    XEvent*		/* event */
435);
436
437#include "CallbackI.h"
438#include "EventI.h"
439#include "HookObjI.h"
440#include "PassivGraI.h"
441#include "ThreadsI.h"
442#include "InitialI.h"
443#include "ResourceI.h"
444#include "StringDefs.h"
445
446extern void _XtBuildKeysymTables(Display *dpy, XtPerDisplay pd);
447
448#ifndef NO_MIT_HACKS
449extern void  _XtDisplayTranslations(
450    Widget		/* widget */,
451    XEvent*		/* event */,
452    String*		/* params */,
453    Cardinal*		/* num_params */
454);
455
456extern void  _XtDisplayAccelerators(
457    Widget		/* widget */,
458    XEvent*		/* event */,
459    String*		/* params */,
460    Cardinal*		/* num_params */
461);
462
463extern void _XtDisplayInstalledAccelerators(
464    Widget		/* widget */,
465    XEvent*		/* event */,
466    String*		/* params */,
467    Cardinal*		/* num_params */
468);
469#endif /* ifndef NO_MIT_HACKS */
470
471extern void _XtPopupInitialize(
472    XtAppContext	/* app_context */
473);
474
475extern void _XtBindActions(
476    Widget	/* widget */,
477    XtTM 	/* tm_rec */
478);
479
480extern Boolean _XtComputeLateBindings(
481    Display*		/* dpy */,
482    LateBindingsPtr	/* lateModifiers */,
483    Modifiers*		/* computed */,
484    Modifiers*		/* computedMask */
485);
486
487extern XtTranslations _XtCreateXlations(
488    TMStateTree *	/* stateTrees */,
489    TMShortCard		/* numStateTrees */,
490    XtTranslations 	/* first */,
491    XtTranslations	/* second */
492);
493
494extern Boolean _XtCvtMergeTranslations(
495    Display*	/* dpy */,
496    XrmValuePtr	/* args */,
497    Cardinal*	/* num_args */,
498    XrmValuePtr	/* from */,
499    XrmValuePtr	/* to */,
500    XtPointer*	/* closure_ret */
501);
502
503void _XtRemoveStateTreeByIndex(
504    XtTranslations	/* xlations */,
505    TMShortCard	/* i */);
506
507void _XtFreeTranslations(
508    XtAppContext	/* app */,
509    XrmValuePtr		/* toVal */,
510    XtPointer		/* closure */,
511    XrmValuePtr		/* args */,
512    Cardinal*		/* num_args */
513);
514
515extern TMShortCard _XtGetModifierIndex(
516    Event*	/* event */
517);
518
519extern TMShortCard _XtGetQuarkIndex(
520    TMParseStateTree	/* stateTreePtr */,
521    XrmQuark		/* quark */
522);
523
524extern XtTranslations _XtGetTranslationValue(
525    Widget		/* widget */
526);
527
528extern TMShortCard _XtGetTypeIndex(
529    Event*	/* event */
530);
531
532extern void _XtGrabInitialize(
533    XtAppContext	/* app */
534);
535
536extern void _XtInstallTranslations(
537    Widget		/* widget */
538);
539
540extern void _XtRemoveTranslations(
541    Widget		/* widget */
542);
543
544extern void _XtDestroyTMData(
545    Widget		/* widget */
546);
547
548extern void _XtMergeTranslations(
549    Widget		/* widget */,
550    XtTranslations	/* newXlations */,
551    _XtTranslateOp	/* operation */
552);
553
554extern void _XtActionInitialize(
555    XtAppContext	/* app */
556);
557
558extern TMStateTree _XtParseTreeToStateTree(
559    TMParseStateTree 	/* parseTree */
560);
561
562extern String _XtPrintActions(
563    ActionRec*	/* actions */,
564    XrmQuark*	/* quarkTbl */
565);
566
567extern String _XtPrintState(
568    TMStateTree	/* stateTree */,
569    TMBranchHead /* branchHead */);
570
571extern String _XtPrintEventSeq(
572    EventSeqPtr	/* eventSeq */,
573    Display*	/* dpy */
574);
575
576typedef Boolean (*_XtTraversalProc)(
577    StatePtr	/* state */,
578    XtPointer	/* data */
579);
580
581extern void _XtTraverseStateTree(
582    TMStateTree		/* tree */,
583    _XtTraversalProc	/* func */,
584    XtPointer		/* data */
585);
586
587extern void _XtTranslateInitialize(
588    void
589);
590
591extern void _XtAddTMConverters(
592    ConverterTable	/* table */
593);
594
595extern void _XtUnbindActions(
596    Widget		/* widget */,
597    XtTranslations	/* xlations */,
598    TMBindData		/* bindData */
599);
600
601extern void _XtUnmergeTranslations(
602    Widget		/* widget */,
603    XtTranslations 	/* xlations */
604);
605
606/* TMKey.c */
607extern void _XtAllocTMContext(XtPerDisplay pd);
608
609_XFUNCPROTOEND
610