]> git.lyx.org Git - lyx.git/blob - src/kbsequence.h
John's Layout Tabular UI improvements and Martins fixes to clearing the
[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 #ifdef __GNUG__
12 #pragma interface
13 #endif
14
15 #include <vector>
16 #include "LString.h"
17
18 #include "commandtags.h"
19
20 class kb_keymap;
21
22 /// Holds a key sequence and the current and standard keymaps
23 class kb_sequence {
24 public:
25         friend class kb_keymap;
26
27         ///
28         kb_sequence(kb_keymap * std, kb_keymap * cur)
29                 : stdmap(std), curmap(cur), length_(0), deleted_(false) {}
30
31         
32
33         /**
34          * Add a key to the key sequence and look it up in the curmap
35          * if the latter is defined.
36          * @param mod modifier mask
37          * @param nmod which modifiers to mask out for equality test
38          * @return the action matching this key sequence or LFUN_UNKNOWN_ACTION
39          */
40         kb_action addkey(unsigned int key, unsigned int mod, unsigned int nmod = 0);
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
48          * Prefixes are S-, C-, M- for shift, control, meta
49          */
50         string::size_type parse(string const & s);
51         
52         /**
53          * Return the current sequence as a string.
54          * @see parse()
55          */
56         string const print() const;
57         
58         /**
59          * Return the current sequence and available options as
60          * a string. No options are added if no curmap kb map exists.
61          */
62         string const printOptions() const;
63         
64         /// Mark the sequence as deleted.
65         void mark_deleted();
66
67         /// Return the ISO value of the last keysym in sequence, or 0
68         char getiso() const;
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         std::vector<unsigned int>::size_type length() const {
82                 return length_;
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         /// get the keysym of last in sequence
93         unsigned int getsym() const;
94         
95         /**
96          * Array holding the current key sequence.
97          * If sequence[length-1] < 0xff it can be used as ISO8859 char
98          */
99         std::vector<unsigned int> sequence;
100         
101         /// modifiers for keys in the sequence
102         std::vector<unsigned int> modifiers;
103         
104         /// Current length of key sequence
105         std::vector<unsigned int>::size_type length_;
106
107         /// is keysequence deleted ?
108         bool deleted_;
109 };
110
111 #endif