]> git.lyx.org Git - lyx.git/blob - src/KeySequence.h
Avoid full metrics computation with Update:FitCursor
[lyx.git] / src / KeySequence.h
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.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef KEYSEQUENCE_H
14 #define KEYSEQUENCE_H
15
16 #include "frontends/KeyModifier.h"
17 #include "frontends/KeySymbol.h"
18
19 #include <string>
20 #include <vector>
21
22
23 namespace lyx {
24
25 class KeyMap;
26 class FuncRequest;
27
28 /// Holds a key sequence and the current and standard keymaps
29 class KeySequence {
30 public:
31         typedef std::vector<KeySymbol> Sequence;
32
33         friend class KeyMap;
34
35         KeySequence() : stdmap(0), curmap(0), deleted_(true) {}
36         ///
37         KeySequence(KeyMap * std, KeyMap * cur)
38                 : stdmap(std), curmap(cur), deleted_(false) {}
39
40         /**
41          * Add a key to the key sequence and look it up in the curmap
42          * if the latter is defined.
43          * @param key 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
47          */
48         FuncRequest const & addkey(KeySymbol const & key, KeyModifier mod,
49                KeyModifier nmod = NoModifier);
50
51         /**
52          * Add a sequence of keys from a string to the sequence
53          * @return string::npos if OK, else error position in string
54          *
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".
61          */
62         size_t parse(std::string const & s);
63
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
68         };
69
70         /**
71          * Return the current sequence as a string.
72          * @param format output format
73          * @see parse()
74          */
75         docstring const print(outputFormat format, bool const untranslated = false) const;
76
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.
82          */
83         docstring const printOptions(bool forgui) const;
84
85         /// Reset sequence to become "deleted"
86         void reset();
87
88         /// clear in full
89         void clear();
90
91         /// remove last key in sequence
92         void removeKey();
93
94         bool deleted() const { return deleted_; }
95
96         /// length of sequence
97         size_t length() const { return sequence.size(); }
98
99 private:
100         /// Keymap to use if a new sequence is starting
101         KeyMap * stdmap;
102
103         /// Keymap to use for the next key
104         KeyMap * curmap;
105
106         /**
107          * Array holding the current key sequence as KeySyms.
108          * If sequence[length - 1] < 0xff it can be used as ISO8859 char
109          */
110         Sequence sequence;
111
112         typedef std::pair<KeyModifier, KeyModifier> ModifierPair;
113
114         /// modifiers for keys in the sequence
115         std::vector<ModifierPair> modifiers;
116
117         /// is keysequence deleted ?
118         bool deleted_;
119 };
120
121
122 } // namespace lyx
123
124 #endif