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