TranslateI.h revision 444c061a
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
345extern TMGlobalRec _XtGlobalTM;
346
347#define TM_MOD_SEGMENT_SIZE 	16
348#define TM_TYPE_SEGMENT_SIZE 	16
349
350#define TMGetTypeMatch(idx) \
351  ((TMTypeMatch) \
352   &((_XtGlobalTM.typeMatchSegmentTbl[((idx) >> 4)])[(idx) & 15]))
353#define TMGetModifierMatch(idx) \
354  ((TMModifierMatch) \
355   &((_XtGlobalTM.modMatchSegmentTbl[(idx) >> 4])[(idx) & 15]))
356
357/* Useful Access Macros */
358#define TMNewMatchSemantics() (_XtGlobalTM.newMatchSemantics)
359#define TMBranchMore(branch) (branch->more)
360#define TMComplexBranchHead(tree, br) \
361  (((TMComplexStateTree)tree)->complexBranchHeadTbl[TMBranchMore(br)])
362
363#define TMGetComplexBindEntry(bindData, idx) \
364  ((TMComplexBindProcs)&(((TMComplexBindData)bindData)->bindTbl[idx]))
365
366#define TMGetSimpleBindEntry(bindData, idx) \
367  ((TMSimpleBindProcs)&(((TMSimpleBindData)bindData)->bindTbl[idx]))
368
369
370#define _InitializeKeysymTables(dpy, pd) \
371    if (pd->keysyms == NULL) \
372        _XtBuildKeysymTables(dpy, pd)
373
374/*
375 * Internal Functions
376 */
377
378extern void _XtPopup(
379    Widget      /* widget */,
380    XtGrabKind  /* grab_kind */,
381    _XtBoolean	/* spring_loaded */
382);
383
384extern String _XtPrintXlations(
385    Widget		/* w */,
386    XtTranslations 	/* xlations */,
387    Widget		/* accelWidget */,
388    _XtBoolean		/* includeRHS */
389);
390
391extern void _XtRegisterGrabs(
392    Widget	/* widget */
393);
394
395extern XtPointer _XtInitializeActionData(
396    struct _XtActionsRec *	/* actions */,
397    Cardinal 			/* count */,
398    _XtBoolean			/* inPlace */
399);
400
401extern void _XtAddEventSeqToStateTree(
402    EventSeqPtr		/* eventSeq */,
403    TMParseStateTree	/* stateTree */
404);
405
406extern Boolean _XtMatchUsingStandardMods(
407    TMTypeMatch		/* typeMatch */,
408    TMModifierMatch	/* modMatch */,
409    TMEventPtr		/* eventSeq */
410);
411
412extern Boolean _XtMatchUsingDontCareMods(
413    TMTypeMatch		/* typeMatch */,
414    TMModifierMatch	/* modMatch */,
415    TMEventPtr		/* eventSeq */
416);
417
418extern Boolean _XtRegularMatch(
419    TMTypeMatch		/* typeMatch */,
420    TMModifierMatch	/* modMatch */,
421    TMEventPtr		/* eventSeq */
422);
423
424extern Boolean _XtMatchAtom(
425    TMTypeMatch		/* typeMatch */,
426    TMModifierMatch	/* modMatch */,
427    TMEventPtr		/* eventSeq */
428);
429
430extern void _XtTranslateEvent(
431    Widget		/* widget */,
432    XEvent*		/* event */
433);
434
435#include "CallbackI.h"
436#include "EventI.h"
437#include "HookObjI.h"
438#include "PassivGraI.h"
439#include "ThreadsI.h"
440#include "InitialI.h"
441#include "ResourceI.h"
442#include "StringDefs.h"
443
444extern void _XtBuildKeysymTables(Display *dpy, XtPerDisplay pd);
445
446#ifndef NO_MIT_HACKS
447extern void  _XtDisplayTranslations(
448    Widget		/* widget */,
449    XEvent*		/* event */,
450    String*		/* params */,
451    Cardinal*		/* num_params */
452);
453
454extern void  _XtDisplayAccelerators(
455    Widget		/* widget */,
456    XEvent*		/* event */,
457    String*		/* params */,
458    Cardinal*		/* num_params */
459);
460
461extern void _XtDisplayInstalledAccelerators(
462    Widget		/* widget */,
463    XEvent*		/* event */,
464    String*		/* params */,
465    Cardinal*		/* num_params */
466);
467#endif /* ifndef NO_MIT_HACKS */
468
469extern void _XtPopupInitialize(
470    XtAppContext	/* app_context */
471);
472
473extern void _XtBindActions(
474    Widget	/* widget */,
475    XtTM 	/* tm_rec */
476);
477
478extern Boolean _XtComputeLateBindings(
479    Display*		/* dpy */,
480    LateBindingsPtr	/* lateModifiers */,
481    Modifiers*		/* computed */,
482    Modifiers*		/* computedMask */
483);
484
485extern XtTranslations _XtCreateXlations(
486    TMStateTree *	/* stateTrees */,
487    TMShortCard		/* numStateTrees */,
488    XtTranslations 	/* first */,
489    XtTranslations	/* second */
490);
491
492extern Boolean _XtCvtMergeTranslations(
493    Display*	/* dpy */,
494    XrmValuePtr	/* args */,
495    Cardinal*	/* num_args */,
496    XrmValuePtr	/* from */,
497    XrmValuePtr	/* to */,
498    XtPointer*	/* closure_ret */
499);
500
501void _XtRemoveStateTreeByIndex(
502    XtTranslations	/* xlations */,
503    TMShortCard	/* i */);
504
505void _XtFreeTranslations(
506    XtAppContext	/* app */,
507    XrmValuePtr		/* toVal */,
508    XtPointer		/* closure */,
509    XrmValuePtr		/* args */,
510    Cardinal*		/* num_args */
511);
512
513extern TMShortCard _XtGetModifierIndex(
514    Event*	/* event */
515);
516
517extern TMShortCard _XtGetQuarkIndex(
518    TMParseStateTree	/* stateTreePtr */,
519    XrmQuark		/* quark */
520);
521
522extern XtTranslations _XtGetTranslationValue(
523    Widget		/* widget */
524);
525
526extern TMShortCard _XtGetTypeIndex(
527    Event*	/* event */
528);
529
530extern void _XtGrabInitialize(
531    XtAppContext	/* app */
532);
533
534extern void _XtInstallTranslations(
535    Widget		/* widget */
536);
537
538extern void _XtRemoveTranslations(
539    Widget		/* widget */
540);
541
542extern void _XtDestroyTMData(
543    Widget		/* widget */
544);
545
546extern void _XtMergeTranslations(
547    Widget		/* widget */,
548    XtTranslations	/* newXlations */,
549    _XtTranslateOp	/* operation */
550);
551
552extern void _XtActionInitialize(
553    XtAppContext	/* app */
554);
555
556extern TMStateTree _XtParseTreeToStateTree(
557    TMParseStateTree 	/* parseTree */
558);
559
560extern String _XtPrintActions(
561    ActionRec*	/* actions */,
562    XrmQuark*	/* quarkTbl */
563);
564
565extern String _XtPrintState(
566    TMStateTree	/* stateTree */,
567    TMBranchHead /* branchHead */);
568
569extern String _XtPrintEventSeq(
570    EventSeqPtr	/* eventSeq */,
571    Display*	/* dpy */
572);
573
574typedef Boolean (*_XtTraversalProc)(
575    StatePtr	/* state */,
576    XtPointer	/* data */
577);
578
579extern void _XtTraverseStateTree(
580    TMStateTree		/* tree */,
581    _XtTraversalProc	/* func */,
582    XtPointer		/* data */
583);
584
585extern void _XtTranslateInitialize(
586    void
587);
588
589extern void _XtAddTMConverters(
590    ConverterTable	/* table */
591);
592
593extern void _XtUnbindActions(
594    Widget		/* widget */,
595    XtTranslations	/* xlations */,
596    TMBindData		/* bindData */
597);
598
599extern void _XtUnmergeTranslations(
600    Widget		/* widget */,
601    XtTranslations 	/* xlations */
602);
603
604/* TMKey.c */
605extern void _XtAllocTMContext(XtPerDisplay pd);
606
607