]> git.lyx.org Git - lyx.git/blob - src/kbsequence.h
6fa089880cfcf86f852d0b440f0fd79e8d5a7b28
[lyx.git] / src / kbsequence.h
1 // -*- C++ -*-
2 /**
3  * \file kbsequence.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 KBSEQUENCE_H
14 #define KBSEQUENCE_H
15
16 #include "frontends/key_state.h"
17 #include "frontends/LyXKeySym.h"
18
19 #include <string>
20 #include <vector>
21
22
23 namespace lyx {
24
25 class kb_keymap;
26 class FuncRequest;
27
28 /// Holds a key sequence and the current and standard keymaps
29 class kb_sequence {
30 public:
31         typedef std::vector<LyXKeySymPtr> KeySequence;
32
33         friend class kb_keymap;
34
35         ///
36         kb_sequence(kb_keymap * std, kb_keymap * cur)
37                 : stdmap(std), curmap(cur), deleted_(false) {}
38
39         /**
40          * Add a key to the key sequence and look it up in the curmap
41          * if the latter is defined.
42          * @param keysym the key to add
43          * @param mod modifier mask
44          * @param nmod which modifiers to mask out for equality test
45          * @return the action matching this key sequence or LFUN_UNKNOWN_ACTION
46          */
47         FuncRequest const &
48         addkey(LyXKeySymPtr keysym, key_modifier::state mod,
49                key_modifier::state nmod = key_modifier::none);
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         std::string::size_type parse(std::string const & s);
63
64         /**
65          * Return the current sequence as a string.
66          * @see parse()
67          */
68         docstring const print() const;
69
70         /**
71          * Return the current sequence and available options as
72          * a string. No options are added if no curmap kb map exists.
73          */
74         docstring const printOptions() const;
75
76         /// Mark the sequence as deleted.
77         void mark_deleted();
78
79         /// Reset sequence to become "deleted"
80         void reset();
81
82         /// clear in full
83         void clear();
84
85         bool deleted() const {
86                 return deleted_;
87         }
88
89         /// length of sequence
90         KeySequence::size_type length() const {
91                 return sequence.size();
92         }
93
94         /// Keymap to use if a new sequence is starting
95         kb_keymap * stdmap;
96
97         /// Keymap to use for the next key
98         kb_keymap * curmap;
99
100 private:
101         /**
102          * Array holding the current key sequence as KeySyms.
103          * If sequence[length - 1] < 0xff it can be used as ISO8859 char
104          */
105         KeySequence sequence;
106
107         typedef std::pair<key_modifier::state, key_modifier::state>
108                 modifier_pair;
109
110         /// modifiers for keys in the sequence
111         std::vector<modifier_pair> modifiers;
112
113         /// is keysequence deleted ?
114         bool deleted_;
115 };
116
117
118 } // namespace lyx
119
120 #endif