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