]> git.lyx.org Git - lyx.git/blob - src/kbsequence.h
minimal effort implementation of:
[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 class kb_keymap;
23 class FuncRequest;
24
25 /// Holds a key sequence and the current and standard keymaps
26 class kb_sequence {
27 public:
28         typedef std::vector<LyXKeySymPtr> KeySequence;
29
30         friend class kb_keymap;
31
32         ///
33         kb_sequence(kb_keymap * std, kb_keymap * cur)
34                 : stdmap(std), curmap(cur), deleted_(false) {}
35
36         /**
37          * Add a key to the key sequence and look it up in the curmap
38          * if the latter is defined.
39          * @param keysym the key to add
40          * @param mod modifier mask
41          * @param nmod which modifiers to mask out for equality test
42          * @return the action matching this key sequence or LFUN_UNKNOWN_ACTION
43          */
44         FuncRequest const &
45         addkey(LyXKeySymPtr keysym, key_modifier::state mod,
46                key_modifier::state nmod = key_modifier::none);
47
48         /**
49          * Add a sequence of keys from a string to the sequence
50          * @return string::npos if OK, else error position in string
51          *
52          * Keys in the string must be separated with whitespace;
53          * Use the keysym names used by XStringToKeysym, f.ex.
54          * "Space", "a", "Return", ...
55          * Prefixes are S-, C-, M- for shift, control, meta
56          * Prefixes can also be ignored by using the Tilde "~"
57          * f.ex.: "~S-Space".
58          */
59         std::string::size_type parse(std::string const & s);
60
61         /**
62          * Return the current sequence as a string.
63          * @see parse()
64          */
65         std::string const print() const;
66
67         /**
68          * Return the current sequence and available options as
69          * a string. No options are added if no curmap kb map exists.
70          */
71         std::string const printOptions() const;
72
73         /// Mark the sequence as deleted.
74         void mark_deleted();
75
76         /// Reset sequence to become "deleted"
77         void reset();
78
79         /// clear in full
80         void clear();
81
82         bool deleted() const {
83                 return deleted_;
84         }
85
86         /// length of sequence
87         KeySequence::size_type length() const {
88                 return sequence.size();
89         }
90
91         /// Keymap to use if a new sequence is starting
92         kb_keymap * stdmap;
93
94         /// Keymap to use for the next key
95         kb_keymap * curmap;
96
97 private:
98         /**
99          * Array holding the current key sequence as KeySyms.
100          * If sequence[length - 1] < 0xff it can be used as ISO8859 char
101          */
102         KeySequence sequence;
103
104         typedef std::pair<key_modifier::state, key_modifier::state>
105                 modifier_pair;
106
107         /// modifiers for keys in the sequence
108         std::vector<modifier_pair> modifiers;
109
110         /// is keysequence deleted ?
111         bool deleted_;
112 };
113
114 #endif