]> git.lyx.org Git - lyx.git/blob - src/kbsequence.h
redraw fix 1.
[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         /**
75          * Return the value of the last keysym in the sequence
76          * in the local ISO encoding. If it does not encode
77          * in this encoding, return 0.
78          */
79         char getLastKeyEncoded() const;
80
81         /// Reset sequence to become "deleted"
82         void reset();
83
84         /// clear in full
85         void clear();
86
87         bool deleted() const {
88                 return deleted_;
89         }
90
91         /// length of sequence
92         KeySequence::size_type length() const {
93                 return sequence.size();
94         }
95
96         /// Keymap to use if a new sequence is starting
97         kb_keymap * stdmap;
98
99         /// Keymap to use for the next key
100         kb_keymap * curmap;
101
102 private:
103         /// get the keysym of last in sequence
104         LyXKeySymPtr getsym() const;
105
106         /**
107          * Array holding the current key sequence as KeySyms.
108          * If sequence[length-1] < 0xff it can be used as ISO8859 char
109          */
110         KeySequence sequence;
111
112         typedef std::pair<key_modifier::state, key_modifier::state>
113                 modifier_pair;
114
115         /// modifiers for keys in the sequence
116         std::vector<modifier_pair> modifiers;
117
118         /// is keysequence deleted ?
119         bool deleted_;
120 };
121
122 #endif