/* This file is part of * ====================================================== * * LyX, The Document Processor * * Copyright (C) 1995 Matthias Ettrich * Copyright (C) 1995-1998 The LyX Team. *
*======================================================*/
/* ---F+------------------------------------------------------------------ *\ Function : printKeysym Called by : kb_sequence::print and printKeyMap. RVDK_PATCH_5 Purpose : prints a keysym, including modifiers. Parameters: key - keysym mod - modifiers buf - string where the result goes maxlen - length of string (including '\0') Returns : length of printed string if ok, 0 otherwise.
\* ---F------------------------------------------------------------------- */
static int printKeysym( KeySym key, unsignedint mod, char *buf, int maxlen )
{ int len; char *s;
mod &= ModsMask;
// calc required length;
len = 0; if ( mod & ShiftMask ) len += 2; if ( mod & ControlMask ) len += 2; if ( mod & Mod1Mask ) len += 2;
s = XKeysymToString( key ); if ( s ) len += strlen( s ); if ( len < maxlen ) { if ( mod & ShiftMask ) {
*buf++ = 'S'; *buf++ = '-'; } if ( mod & ControlMask ) {
*buf++ = 'C'; *buf++ = '-'; } if ( mod & Mod1Mask ) {
*buf++ = 'M'; *buf++ = '-'; } if ( s ) strcpy( buf, s ); return len;
} else return 0;
}
/* ---F+------------------------------------------------------------------ *\ Function : printKeyTab Called by : kb_keymap::print Purpose : print the keysyms found in the given key table. RVDK_PATCH_5 Parameters: tabPt - keytable pointer buf - string where the result goes maxLen - length of string (including '\0') Returns : length of printed string.
\* ---F------------------------------------------------------------------- */
static int printKeyTab( kb_key *tabPt, char *buf, int maxLen )
{ int len, doneLen = 0; unsignedint ksym, mod;
/* -------> Print each of the slots into buf. */ for( ; (tabPt->code & 0xffff) != NoSymbol; tabPt++) { if ( maxLen <= 0 ) break;
ksym = tabPt->code;
mod = tabPt->mod & 0xffff;
len = printKeysym( ksym, mod, buf, maxLen ); if ( len <= 0 ) break;
buf += len;
maxLen -= len;
doneLen += len;
/* -------> Add space when possible. */ if ( maxLen > 0 ) {
*buf++ = ' ';
*buf = '\0';
maxLen--;
doneLen++;
}
} return doneLen;
}
/* ---F+------------------------------------------------------------------ *\ Function : kb_sequence::addkey Called by : [user] Purpose : add a key to the sequence, look up in map and return action Parameters: key - keysym of key mod - modifier mask nmod - modifier veto mask (unused now) Returns : action or -1 if error (no map defined or key not found)
\* ---F------------------------------------------------------------------- */
modifiers[length] = mod + (nmod<<16);
sequence[length++] = key;
if(curmap) return curmap->lookup(key, mod, this);
return -1;
}
/* ---F+------------------------------------------------------------------ *\ Function : kb_sequence::parse Called by : [user] Purpose : parse a string that holds a key sequence and add the keys Parameters: s - string holding the key sequence Returns : 0 - if ok, error pos if error Note : Keys must be separated with whitespace; Use the keysym names used by XStringToKeysym Prefixes are S-, C-, M- for shift, control, meta
\* ---F------------------------------------------------------------------- */
int kb_sequence::parse(charconst*s)
{ int i = 0; unsignedint mod = 0, nmod = 0;
KeySym key = 0; char tbuf[100];
/* ---F+------------------------------------------------------------------ *\ Function : kb_sequence::print Called by : [user] Purpose : print the currently defined sequence into a string Parameters: buf - string where the result goes maxlen - length of string (including '\0') when_defined - only print when sequence is real: length > 0. Returns : 0, if ok, -1 if string too long
\* ---F------------------------------------------------------------------- */
int kb_sequence::print(char *buf, int maxlen, bool when_defined) const
{
KeySym key; unsignedint mod; int len; int l = length; if ( l<0 && !when_defined ) l = -l;
for(int i = 0; i < l; i++) {
key = sequence[i];
mod = modifiers[i] & 0xffff;
/* ---F+------------------------------------------------------------------ *\ Function : kb_sequence::printOptions Called by : [user] Purpose : print the available key options from the current state in the sequence. RVDK_PATCH_5 Parameters: buf - string where the result goes maxlen - length of string (including '\0') Returns : 0, if ok, -1 if string too long
\* ---F------------------------------------------------------------------- */
int kb_sequence::printOptions(char *buf, int maxlen) const
{ int len;
/* ---F+------------------------------------------------------------------ *\ Function : kb_sequence::delseq Called by : [user] Purpose : mark the sequence as deleted Parameters: none Returns : nothing
\* ---F------------------------------------------------------------------- */
void kb_sequence::delseq()
{ // negative length marks sequence as deleted, but we can still // print() it or retrieve the last char using getiso()
length = -length;
}
/* ---F+------------------------------------------------------------------ *\ Function : kb_sequence::getsym Called by : [user], getiso Purpose : get the keysym of the last key in sequence Parameters: none Returns : keysym
\* ---F------------------------------------------------------------------- */
KeySym kb_sequence::getsym()
{ int l = length; if(l==0) return NoSymbol; if(l<0) l = -l; return sequence[l-1];
}
/* ---F+------------------------------------------------------------------ *\ Function : kb_sequence::getiso Called by : [user] Purpose : return iso character code of last key, if any Parameters: none Returns : iso code or 0 if none
\* ---F------------------------------------------------------------------- */
char kb_sequence::getiso()
{ int c = getsym();
if(c > 0xff) return'\0'; return (char)c;
}
/* ---F+------------------------------------------------------------------ *\ Function : kb_sequence::reset Called by : [user] Purpose : reset sequence to initial state. RVDK_PATCH_5 Parameters: none Returns : void
\* ---F------------------------------------------------------------------- */
// This binds a key to an action int kb_keymap::bind(charconst *seq, int action)
{
kb_sequence k;
int res = k.parse(seq); if (!res) {
defkey(&k, action);
} else
lyxerr.debug(LString("Parse error at position ") + res + " in key sequence '" + seq + "'.", Error::KBMAP); return res;
}
/* ---F+------------------------------------------------------------------ *\ Function : kb_keymap::lookup Called by : [user], kb_sequence::add() Purpose : look up a key press in a given keymap Parameters: key - the keysym of the key press mod - the modifier mask of the keypress seq - the key-sequence retrieved so far Returns : user defined action; 0 for prefix key, -1 if key not found
\* ---F------------------------------------------------------------------- */
/* ---F+------------------------------------------------------------------ *\ Function : kb_keymap::print Called by : [user] Purpose : Prints all the available keysyms. RVDK_PATCH_5 Parameters: buf - string where output goes. maxLen - available length in string, including `\0'. Returns : updated maxLen.
\* ---F------------------------------------------------------------------- */
int kb_keymap::print(char *buf, int maxLen) const
{ int len;
/* -----> Return when running out of string space or when keymap has no table.
Else, place a terminating newline in case no other output is generated. */
if ( maxLen <= 3 || !buf ) return maxLen; if ( !table ) return maxLen;
*buf = '\0';
/* -------> Hash table. Process each of its slots recursively and return. */ if ( size < 0 ) { for ( int ix = 0; (ix < KB_HASHSIZE) && (maxLen > 1); ix++ ) { if ( htable[ix] ) {
len = printKeyTab( htable[ix], buf, maxLen );
maxLen -= len;
buf += len;
}
}
} else { /* -------> Normal table. */
len = printKeyTab( table, buf, maxLen );
maxLen -= len;
buf += len;
} return maxLen;
}
/* ---F+------------------------------------------------------------------ *\ Function : kb_keymap::defkey Called by : [user] Purpose : define an action for a key sequence Parameters: seq - the key sequence action - the action to be defined idx - recursion depth Returns : 0 if ok.
\* ---F------------------------------------------------------------------- */
int kb_keymap::defkey(kb_sequence *seq, int action, int idx /*=0*/)
{ int tsize; unsignedint code, modmsk;
kb_key *tab, **ptab;
// --- define rest of sequence --------------------------------------
if(idx+1 == seq->length) {
newone->action = action;
newone->table = 0; return 0;
} else {
newone->table = new kb_keymap; int res = newone->table->defkey(seq, action, idx+1); return res;
}
}
/* ---F+------------------------------------------------------------------ *\ Function : kb_keymap::~kb_keymap Called by : [destructor] Purpose : free keymap and its descendents Parameters: none Returns : nothing
\* ---F------------------------------------------------------------------- */
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.