X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fkbsequence.h;h=e00382d34edb58e13938541f940c2fe2eef5e22c;hb=98c966c64594611e469313314abd1e59524adb4a;hp=87265b74f94b0fc118cb9d0e5deaffcc744d1ddb;hpb=45a03f4f67bb00f8142e465c615f348f0622eb32;p=lyx.git diff --git a/src/kbsequence.h b/src/kbsequence.h index 87265b74f9..e00382d34e 100644 --- a/src/kbsequence.h +++ b/src/kbsequence.h @@ -1,10 +1,9 @@ // -*- C++ -*- -/* ======================================================================= *\ - File : kbmap.h, kbmap.h,v 1.3 1996/12/10 04:35:57 larsbj Exp - Author : chb, 30.Oct.1995 - Docu : see kbmap.C - Purpose: class definitions for XKeyEvent keymap handling - \* ==================================================================== */ +/** + * \file kbsequence.h + * Copyright 2001 the LyX Team + * Read the file COPYING + */ #ifndef KBSEQUENCE_H #define KBSEQUENCE_H @@ -13,82 +12,98 @@ #pragma interface #endif +#include #include "LString.h" -#define KB_PREALLOC 16 - class kb_keymap; /// Holds a key sequence and the current and standard keymaps class kb_sequence { public: + friend class kb_keymap; + /// - 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 - if the latter is defined. */ + kb_sequence(kb_keymap * std, kb_keymap * cur) + : stdmap(std), curmap(cur), length_(0), deleted_(false) {} + + + + /** + * Add a key to the key sequence and look it up in the curmap + * if the latter is defined. + * @param mod modifier mask + * @param nmod which modifiers to mask out for equality test + * @return the action matching this key sequence or LFUN_UNKNOWN_ACTION + */ int addkey(unsigned int key, unsigned int mod, unsigned int nmod = 0); - /// - int print(string & buf, bool when_defined = false) const; - - /// - int printOptions(string & buf) const; - - /// Make length negative to mark the sequence as deleted - void delseq(); - - /// + /** + * Add a sequence of keys from a string to the sequence + * @return string::npos if OK, else error position in string + * + * Keys in the string must be separated with whitespace; + * Use the keysym names used by XStringToKeysym + * Prefixes are S-, C-, M- for shift, control, meta + */ + string::size_type parse(string const & s); + + /** + * Return the current sequence as a string. + * @see parse() + */ + string const print() const; + + /** + * Return the current sequence and available options as + * a string. No options are added if no curmap kb map exists. + */ + string const printOptions() const; + + /// Mark the sequence as deleted. + void mark_deleted(); + + /// Return the ISO value of the last keysym in sequence, or 0 char getiso() const; - - /// - unsigned int getsym() const; - - /// + + /// Reset sequence to become "deleted" void reset(); - - /// - int parse(string const & s); - + + /// clear in full + void clear(); + + bool deleted() const { + return deleted_; + } + + /// length of sequence + std::vector::size_type length() const { + return length_; + } + /// 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; + /// get the keysym of last in sequence + unsigned int getsym() const; + + /** + * Array holding the current key sequence. + * If sequence[length-1] < 0xff it can be used as ISO8859 char + */ + std::vector sequence; + + /// modifiers for keys in the sequence + std::vector modifiers; + + /// Current length of key sequence + std::vector::size_type length_; + + /// is keysequence deleted ? + bool deleted_; }; #endif