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