XlAsciiImpl.mesa
Copyright Ó 1991, 1992 by Xerox Corporation. All rights reserved.
Christian Jacobi, March 29, 1991 1:12:40 pm PST
Christian Jacobi, February 27, 1992 1:23 pm PST
DIRECTORY
Ascii,
KeyChars,
KeySymsKB,
KeyMapping,
Xl,
XlAscii;
XlAsciiImpl: CEDAR MONITOR
IMPORTS Ascii, KeyChars, KeyMapping, Xl
EXPORTS XlAscii ~
BEGIN
nullKeySym: Xl.KeySym ~ [0];
AsciiFromKeySym: PUBLIC PROC [keysym: Xl.KeySym] RETURNS [char: CHAR ¬ 0C] = {
char ¬ KeyChars.CharFromKeySym[keysym];
IF char>VAL[127] THEN char ¬ 0C;
};
KeySymFromAscii: PUBLIC PROC [char: CHAR] RETURNS [keysym: Xl.KeySym] = {
keysym ¬ KeyChars.KeySymFromChar[char];
};
Convert: PUBLIC PROC [connection: Xl.Connection, keyCode: Xl.KeyCode, state: Xl.SetOfKeyButMask ¬ [], matchKeys: LIST OF Xl.KeySym ¬ NIL] RETURNS [char: CHAR ¬ 0C, keysym: Xl.KeySym ¬ [0], matched: Xl.KeySym ¬ [0], isModifier: BOOL ¬ FALSE] = {
modmap: Xl.ModifierMapping ¬ Xl.GetModifierMapping[connection];
mapping: Xl.KeyboardMapping ¬ Xl.GetKeyboardMapping[connection];
FOR m: Xl.KeyBut IN [shift..mod5] DO
IF modmap[0][m]=keyCode THEN {isModifier ¬ TRUE; EXIT};
ENDLOOP;
IF isModifier
THEN {
keysym ¬ KeyMapping.GetKeySym[mapping, keyCode, 0];
char ¬ AsciiFromKeySym[keysym];
}
ELSE {
ks0: Xl.KeySym ¬ KeyMapping.GetKeySym[mapping, keyCode, 0];
ks1: Xl.KeySym ¬ KeyMapping.GetKeySym[mapping, keyCode, 1];
ks2: Xl.KeySym ¬ KeyMapping.GetKeySym[mapping, keyCode, 2];
ks3: Xl.KeySym ¬ KeyMapping.GetKeySym[mapping, keyCode, 3];
FOR list: LIST OF Xl.KeySym ¬ matchKeys, list.rest WHILE list #NIL DO
SELECT list.first FROM
ks0, ks1, ks2, ks3 => {matched ¬ list.first; EXIT};
ENDCASE => {};
ENDLOOP;
SELECT TRUE FROM
state.control AND state.shift => {
keysym ¬ ks3;
IF keysym=nullKeySym THEN {
keysym ¬ ks1;
IF keysym=nullKeySym THEN keysym ¬ ks0;
};
char ¬ AsciiFromKeySym[ks1];
char ¬ Ascii.Control[char];
};
state.control => {
keysym ¬ ks2;
IF keysym=nullKeySym THEN keysym ¬ ks0;
char ¬ AsciiFromKeySym[ks0];
char ¬ Ascii.Control[char];
};
state.shift => {
keysym ¬ ks1;
IF keysym#nullKeySym
THEN char ¬ AsciiFromKeySym[ks1]
ELSE {
char ¬ AsciiFromKeySym[ks0];
char ¬ Ascii.Upper[char];
keysym ¬ KeySymFromAscii[char];
};
};
state.lock => {
char1: CHAR ¬ AsciiFromKeySym[ks0];
char ¬ Ascii.Upper[char1];
keysym ¬ IF char1=char THEN ks0 ELSE ks1;
};
ENDCASE => {
char1: CHAR ¬ AsciiFromKeySym[ks0];
keysym ¬ ks0;
char ¬ Ascii.Lower[char1];
IF char#char1 THEN {
keysym ¬ KeySymFromAscii[char];
};
};
};
};
END.