Not so soon, I guess, since that FIXME was from r6305.
[lyx.git] / src / KeySequence.h
bloba0eb74eb03b2c80e657c2588a622621b23c54093
1 // -*- C++ -*-
2 /**
3 * \file KeySequence.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
10 * Full author contact details are available in file CREDITS.
13 #ifndef KEYSEQUENCE_H
14 #define KEYSEQUENCE_H
16 #include "frontends/KeyModifier.h"
17 #include "frontends/KeySymbol.h"
19 #include <string>
20 #include <vector>
23 namespace lyx {
25 class KeyMap;
26 class FuncRequest;
28 /// Holds a key sequence and the current and standard keymaps
29 class KeySequence {
30 public:
31 typedef std::vector<KeySymbol> Sequence;
33 friend class KeyMap;
35 KeySequence() : stdmap(0), curmap(0), deleted_(true) {}
36 ///
37 KeySequence(KeyMap * std, KeyMap * cur)
38 : stdmap(std), curmap(cur), deleted_(false) {}
40 /**
41 * Add a key to the key sequence and look it up in the curmap
42 * if the latter is defined.
43 * @param keysym the key to add
44 * @param mod modifier mask
45 * @param nmod which modifiers to mask out for equality test
46 * @return the action matching this key sequence or LFUN_UNKNOWN_ACTION
48 FuncRequest const & addkey(KeySymbol const & keysym, KeyModifier mod,
49 KeyModifier nmod = NoModifier);
51 /**
52 * Add a sequence of keys from a string to the sequence
53 * @return string::npos if OK, else error position in string
55 * Keys in the string must be separated with whitespace;
56 * Use the keysym names used by XStringToKeysym, f.ex.
57 * "Space", "a", "Return", ...
58 * Prefixes are S-, C-, M- for shift, control, meta
59 * Prefixes can also be ignored by using the Tilde "~"
60 * f.ex.: "~S-Space".
62 size_t parse(std::string const & s);
64 enum outputFormat {
65 Portable, //< use a more portable format
66 ForGui, //< use platform specific translations and special characters
67 BindFile //< the format used in lyx bind files
70 /**
71 * Return the current sequence as a string.
72 * @param format output format
73 * @see parse()
75 docstring const print(outputFormat format) const;
77 /**
78 * Return the current sequence and available options as
79 * a string. No options are added if no curmap kb map exists.
80 * @param forgui true if the string should use translations and
81 * special characters.
83 docstring const printOptions(bool forgui) const;
85 /// Reset sequence to become "deleted"
86 void reset();
88 /// clear in full
89 void clear();
91 /// remove last key in sequence
92 void removeKey();
94 bool deleted() const { return deleted_; }
96 /// length of sequence
97 size_t length() const { return sequence.size(); }
99 private:
100 /// Keymap to use if a new sequence is starting
101 KeyMap * stdmap;
103 /// Keymap to use for the next key
104 KeyMap * curmap;
107 * Array holding the current key sequence as KeySyms.
108 * If sequence[length - 1] < 0xff it can be used as ISO8859 char
110 Sequence sequence;
112 typedef std::pair<KeyModifier, KeyModifier> ModifierPair;
114 /// modifiers for keys in the sequence
115 std::vector<ModifierPair> modifiers;
117 /// is keysequence deleted ?
118 bool deleted_;
122 } // namespace lyx
124 #endif