]> git.lyx.org Git - lyx.git/blob - src/KeySequence.h
Fulfill promise to Andre: TextClass_ptr --> TextClassPtr.
[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 KB_SEQUENCE_H
14 #define KB_SEQUENCE_H
15
16 #include "frontends/key_state.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 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
47          */
48         FuncRequest const &
49         addkey(KeySymbol const & keysym, key_modifier::state mod,
50                key_modifier::state nmod = key_modifier::none);
51
52         /**
53          * Add a sequence of keys from a string to the sequence
54          * @return string::npos if OK, else error position in string
55          *
56          * Keys in the string must be separated with whitespace;
57          * Use the keysym names used by XStringToKeysym, f.ex.
58          * "Space", "a", "Return", ...
59          * Prefixes are S-, C-, M- for shift, control, meta
60          * Prefixes can also be ignored by using the Tilde "~"
61          * f.ex.: "~S-Space".
62          */
63         size_t parse(std::string const & s);
64
65         /**
66          * Return the current sequence as a string.
67          * @param forgui true if the string should use translations and
68          *   special characters.
69          * @see parse()
70          */
71         docstring const print(bool forgui) const;
72
73         /**
74          * Return the current sequence and available options as
75          * a string. No options are added if no curmap kb map exists.
76          * @param forgui true if the string should use translations and
77          *   special characters.
78          */
79         docstring const printOptions(bool forgui) const;
80
81         /// Mark the sequence as deleted.
82         void mark_deleted();
83
84         /// Reset sequence to become "deleted"
85         void reset();
86
87         /// clear in full
88         void clear();
89
90         bool deleted() const { return deleted_; }
91
92         /// length of sequence
93         size_t length() const { return sequence.size(); }
94
95         /// Keymap to use if a new sequence is starting
96         KeyMap * stdmap;
97
98         /// Keymap to use for the next key
99         KeyMap * curmap;
100
101 private:
102         /**
103          * Array holding the current key sequence as KeySyms.
104          * If sequence[length - 1] < 0xff it can be used as ISO8859 char
105          */
106         Sequence sequence;
107
108         typedef std::pair<key_modifier::state, key_modifier::state>
109                 modifier_pair;
110
111         /// modifiers for keys in the sequence
112         std::vector<modifier_pair> modifiers;
113
114         /// is keysequence deleted ?
115         bool deleted_;
116 };
117
118
119 } // namespace lyx
120
121 #endif