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