]> git.lyx.org Git - lyx.git/blob - src/kbsequence.h
more dialog merging
[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          * @param forgui true if the string should use translations and 
67          *   special characters. 
68          * @see parse()
69          */
70         docstring const print(bool forgui) const;
71
72         /**
73          * Return the current sequence and available options as
74          * a string. No options are added if no curmap kb map exists.
75          * @param forgui true if the string should use translations and 
76          *   special characters. 
77          */
78         docstring const printOptions(bool forgui) const;
79
80         /// Mark the sequence as deleted.
81         void mark_deleted();
82
83         /// Reset sequence to become "deleted"
84         void reset();
85
86         /// clear in full
87         void clear();
88
89         bool deleted() const {
90                 return deleted_;
91         }
92
93         /// length of sequence
94         KeySequence::size_type length() const {
95                 return sequence.size();
96         }
97
98         /// Keymap to use if a new sequence is starting
99         kb_keymap * stdmap;
100
101         /// Keymap to use for the next key
102         kb_keymap * curmap;
103
104 private:
105         /**
106          * Array holding the current key sequence as KeySyms.
107          * If sequence[length - 1] < 0xff it can be used as ISO8859 char
108          */
109         KeySequence sequence;
110
111         typedef std::pair<key_modifier::state, key_modifier::state>
112                 modifier_pair;
113
114         /// modifiers for keys in the sequence
115         std::vector<modifier_pair> modifiers;
116
117         /// is keysequence deleted ?
118         bool deleted_;
119 };
120
121
122 } // namespace lyx
123
124 #endif