Source Code (Use browser search to find items of interest.)

Class Index

klyx'kb_sequence (./klyx/src/kbmap.h:83)

class kb_sequence {
public:
	///
	kb_sequence() {
		stdmap = curmap = 0;
		sequence = staticseq;
		modifiers = staticmod;
		length = 0; 
		size = KB_PREALLOC;
	}
	
	///
	
	
	///
	~kb_sequence()
	{
		if (sequence != staticseq) {
			delete sequence;
			delete modifiers;
		}
	}
	
	/// Add a key to the key sequence and look it up in the curmap
	/** Add a key to the key sequence and look it up in the curmap
	  if the latter is defined. */
	int addkey(KeySym key, unsigned mod, unsigned nmod = 0);
	
	///
	int print(char *buf, int maxlen, bool when_defined = false) const; //RVDK_PATCH_5
	
        ///
	int printOptions(char *buf, int maxlen) const;
	
	/// Make length negative to mark the sequence as deleted
	void delseq();
	
	///
	char getiso();
	
	///
	KeySym getsym();
	
	///
	void reset();
	
	///
	int parse(char const *s);
	
	/// Keymap to use if a new sequence is starting
	kb_keymap *stdmap;
	
	/// Keymap to use for the next key
	kb_keymap *curmap;
	
	/// Array holding the current key sequence
	/** If sequence[length-1] < 0xff it can be used as ISO8859 char */
	unsigned int *sequence;
	
	///
	unsigned int *modifiers;
	
	/// Current length of key sequence
	int length;
	
private:
	/// Static array preallocated for sequence
	unsigned int staticseq[KB_PREALLOC];
	
	///
	unsigned int staticmod[KB_PREALLOC];
	
	/// Physically allocated storage size
	int size;
};

klyx'kb_sequence::addkey() (./klyx/src/kbmap.C:132)

int kb_sequence::addkey(KeySym key, unsigned int mod, unsigned int nmod /*=0*/)
{
	if(length<0) length=0;

	if(length+1 >= size) {
		unsigned int *nseq = new unsigned int[size+KB_PREALLOC];
		size += KB_PREALLOC;
		memcpy(nseq, sequence, length*sizeof(unsigned int));
		if(sequence != staticseq) delete sequence;
		sequence = nseq;
		nseq = new unsigned int[size];
		memcpy(nseq, modifiers, length*sizeof(unsigned int));
		if(modifiers != staticmod) delete modifiers;
		modifiers = nseq;
	}

	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------------------------------------------------------------------- */


klyx'kb_sequence::parse() (./klyx/src/kbmap.C:169)

int kb_sequence::parse(char const*s)
{
	int i = 0;
	unsigned int mod = 0, nmod = 0;
	KeySym key = 0;
	char tbuf[100];
	
	if(!s[0]) return 1;
	
	while(s[i]) {
		if(s[i] && ((unsigned char) s[i]) <= ' ') i++;
		if(!s[i]) break;
		
		if(s[i+1]=='-')	{ // is implicit that s[i]==true
			switch(s[i]) {
			case 's': case 'S':
				mod |= ShiftMask;
				i+=2;
				continue;
			case 'c': case 'C':
				mod |= ControlMask;
				i+=2;
				continue;
			case 'm': case 'M':
				mod |= Mod1Mask;
				i+=2;
				continue;
			default:
				return i+1;
			}
		} else if(s[i]=='~' && s[i+1] && s[i+2]=='-') {
			switch(s[i+1]) {
			case 's': case 'S':
				nmod |= ShiftMask;
				i+=3;
				continue;
			case 'c': case 'C':
				nmod |= ControlMask;
				i+=3;
				continue;
			case 'm': case 'M':
				nmod |= Mod1Mask;
				i+=3;
				continue;
			default:
				return i+2;
			}
		} else {
			int j = 0;
			for(j = i; s[j] && ((unsigned char)s[j])>' '; j++)
				tbuf[j-i] = s[j];    // (!!!check bounds :-)
			
			tbuf[j-i] = '\0';
         
			key = XStringToKeysym(tbuf);
			if(key == NoSymbol) {
				lyxerr.debug("kbmap.C: No such keysym: "
					     + LString(tbuf),Error::KBMAP);
				return j;
			}
			i = j;
			
			addkey(key, mod, nmod);
			mod = 0;
			nmod = 0;
		}
	}
	return 0;
}


/* ---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------------------------------------------------------------------- */


klyx'kb_sequence::print() (./klyx/src/kbmap.C:250)

int kb_sequence::print(char *buf, int maxlen, bool when_defined) const
{
	KeySym key;
	unsigned int 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;

		len = printKeysym( key, mod, buf, maxlen );  // RVDK_PATCH_5
		buf += len;
		maxlen -= len;
		
		if ( len == 0 ) {
			*buf = '\0';
			return -1;
		}

		if(i+1<l && maxlen>1) {  // append a blank
			*buf++ = ' ';
			maxlen--;
		}
	}
	*buf = '\0';
	return 0;
}


/* ---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------------------------------------------------------------------- */


klyx'kb_sequence::printOptions() (./klyx/src/kbmap.C:291)

int kb_sequence::printOptions(char *buf, int maxlen) const
{
	int len;

	print( buf, maxlen, true );
	len = strlen( buf );
	maxlen -= len;
	buf    += len;
	
	if ( maxlen < 20 || !curmap ) return -1;

 	char s[20];
 	strcpy(s, i18n("   options: "));
 	strcpy( buf, s);
 	buf += strlen(s);
 	maxlen -= strlen(s);

	curmap->print(buf, maxlen);
	return 0;
}


/* ---F+------------------------------------------------------------------ *\
    Function  : kb_sequence::delseq
    Called by : [user]
    Purpose   : mark the sequence as deleted
    Parameters: none
    Returns   : nothing
\* ---F------------------------------------------------------------------- */


klyx'kb_sequence::delseq() (./klyx/src/kbmap.C:321)

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------------------------------------------------------------------- */


klyx'kb_sequence::getsym() (./klyx/src/kbmap.C:337)

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------------------------------------------------------------------- */


klyx'kb_sequence::getiso() (./klyx/src/kbmap.C:354)

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------------------------------------------------------------------- */


klyx'kb_sequence::reset() (./klyx/src/kbmap.C:372)

void kb_sequence::reset()
{
	delseq();
	curmap = stdmap;
	if ( length > 0 ) length = -length;
}


// === kb_keymap methods ==================================================

// This binds a key to an action