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