X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fkbsequence.h;h=6dc269a0357687f9f3e343c8927992a5a4036848;hb=e7f4618bcce770369cf46335c2c7f0164b4b8857;hp=060f8ae3963b2e88da77f67f8112ae46ea0cf0f6;hpb=acb3eecb5d542eefbd4b50fa8ce9d819642588f6;p=lyx.git diff --git a/src/kbsequence.h b/src/kbsequence.h index 060f8ae396..6dc269a035 100644 --- a/src/kbsequence.h +++ b/src/kbsequence.h @@ -1,112 +1,124 @@ // -*- 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 + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Lars Gullik Bjønnes + * \author Jean-Marc Lasgouttes + * + * Full author contact details are available in file CREDITS. + */ #ifndef KBSEQUENCE_H #define KBSEQUENCE_H -#ifdef __GNUG__ -#pragma interface -#endif +#include "frontends/key_state.h" +#include "frontends/LyXKeySym.h" +#include #include -#include "LString.h" -#if 0 -#define KB_PREALLOC 16 -#endif + +namespace lyx { class kb_keymap; +class FuncRequest; /// Holds a key sequence and the current and standard keymaps class kb_sequence { public: + typedef std::vector KeySequence; + + friend class kb_keymap; + /// - kb_sequence() { - stdmap = curmap = 0; -#if 0 - sequence = staticseq; - modifiers = staticmod; -#endif - length = 0; -#if 0 - size = KB_PREALLOC; -#endif + kb_sequence(kb_keymap * std, kb_keymap * cur) + : stdmap(std), curmap(cur), deleted_(false) {} + + /** + * Add a key to the key sequence and look it up in the curmap + * if the latter is defined. + * @param keysym the key to add + * @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 + */ + FuncRequest const & + addkey(LyXKeySymPtr keysym, key_modifier::state mod, + key_modifier::state nmod = key_modifier::none); + + /** + * 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, f.ex. + * "Space", "a", "Return", ... + * Prefixes are S-, C-, M- for shift, control, meta + * Prefixes can also be ignored by using the Tilde "~" + * f.ex.: "~S-Space". + */ + std::string::size_type parse(std::string const & s); + + /** + * Return the current sequence as a string. + * @param forgui true if the string should use translations and + * special characters. + * @see parse() + */ + docstring const print(bool forgui) const; + + /** + * Return the current sequence and available options as + * a string. No options are added if no curmap kb map exists. + * @param forgui true if the string should use translations and + * special characters. + */ + docstring const printOptions(bool forgui) const; + + /// Mark the sequence as deleted. + void mark_deleted(); + + /// Reset sequence to become "deleted" + void reset(); + + /// clear in full + void clear(); + + bool deleted() const { + return deleted_; } -#if 0 - /// - ~kb_sequence() { - if (sequence != staticseq) { - delete sequence; - delete modifiers; - } + /// length of sequence + KeySequence::size_type length() const { + return sequence.size(); } -#endif - - /** Add a key to the key sequence and look it up in the curmap - if the latter is defined. */ - 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(); - - /// - char getiso() const; - - /// - unsigned int getsym() const; - - /// - void reset(); - - /// - int parse(string 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 */ -#if 0 - unsigned int * sequence; -#else - std::vector sequence; -#endif - - /// -#if 0 - unsigned int * modifiers; -#else - std::vector modifiers; -#endif - - /// Current length of key sequence - int length; -#if 0 + private: - /// Static array preallocated for sequence - unsigned int staticseq[KB_PREALLOC]; - - /// - unsigned int staticmod[KB_PREALLOC]; - - /// Physically allocated storage size - int size; -#endif + /** + * Array holding the current key sequence as KeySyms. + * If sequence[length - 1] < 0xff it can be used as ISO8859 char + */ + KeySequence sequence; + + typedef std::pair + modifier_pair; + + /// modifiers for keys in the sequence + std::vector modifiers; + + /// is keysequence deleted ? + bool deleted_; }; + +} // namespace lyx + #endif